diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-25 21:27:53 -0400 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2021-06-25 21:27:53 -0400 |
commit | 1681b9ad0021e0f72bd2f2a4e59e51b9bcdded02 (patch) | |
tree | 3c06d4505ba1da12e08d5b95ef5a8b7d17a01b3e /git.c | |
parent | fc28bfdf3a7acb15f718074c5526eee15f2dfbed (diff) |
Started work on `create_info()`.
Diffstat (limited to 'git.c')
-rw-r--r-- | git.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -68,6 +68,53 @@ pull_request *get_pull_request(int id, const char *root) { } +int create_info(pull_request *pr, const char *pr_dir) { + int len = strlen(pr_dir) + strlen("/info"); + char *info = calloc(len+1, sizeof(char)); + char *info_buf; + FILE *fp; + + /* Append /info to the PR directory. */ + sprintf(info, "%s/info", pr_dir); + + /* TODO: Write the rest of the code. */ + + /* Is there already an info file? */ + if (access(info, F_OK) == 0) { + long size = 0; + char *buf = read_file(info, &size); + + log(LOG_INFO, "Info file already exists."); + + /* Did we read the file? */ + if (buf != NULL) { + /* Are the contents of the info file the same? */ + if (strcmp(info_buf, buf) == 0) { + log(LOG_INFO, "New info file is the same as the existing one."); + free(info); + free(info_buf); + free(buf); + return 2; + } + free(buf); + } else { + log(LOG_ERR, "Couldn't open existing info file."); + return 0; + } + } + + /* Open the info file. */ + fp = fopen(pr_dir, "w"); + + /* Did we fail to open the file? */ + if (fp == NULL) { + log(LOG_ERR, "Failed to open info file."); + return 0; + } + + return 1; +} + int create_pull_request_dir(pull_request *pr, int id, const char *root) { int ret = id; struct stat st; |