Skip to content

Commit

Permalink
error handling implemented to solve #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjoedicker committed Sep 25, 2020
1 parent e418abe commit 2500fb6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Empty file added 2_re
Empty file.
48 changes: 27 additions & 21 deletions src/source/filelib.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,37 @@ restorefile(struct Argument *target_file)
KEEP_HEAD
);

size_t sizeof_trace_path = (strlen(target_file->logistics->trace_file_loc) + strlen(target_file->parsed_file_path) + 2);
char *trace_file_path = extendpath(
sizeof_trace_path,
target_file->logistics->trace_file_loc,
"/.",
target_file->parsed_file_path,
KEEP_HEAD
);
if (target_file->restore_path == NULL)
{
char *restore_path = readfile(trace_file_path);
rename(file_loc, restore_path);
if (access(file_loc, F_OK) == 0) {

size_t sizeof_trace_path = (strlen(target_file->logistics->trace_file_loc) + strlen(target_file->parsed_file_path) + 2);
char *trace_file_path = extendpath(
sizeof_trace_path,
target_file->logistics->trace_file_loc,
"/.",
target_file->parsed_file_path,
KEEP_HEAD
);

if (access(trace_file_path, F_OK) == 0) {
if (target_file->restore_path == NULL)
{
char *restore_path = readfile(trace_file_path);
rename(file_loc, restore_path);

if (access(trace_file_path, F_OK) == 0) {
rename(file_loc, restore_path);
}

free(restore_path);
} else {
if (!access(target_file->restore_path, F_OK)){
sprintf(target_file->restore_path, "%s%s%s", target_file->restore_path, "/", target_file->parsed_file_path);
rename(file_loc, target_file->restore_path);
}
}

free(restore_path);
free(file_loc);
free(trace_file_path);
} else {
if (!access(target_file->restore_path, F_OK)){
sprintf(target_file->restore_path, "%s%s%s", target_file->restore_path, "/", target_file->parsed_file_path);
rename(file_loc, target_file->restore_path);
}
printf("file not found\n");
}

free(file_loc);
free(trace_file_path);
}

0 comments on commit 2500fb6

Please sign in to comment.