From 1936a4303eae6dc1cc7ce072d87e3f8f365f4e64 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 3 Jul 2021 10:48:23 -0400 Subject: Use the filename created by `create_num_str()`, rather than the patch filename itself. --- git.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index 02889ae..490782c 100644 --- a/git.c +++ b/git.c @@ -304,31 +304,36 @@ int create_pull_request_dir(pull_request *pr, int id, const char *root) { /* Make patch files for each commit of PR. */ for (int i = 0; commits[i] != NULL; i++) { FILE *fp; + char *filename = create_num_str(commits[i]->name, i); + /* Does this patch file exists? */ - if (access(commits[i]->name, F_OK) == 0) { + if (access(filename, F_OK) == 0) { long size = 0; - char *buf = read_file(commits[i]->name, &size); - log(LOG_NOTICE, "Patch file %s already exists.", commits[i]->name); + char *buf = read_file(filename, &size); + log(LOG_NOTICE, "Patch file %s already exists.", filename); /* Did we read the file? */ if (buf != NULL) { /* Are the contents of the patch file the same? */ if (strcmp(commits[i]->buf, buf) == 0) { /* Skip creating this patch file. */ - log(LOG_NOTICE, "Patch file %s is the same as the new one.", commits[i]->name); + log(LOG_NOTICE, "Patch file %s is the same as the new one.", filename); free(buf); + free(filename); continue; } free(buf); } else { - log(LOG_WARNING, "Couldn't open patch file %s.", commits[i]->name); + log(LOG_WARNING, "Couldn't open patch file %s.", filename); + free(filename); continue; } } /* Create the format patch file for this commit. */ - fp = fopen(commits[i]->name, "w"); + fp = fopen(filename, "w"); fwrite(commits[i]->buf, sizeof(char), strlen(commits[i]->buf), fp); fclose(fp); + free(filename); } if (commits != NULL && pr->pr_type) { -- cgit v1.2.3-13-gbd6f