diff --git a/src/main.c b/src/main.c index 699405ee..9d225e49 100644 --- a/src/main.c +++ b/src/main.c @@ -58,7 +58,7 @@ process_mrl(st_waste *waste_head, fprintf(stderr, "while reading %s\n", mrl_file); clearerr(fp); } - close_file(fp, mrl_file, __func__); + close_file(&fp, mrl_file, __func__); // This fixes a coverity warning, and may be a good idea anyway, since the data read // by fread may not be null-terminated. contents[f_size] = '\0'; @@ -132,16 +132,16 @@ add_removal(st_removed *removals, const char *file) static void create_undo_file(st_removed *removals_head, const char *mrl_file) { - FILE *fd = fopen(mrl_file, "w"); - if (fd) + FILE *fp = fopen(mrl_file, "w"); + if (fp) { st_removed *st_removals_list = removals_head; while (st_removals_list != NULL) { - fprintf(fd, "%s\n", st_removals_list->file); + fprintf(fp, "%s\n", st_removals_list->file); st_removals_list = st_removals_list->next_node; } - close_file(fd, mrl_file, __func__); + close_file(&fp, mrl_file, __func__); } else open_err(mrl_file, __func__); @@ -522,14 +522,14 @@ get_locations(const char *alt_config_file) if ((p_state = check_pathname_state(x.config_file)) == P_STATE_ENOENT) { - FILE *fd = fopen(x.config_file, "w"); - if (fd) + FILE *fp = fopen(x.config_file, "w"); + if (fp) { puts(_("Creating default configuration file:")); printf(" %s\n\n", x.config_file); - print_config(fd); - close_file(fd, x.config_file, __func__); + print_config(fp); + close_file(&fp, x.config_file, __func__); } else { diff --git a/src/messages_rmw.c b/src/messages_rmw.c index 5c296c33..43badfb8 100644 --- a/src/messages_rmw.c +++ b/src/messages_rmw.c @@ -65,12 +65,12 @@ function: <%s>\n\ * @return an error number, 0 if no error */ int -close_file(FILE *file_ptr, const char *filename, const char *function_name) +close_file(FILE **fp, const char *filename, const char *function_name) { - if (file_ptr == NULL) + if (*fp == NULL) return -1; - if (fclose(file_ptr) != EOF) + if (fclose(*fp) != EOF) return 0; else { @@ -84,6 +84,7 @@ function: <%s>\n\ } } + void display_dot_trashinfo_error(const char *dti) { diff --git a/src/messages_rmw.h b/src/messages_rmw.h index 909ffd79..c78f91a6 100644 --- a/src/messages_rmw.h +++ b/src/messages_rmw.h @@ -33,8 +33,7 @@ void print_msg_warn(void); void open_err(const char *filename, const char *function_name); -int -close_file(FILE * file_ptr, const char *filename, const char *function_name); +int close_file(FILE **fp, const char *filename, const char *function_name); void display_dot_trashinfo_error(const char *dti); diff --git a/src/purging_rmw.c b/src/purging_rmw.c index cce49939..8f5f2efe 100644 --- a/src/purging_rmw.c +++ b/src/purging_rmw.c @@ -54,12 +54,12 @@ is_time_to_purge(st_time *st_time_var, const char *file) print_msg_error(); printf("while getting line from %s\n", file); perror(__func__); - close_file(fp, file, __func__); + close_file(&fp, file, __func__); exit(EXIT_FAILURE); } trim_whitespace(time_prev); - close_file(fp, file, __func__); + close_file(&fp, file, __func__); if ((st_time_var->now - atoi(time_prev)) < SECONDS_IN_A_DAY) return false; @@ -69,7 +69,7 @@ is_time_to_purge(st_time *st_time_var, const char *file) if (fp) { fprintf(fp, "%ld\n", st_time_var->now); - close_file(fp, file, __func__); + close_file(&fp, file, __func__); /* * if this is the first time the file got created, it's very likely diff --git a/src/restore_rmw.c b/src/restore_rmw.c index fa938ff8..66016477 100644 --- a/src/restore_rmw.c +++ b/src/restore_rmw.c @@ -528,11 +528,11 @@ undo_last_rmw(st_time *st_time_var, const char *mrl_file, const { if (cli_user_options->want_dry_run == false) { - FILE *fd = fopen(mrl_file, "w"); - if (fd != NULL) + FILE *fp = fopen(mrl_file, "w"); + if (fp != NULL) { - fprintf(fd, "%s", mrl_is_empty); - close_file(fd, mrl_file, __func__); + fprintf(fp, "%s", mrl_is_empty); + close_file(&fp, mrl_file, __func__); } else open_err(mrl_file, __func__); diff --git a/src/trashinfo_rmw.c b/src/trashinfo_rmw.c index 61d967b7..c16e20c1 100644 --- a/src/trashinfo_rmw.c +++ b/src/trashinfo_rmw.c @@ -83,7 +83,7 @@ create_trashinfo(rmw_target *st_f_props, st_waste *waste_curr, **/ char *escaped_path = escape_url(st_f_props->real_path); if (escaped_path == NULL) - return close_file(fp, final_info_dest, __func__); + return close_file(&fp, final_info_dest, __func__); char *escaped_path_ptr = escaped_path; if (waste_curr->media_root != NULL) @@ -108,7 +108,7 @@ create_trashinfo(rmw_target *st_f_props, st_waste *waste_curr, fprintf(fp, "%s%s\n", st_trashinfo_template[TI_DATE_LINE].str, st_time_var->deletion_date); - return close_file(fp, final_info_dest, __func__); + return close_file(&fp, final_info_dest, __func__); } else { @@ -191,7 +191,7 @@ parse_trashinfo_file(const char *file, const char *req_value) } line_no++; } - close_file(fp, file, __func__); + close_file(&fp, file, __func__); if (res && line_no == TI_LINE_COUNT) return trashinfo_field.value; diff --git a/test/test_restore.sh b/test/test_restore.sh index 15451c4b..be9b5122 100755 --- a/test/test_restore.sh +++ b/test/test_restore.sh @@ -119,7 +119,7 @@ fi # /dev/sda7 on /mnt/sda7 type ext4 (rw,relatime) # /dev/sda7 on /home/andy/src type ext4 (rw,relatime) -if test -d /mnt/e2f95a91; then +if test -d /mnt/918375c2; then test_file="media_root_test" PREV_RMW_FAKE_HOME=${RMW_FAKE_HOME} # needs to be unset so rmw will use $HOME instead