From f57654c80ecb53fd40bf2b2e18d41197718bbaa7 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 21 Jul 2022 20:30:46 -0500 Subject: [PATCH] Bugfix: Copy should destination should be the base name rather than the entire path. The entire path is being appended to the destination when performing a clone or a copy operation. Example: copy a/b/c.txt destination/ This should copy c.txt as "destination/c.txt". What instead happens is this: "destination/a/b/c.txt". Change the code to now detect the file base name and append the base name rather than append the entire path. --- level_3/fake/c/private-make-operate_process_type.c | 27 +++++++++++++++------- level_3/fake/c/private-make-operate_process_type.h | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/level_3/fake/c/private-make-operate_process_type.c b/level_3/fake/c/private-make-operate_process_type.c index 615001a..6ffedfa 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -53,7 +53,7 @@ extern "C" { status = f_directory_is(data_make->cache_arguments.array[1]); if (F_status_is_error(status)) { - fll_error_file_print(data_make->error, F_status_set_fine(status), "f_directory_is", F_true, data_make->cache_arguments.array[1], f_file_operation_identify_s, fll_error_file_type_directory_e); + fll_error_file_print(data_make->error, F_status_set_fine(status), "f_directory_is", F_true, data_make->cache_arguments.array[1], f_file_operation_identify_s, fll_error_file_type_path_e); return F_status_set_error(F_failure); } @@ -68,7 +68,17 @@ extern "C" { destination.used = data_make->cache_arguments.array[total].used + 1; if (existing) { - destination.used += data_make->cache_arguments.array[i].used + 1; + data_make->cache_path.used = 0; + + status = f_file_name_base(data_make->cache_arguments.array[i], &data_make->cache_path); + + if (F_status_is_error(status)) { + fll_error_file_print(data_make->error, F_status_set_fine(status), "f_file_name_base", F_true, data_make->cache_arguments.array[i], f_file_operation_process_s, fll_error_file_type_path_e); + + return F_status_set_error(F_failure); + } + + destination.used += data_make->cache_path.used + 1; } f_char_t destination_string[destination.used + 1]; @@ -84,27 +94,28 @@ extern "C" { if (existing) { if (destination_string[data_make->cache_arguments.array[total].used - 1] == f_path_separator_s.string[0]) { - memcpy(destination_string + data_make->cache_arguments.array[total].used, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); - if (data_make->cache_arguments.array[i].string[data_make->cache_arguments.array[i].used - 1] == f_path_separator_s.string[0]) { + memcpy(destination_string + data_make->cache_arguments.array[total].used, data_make->cache_path.string, sizeof(f_char_t) * data_make->cache_path.used); + + if (data_make->cache_path.string[data_make->cache_path.used - 1] == f_path_separator_s.string[0]) { destination.used -= 2; } else { - destination_string[data_make->cache_arguments.array[total].used + data_make->cache_arguments.array[i].used] = f_path_separator_s.string[0]; + destination_string[data_make->cache_arguments.array[total].used + data_make->cache_path.used] = f_path_separator_s.string[0]; --destination.used; } } else { - memcpy(destination_string + data_make->cache_arguments.array[total].used + 1, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); + memcpy(destination_string + data_make->cache_arguments.array[total].used + 1, data_make->cache_path.string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; - if (data_make->cache_arguments.array[i].string[data_make->cache_arguments.array[i].used - 1] == f_path_separator_s.string[0]) { + if (data_make->cache_path.string[data_make->cache_path.used - 1] == f_path_separator_s.string[0]) { --destination.used; } else { - destination_string[data_make->cache_arguments.array[total].used + 1 + data_make->cache_arguments.array[i].used] = f_path_separator_s.string[0]; + destination_string[data_make->cache_arguments.array[total].used + 1 + data_make->cache_path.used] = f_path_separator_s.string[0]; } } } diff --git a/level_3/fake/c/private-make-operate_process_type.h b/level_3/fake/c/private-make-operate_process_type.h index a6acf49..7aee80a 100644 --- a/level_3/fake/c/private-make-operate_process_type.h +++ b/level_3/fake/c/private-make-operate_process_type.h @@ -33,6 +33,7 @@ extern "C" { * @see f_directory_is() * @see f_file_clone() * @see f_file_copy() + * @see f_file_name_base() * @see fl_directory_clone() * @see fl_directory_copy() */ -- 1.8.3.1