From 071aea8fa36eaa2332aa5cfa9964a44c70e22b84 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 21 Jul 2022 22:53:48 -0500 Subject: [PATCH] Bugfix: Apply recent bug fixes for the copy/clone operation to the move operation. The move operation is very similar to the copy and clone operations. Apply the fixes from these commits: - e70631a5463f7dcb7ad70a0f92040c2d59ad947a - f57654c80ecb53fd40bf2b2e18d41197718bbaa7 The commit e70631a5463f7dcb7ad70a0f92040c2d59ad947a also went a bit over kill and added unecessary trailing slashes. I only tested directoreis at the time and it was not a problem. This broke for non-directory file types. --- level_3/fake/c/private-make-operate_process_type.c | 53 +++++++++++----------- level_3/fake/c/private-make-operate_process_type.h | 2 + 2 files changed, 28 insertions(+), 27 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 6036191..3555972 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -94,37 +94,14 @@ 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_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_path.used] = f_path_separator_s.string[0]; - - --destination.used; - } + --destination.used; } else { 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_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_path.used] = f_path_separator_s.string[0]; - } - } - } - else { - if (destination_string[data_make->cache_arguments.array[total].used - 1] == f_path_separator_s.string[0]) { - --destination.used; - } - else { - destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; } } @@ -1163,18 +1140,40 @@ extern "C" { destination.used = data_make->cache_arguments.array[total].used; 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]; destination.string = destination_string; destination_string[destination.used] = 0; + if (existing) { + destination_string[destination.used - 1] = 0; + } + memcpy(destination_string, data_make->cache_arguments.array[total].string, sizeof(f_char_t) * data_make->cache_arguments.array[total].used); if (existing) { - 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); - destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; + 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_path.string, sizeof(f_char_t) * data_make->cache_path.used); + + --destination.used; + } + else { + 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]; + } } status = fll_file_move(data_make->cache_arguments.array[i], destination, recurse); 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 7aee80a..54de056 100644 --- a/level_3/fake/c/private-make-operate_process_type.h +++ b/level_3/fake/c/private-make-operate_process_type.h @@ -316,9 +316,11 @@ extern "C" { * F_none on success. * * Errors (with error bit) from: f_directory_is(). + * Errors (with error bit) from: f_file_name_base(). * Errors (with error bit) from: fll_file_move(). * * @see f_directory_is() + * @see f_file_name_base() * @see fll_file_move() */ #ifndef _di_fake_make_operate_process_type_move_ -- 1.8.3.1