From e87b53cb107be75df05a0bf0dffc1832b0b6f5ec Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 19 Feb 2025 22:07:11 -0600 Subject: [PATCH] Progress: Continue working on completing the remove program. Implement the memory cache for the remember parameter. --- .../program/kevux/tools/remove/main/common/print.c | 1 + .../program/kevux/tools/remove/main/common/print.h | 1 + .../c/program/kevux/tools/remove/main/operate.c | 132 ++++++++++++++++++++- .../c/program/kevux/tools/remove/main/operate.h | 2 +- 4 files changed, 129 insertions(+), 7 deletions(-) diff --git a/sources/c/program/kevux/tools/remove/main/common/print.c b/sources/c/program/kevux/tools/remove/main/common/print.c index f0cda1e..091e331 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.c +++ b/sources/c/program/kevux/tools/remove/main/common/print.c @@ -31,6 +31,7 @@ extern "C" { "kt_remove_dates_resize", "kt_remove_get_id", "kt_remove_modes_resize", + "kt_remove_operate_memory_save", "kt_remove_setting_load", }; #endif // _di_kt_remove_f_a_ diff --git a/sources/c/program/kevux/tools/remove/main/common/print.h b/sources/c/program/kevux/tools/remove/main/common/print.h index 94b14f8..b9cff65 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.h +++ b/sources/c/program/kevux/tools/remove/main/common/print.h @@ -64,6 +64,7 @@ extern "C" { kt_remove_f_kt_remove_dates_resize_e, kt_remove_f_kt_remove_get_id_e, kt_remove_f_kt_remove_modes_resize_e, + kt_remove_f_kt_remove_operate_memory_save_e, kt_remove_f_kt_remove_setting_load_e, }; // enum #endif // _di_kt_remove_f_e_ diff --git a/sources/c/program/kevux/tools/remove/main/operate.c b/sources/c/program/kevux/tools/remove/main/operate.c index 30c3d2d..ddb9669 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.c +++ b/sources/c/program/kevux/tools/remove/main/operate.c @@ -19,13 +19,17 @@ extern "C" { const uint16_t flag_operate = kt_remove_preprocess_file(main, path, 0); - if (F_status_is_error_not(main->setting.state.status) && !(main->setting.flag & (kt_remove_main_flag_simulate_d)) && !(flag_operate & kt_remove_flag_file_operate_processed_d)) { + if (F_status_is_error_not(main->setting.state.status) && !(main->setting.flag & kt_remove_main_flag_simulate_d) && !(flag_operate & kt_remove_flag_file_operate_processed_d)) { main->setting.state.status = flag_operate & kt_remove_flag_file_operate_directory_d ? kt_remove_operate_file_recurse(main, path, flag_operate) : kt_remove_operate_file_remove(main, path, flag_operate); + } - if (F_status_is_error_not(main->setting.state.status)) { - kt_remove_operate_memory_save(main, path, flag_operate); + if (F_status_is_error_not(main->setting.state.status)) { + kt_remove_operate_memory_save(main, path, flag_operate); + + if (F_status_is_error(main->setting.state.status)) { + kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(kt_remove_operate_memory_save), path, f_file_operation_process_s, fll_error_file_type_path_e); } } @@ -156,8 +160,60 @@ extern "C" { if (!main->cache.memory.used) return; - // @todo check list and then set F_remove_not as appropriate. - // *flag_operate |= kt_remove_flag_file_operate_processed_d + f_range_t range = f_range_t_initialize; + f_number_unsigned_t i = 0; + + if (main->setting.flag & kt_remove_main_flag_recurse_d) { + for (; i < main->cache.memory.used; ++i) { + + if (kt_remove_signal_check(main)) return; + if (!main->cache.memory.array[i].used) continue; + + // The memory cache is nulless and top-most directories end in slashes. + range.start = 0; + range.stop = main->cache.memory.array[i].used - 1; + + if (main->cache.memory.array[i].string[range.stop] == f_path_separator_s.string[0]) { + if (f_compare_dynamic_partial_dynamic(main->cache.memory.array[i], path, range) == F_equal_to) { + *flag_operate |= kt_remove_flag_file_operate_processed_d; + + break; + } + + // Perform exact match without the trailing directory slash. + if (range.stop) { + --range.stop; + } + + if (f_compare_dynamic_partial_dynamic(main->cache.memory.array[i], path, range) == F_equal_to) { + *flag_operate |= kt_remove_flag_file_operate_processed_d; + + break; + } + } + else { + if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) { + *flag_operate |= kt_remove_flag_file_operate_processed_d; + + break; + } + } + } // for + } + else { + + // Only perform exact matches when not using recursion. + for (; i < main->cache.memory.used; ++i) { + + if (kt_remove_signal_check(main)) return; + + if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) { + *flag_operate |= kt_remove_flag_file_operate_processed_d; + + break; + } + } // for + } } #endif // _di_kt_remove_operate_memory_check_ @@ -178,7 +234,71 @@ extern "C" { return; } - // @todo + main->setting.state.status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &main->cache.memory.array, &main->cache.memory.used, &main->cache.memory.size); + + // Find any child paths that would be included by this and remove them from the paths list. + if (F_status_is_error_not(main->setting.state.status) && (flag_operate & kt_remove_flag_file_operate_directory_d)) { + main->cache.buffer.used = 0; + + main->setting.state.status = f_memory_array_increase_by(path.used + f_path_separator_s.used, sizeof(f_char_t), (void **) &main->cache.buffer.string, &main->cache.buffer.used, &main->cache.buffer.size); + + if (F_status_is_error_not(main->setting.state.status)) { + main->setting.state.status = f_string_dynamic_append_nulless(path, &main->cache.buffer); + } + + if (F_status_is_error_not(main->setting.state.status)) { + main->setting.state.status = f_string_dynamic_append_nulless(f_path_separator_s, &main->cache.buffer); + } + + if (F_status_is_error_not(main->setting.state.status)) { + const f_range_t range = macro_f_range_t_initialize_2(main->cache.buffer.used); + f_number_unsigned_t i = 0; + + for (; i < main->cache.memory.used; ++i) { + + if (kt_remove_signal_check(main)) return; + if (main->cache.buffer.used > main->cache.memory.array[i].used) continue; + + if (f_compare_dynamic_partial_dynamic(main->cache.buffer, main->cache.memory.array[i], range) == F_equal_to) break; + } // for + + // Swap the first and the last paths and then remove the last path. + if (i < main->cache.memory.used) { + const f_string_static_t temporary = macro_f_string_dynamic_t_initialize_1(main->cache.memory.array[i].string, main->cache.memory.array[i].size, main->cache.memory.array[i].used); + + main->cache.memory.array[i].string = main->cache.memory.array[main->cache.memory.used].string; + main->cache.memory.array[i].size = main->cache.memory.array[main->cache.memory.used].size; + main->cache.memory.array[i].used = main->cache.memory.array[main->cache.memory.used].used; + + main->cache.memory.array[main->cache.memory.used].string = temporary.string; + main->cache.memory.array[main->cache.memory.used].size = temporary.size; + main->cache.memory.array[main->cache.memory.used--].used = 0; + } + } + } + + if (F_status_is_error_not(main->setting.state.status)) { + main->cache.memory.array[main->cache.memory.used].used = 0; + + if (flag_operate & kt_remove_flag_file_operate_directory_d) { + main->setting.state.status = f_memory_array_increase_by(path.used + f_path_separator_s.used, sizeof(f_char_t), (void **) &main->cache.memory.array[main->cache.memory.used].string, &main->cache.memory.array[main->cache.memory.used].used, &main->cache.memory.array[main->cache.memory.used].size); + } + } + + if (F_status_is_error_not(main->setting.state.status)) { + main->setting.state.status = f_string_dynamic_append_nulless(path, &main->cache.memory.array[main->cache.memory.used]); + } + + if (F_status_is_error_not(main->setting.state.status)) { + if (flag_operate & kt_remove_flag_file_operate_directory_d) { + main->setting.state.status = f_string_dynamic_append_nulless(f_path_separator_s, &main->cache.memory.array[main->cache.memory.used]); + } + } + + if (F_status_is_error_not(main->setting.state.status)) { + ++main->cache.memory.used; + main->setting.state.status = F_okay; + } } #endif // _di_kt_remove_operate_memory_save_ diff --git a/sources/c/program/kevux/tools/remove/main/operate.h b/sources/c/program/kevux/tools/remove/main/operate.h index fd5712d..d752f26 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.h +++ b/sources/c/program/kevux/tools/remove/main/operate.h @@ -196,7 +196,7 @@ extern "C" { * Must not be NULL. * * This alters main.setting.state.status: - * F_okay on success and the path is to be processed. + * F_okay on success. * F_data_not on success but path is an empty string. * * Errors (with error bit) from: f_string_dynamic_append(). -- 1.8.3.1