From 56f6f38eec42cb3849cac4fccb5ad3df676b9d8c Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 20 Jan 2025 20:02:23 -0600 Subject: [PATCH] Progress: Continue working on completing the remove program. Add fl_path dependency to utilize fl_path_canonical(). Replace project specific array reallocations with FLL array reallocations. Add missing directory parameter processing. --- data/build/remove/dependencies | 1 + data/build/remove/settings | 2 +- sources/c/program/kevux/tools/remove/main/common.c | 53 ++++------------------ sources/c/program/kevux/tools/remove/main/common.h | 44 ------------------ .../program/kevux/tools/remove/main/common/print.c | 3 +- .../program/kevux/tools/remove/main/common/print.h | 1 + .../program/kevux/tools/remove/main/common/type.c | 28 ++++++++---- .../program/kevux/tools/remove/main/common/type.h | 43 ++++++++++++++---- .../c/program/kevux/tools/remove/main/convert.c | 12 ++--- .../c/program/kevux/tools/remove/main/operate.c | 8 ++-- .../kevux/tools/remove/main/print/simulate.c | 6 +-- sources/c/program/kevux/tools/remove/main/remove.c | 12 ++++- sources/c/program/kevux/tools/remove/main/remove.h | 1 + 13 files changed, 91 insertions(+), 123 deletions(-) diff --git a/data/build/remove/dependencies b/data/build/remove/dependencies index e8ee086..48d231b 100644 --- a/data/build/remove/dependencies +++ b/data/build/remove/dependencies @@ -23,6 +23,7 @@ f_time fl_conversion fl_directory +fl_path fl_print fll_error diff --git a/data/build/remove/settings b/data/build/remove/settings index bbcbb26..d7c7ab2 100644 --- a/data/build/remove/settings +++ b/data/build/remove/settings @@ -38,7 +38,7 @@ build_language c build_libraries -lc build_libraries-individual -lfll_error -lfll_print -lfll_program -build_libraries-individual -lfl_conversion -fl_directory -lfl_print +build_libraries-individual -lfl_conversion -fl_directory -lfl_path -lfl_print build_libraries-individual -lf_account -lf_color -lf_compare -lf_console -lf_conversion -lf_directory -lf_file -lf_memory -lf_path -lf_pipe -lf_print -lf_rip -lf_signal -lf_string -lf_time -lf_type_array -lf_utf build_libraries-individual_thread -lf_thread build_libraries-level -lfll_2 -lfll_1 -lfll_0 diff --git a/sources/c/program/kevux/tools/remove/main/common.c b/sources/c/program/kevux/tools/remove/main/common.c index 82a4b9b..802ee47 100644 --- a/sources/c/program/kevux/tools/remove/main/common.c +++ b/sources/c/program/kevux/tools/remove/main/common.c @@ -4,46 +4,6 @@ extern "C" { #endif -#ifndef _di_kt_remove_dates_resize_ - f_status_t kt_remove_dates_resize(const f_number_unsigned_t length, kt_remove_dates_t * const dates) { - - if (!dates) return F_status_set_error(F_parameter); - - if (dates->used + length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); - - const f_status_t status = f_memory_resize(dates->size, length, sizeof(kt_remove_date_t), (void **) & dates->array); - if (F_status_is_error(status)) return status; - - dates->size = length; - - if (dates->used > dates->size) { - dates->used = length; - } - - return F_okay; - } -#endif // _di_kt_remove_dates_resize_ - -#ifndef _di_kt_remove_modes_resize_ - f_status_t kt_remove_modes_resize(const f_number_unsigned_t length, kt_remove_modes_t * const modes) { - - if (!modes) return F_status_set_error(F_parameter); - - if (modes->used + length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); - - const f_status_t status = f_memory_resize(modes->size, length, sizeof(kt_remove_mode_t), (void **) & modes->array); - if (F_status_is_error(status)) return status; - - modes->size = length; - - if (modes->used > modes->size) { - modes->used = length; - } - - return F_okay; - } -#endif // _di_kt_remove_modes_resize_ - #ifndef _di_kt_remove_setting_load_ void kt_remove_setting_load(const f_console_arguments_t arguments, kt_remove_main_t * const main) { @@ -209,6 +169,11 @@ extern "C" { } } + if (main->program.parameters.array[kt_remove_parameter_directory_e].result & f_console_result_found_e) { + main->setting.flag |= kt_remove_main_flag_directory_d; + main->setting.flag |= kt_remove_main_flag_option_used_d; + } + if (main->program.parameters.array[kt_remove_parameter_force_e].result & f_console_result_found_e) { main->setting.flag |= kt_remove_main_flag_force_d; } @@ -276,10 +241,10 @@ extern "C" { } if (dates[p]->used + total_locations > dates[p]->size) { - main->setting.state.status = kt_remove_dates_resize(dates[p]->size + (total_locations - dates[p]->size), dates[p]); + main->setting.state.status = f_memory_array_resize(dates[p]->size + (total_locations - dates[p]->size), sizeof(kt_remove_date_t), (void **) &dates[p]->array, &dates[p]->used, &dates[p]->size); if (F_status_is_error(main->setting.state.status)) { - kt_remove_print_error(&main->program.error, macro_kt_remove_f(kt_remove_dates_resize)); + kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_memory_array_resize)); return; } @@ -518,10 +483,10 @@ extern "C" { } if (main->setting.modes.used + total_locations > main->setting.modes.size) { - main->setting.state.status = kt_remove_modes_resize(main->setting.modes.size + (total_locations - main->setting.modes.size), &main->setting.modes); + main->setting.state.status = f_memory_array_resize(main->setting.modes.size + (total_locations - main->setting.modes.size), sizeof(kt_remove_mode_t), (void **) &main->setting.modes.array, &main->setting.modes.used, &main->setting.modes.size); if (F_status_is_error(main->setting.state.status)) { - kt_remove_print_error(&main->program.error, macro_kt_remove_f(kt_remove_modes_resize)); + kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_memory_array_resize)); return; } diff --git a/sources/c/program/kevux/tools/remove/main/common.h b/sources/c/program/kevux/tools/remove/main/common.h index e2f7ac9..64ba7a6 100644 --- a/sources/c/program/kevux/tools/remove/main/common.h +++ b/sources/c/program/kevux/tools/remove/main/common.h @@ -17,50 +17,6 @@ extern "C" { #endif /** - * Resize a date array. @todo migrate this? - * - * @param length - * The new size to use. - * @param dates - * The array to resize. - * - * Must not be NULL. - * - * @return - * F_okay on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_kt_remove_dates_resize_ - extern f_status_t kt_remove_dates_resize(const f_number_unsigned_t length, kt_remove_dates_t * const dates); -#endif // _di_kt_remove_dates_resize_ - -/** - * Resize a mode array. @todo migrate this? - * - * @param length - * The new size to use. - * @param modes - * The array to resize. - * - * Must not be NULL. - * - * @return - * F_okay on success. - * - * F_array_too_large (with error bit) if the combined array is too large. - * F_parameter (with error bit) if a parameter is invalid. - * - * Errors (with error bit) from: f_memory_resize(). - */ -#ifndef _di_kt_remove_modes_resize_ - extern f_status_t kt_remove_modes_resize(const f_number_unsigned_t length, kt_remove_modes_t * const modes); -#endif // _di_kt_remove_modes_resize_ - -/** * Perform the standard program setting load process. * * This prints error messages as appropriate. 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 1803800..9174dcc 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.c +++ b/sources/c/program/kevux/tools/remove/main/common/print.c @@ -18,15 +18,14 @@ extern "C" { "f_utf_is_whitespace", "fl_conversion_dynamic_partial_to_unsigned_detect", "fl_conversion_dynamic_to_unsigned_detect", + "fl_path_canonical", "fll_program_parameter_process_context", "fll_program_parameter_process_empty", "fll_program_parameter_process_verbosity", "kt_remove_convert_date_relative", "kt_remove_convert_timezone", - "kt_remove_dates_resize", "kt_remove_get_id_group", "kt_remove_get_id_user", - "kt_remove_modes_resize", }; #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 40cf000..c7a7296 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.h +++ b/sources/c/program/kevux/tools/remove/main/common/print.h @@ -51,6 +51,7 @@ extern "C" { kt_remove_f_f_utf_is_whitespace_e, kt_remove_f_fl_conversion_dynamic_partial_to_unsigned_detect_e, kt_remove_f_fl_conversion_dynamic_to_unsigned_detect_e, + kt_remove_f_fl_path_canonical_e, kt_remove_f_fll_program_parameter_process_context_e, kt_remove_f_fll_program_parameter_process_empty_e, kt_remove_f_fll_program_parameter_process_verbosity_e, diff --git a/sources/c/program/kevux/tools/remove/main/common/type.c b/sources/c/program/kevux/tools/remove/main/common/type.c index 0f7e09d..5639d40 100644 --- a/sources/c/program/kevux/tools/remove/main/common/type.c +++ b/sources/c/program/kevux/tools/remove/main/common/type.c @@ -4,35 +4,45 @@ extern "C" { #endif + +#ifndef _di_kt_remove_cache_delete_ + void kt_remove_cache_delete(kt_remove_cache_t * const cache) { + + if (!cache) return; + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->file.string, &cache->file.used, &cache->file.size); + } +#endif // _di_kt_remove_cache_delete_ + #ifndef _di_kt_remove_main_delete_ void kt_remove_main_delete(kt_remove_main_t * const main) { if (!main) return; fll_program_data_delete(&main->program); + + kt_remove_cache_delete(&main->cache); kt_remove_setting_delete(&main->setting); } #endif // _di_kt_remove_main_delete_ #ifndef _di_kt_remove_setting_delete_ - f_status_t kt_remove_setting_delete(kt_remove_setting_t * const setting) { + void kt_remove_setting_delete(kt_remove_setting_t * const setting) { - if (!setting) return F_status_set_error(F_parameter); + if (!setting) return; - f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->buffer.string, &setting->buffer.used, &setting->buffer.size); f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &setting->files.array, &setting->files.used, &setting->files.size, &f_string_dynamics_delete_callback); - kt_remove_dates_resize(0, &setting->accessed); - kt_remove_dates_resize(0, &setting->changed); - kt_remove_dates_resize(0, &setting->updated); - kt_remove_modes_resize(0, &setting->modes); + f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->accessed.array, &setting->accessed.used, &setting->accessed.size); + f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->changed.array, &setting->changed.used, &setting->changed.size); + f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->updated.array, &setting->updated.used, &setting->updated.size); + f_memory_array_resize(0, sizeof(kt_remove_mode_t), (void **) &setting->modes.array, &setting->modes.used, &setting->modes.size); f_memory_array_resize(0, sizeof(uint32_t), (void **) &setting->groups.array, &setting->groups.used, &setting->groups.size); f_memory_array_resize(0, sizeof(uint32_t), (void **) &setting->users.array, &setting->users.used, &setting->users.size); f_directory_recurse_do_delete(&setting->recurse); - - return F_okay; } #endif // _di_kt_remove_setting_delete_ diff --git a/sources/c/program/kevux/tools/remove/main/common/type.h b/sources/c/program/kevux/tools/remove/main/common/type.h index a7ddb12..4d0ca34 100644 --- a/sources/c/program/kevux/tools/remove/main/common/type.h +++ b/sources/c/program/kevux/tools/remove/main/common/type.h @@ -138,6 +138,25 @@ extern "C" { #endif // _di_kt_remove_modes_t_ /** + * The program cache. + * + * buffer: The generic buffer. + * file: The current file being processed (generally canonicalized). + */ +#ifndef _di_kt_remove_cache_t_ + typedef struct { + f_string_dynamic_t buffer; + f_string_dynamic_t file; + } kt_remove_cache_t; + + #define kt_remove_cache_t_initialize \ + { \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + } +#endif // _di_kt_remove_cache_t_ + +/** * The main program settings. * * This is passed to the program-specific main entry point to designate program settings. @@ -151,7 +170,6 @@ extern "C" { * program_name: The short name of the program. * program_name_long: The human friendly name of the program. * - * buffer: A string buffer used for caching purposes. * files: An array of file names (full paths to the files) to remove. * * accessed: An array of last accessed dates used for comparison. @@ -173,7 +191,6 @@ extern "C" { f_status_t status_thread; f_state_t state; - f_string_dynamic_t buffer; f_string_dynamics_t files; kt_remove_dates_t accessed; @@ -199,7 +216,6 @@ extern "C" { kt_remove_main_flag_none_d, \ F_okay, \ macro_f_state_t_initialize_1(kt_remove_allocation_large_d, kt_remove_allocation_small_d, F_okay, 0, 0, &fll_program_standard_signal_handle, 0, 0, 0, 0), \ - f_string_dynamic_t_initialize, \ f_string_dynamics_t_initialize, \ kt_remove_dates_t_initialize, \ kt_remove_dates_t_initialize, \ @@ -227,16 +243,30 @@ extern "C" { struct kt_remove_main_t_ { fll_program_data_t program; kt_remove_setting_t setting; + kt_remove_cache_t cache; }; #define kt_remove_main_t_initialize \ { \ fll_program_data_t_initialize, \ kt_remove_setting_t_initialize, \ + kt_remove_cache_t_initialize, \ } #endif // _di_kt_remove_main_t_ /** + * Delete the program main setting data. + * + * @param cache + * The program main cache data. + * + * This does not alter setting.state.status. + */ +#ifndef _di_kt_remove_cache_delete_ + extern void kt_remove_cache_delete(kt_remove_cache_t * const cache); +#endif // _di_kt_remove_cache_delete_ + +/** * Deallocate main program data. * * @param setting_make @@ -255,14 +285,9 @@ extern "C" { * The program main setting data. * * This does not alter setting.state.status. - * - * @return - * F_okay on success. - * - * F_parameter (with error bit) if a parameter is invalid. */ #ifndef _di_kt_remove_setting_delete_ - extern f_status_t kt_remove_setting_delete(kt_remove_setting_t * const setting); + extern void kt_remove_setting_delete(kt_remove_setting_t * const setting); #endif // _di_kt_remove_setting_delete_ #ifdef __cplusplus diff --git a/sources/c/program/kevux/tools/remove/main/convert.c b/sources/c/program/kevux/tools/remove/main/convert.c index 64d1c42..51cf74b 100644 --- a/sources/c/program/kevux/tools/remove/main/convert.c +++ b/sources/c/program/kevux/tools/remove/main/convert.c @@ -436,14 +436,14 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_number) { - main->setting.buffer.used = 0; + main->cache.buffer.used = 0; - main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->setting.buffer); + main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->cache.buffer); if (F_status_is_error(main->setting.state.status)) return 0; gid_t gid = 0; - main->setting.state.status = f_account_group_id_by_name(main->setting.buffer, &gid); + main->setting.state.status = f_account_group_id_by_name(main->cache.buffer, &gid); if (F_status_is_error(main->setting.state.status)) return 0; if (main->setting.state.status == F_exist_not) { @@ -483,14 +483,14 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_number) { - main->setting.buffer.used = 0; + main->cache.buffer.used = 0; - main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->setting.buffer); + main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->cache.buffer); if (F_status_is_error(main->setting.state.status)) return 0; uid_t uid = 0; - main->setting.state.status = f_account_id_by_name(main->setting.buffer, &uid); + main->setting.state.status = f_account_id_by_name(main->cache.buffer, &uid); if (F_status_is_error(main->setting.state.status)) return 0; if (main->setting.state.status == F_exist_not) { diff --git a/sources/c/program/kevux/tools/remove/main/operate.c b/sources/c/program/kevux/tools/remove/main/operate.c index 0755455..76742e2 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.c +++ b/sources/c/program/kevux/tools/remove/main/operate.c @@ -449,9 +449,9 @@ extern "C" { // @todo consider providing a "follow deep" parameter for recursively following until a non-link is reached. if (flag & kt_remove_flag_file_operate_follow_d) { - main->setting.buffer.used = 0; + main->cache.buffer.used = 0; - main->setting.state.status = f_file_link_read(path, F_false, &main->setting.buffer); + main->setting.state.status = f_file_link_read(path, F_false, &main->cache.buffer); if (F_status_is_error(main->setting.state.status)) { kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), path, f_file_operation_stat_s, fll_error_file_type_link_e); @@ -459,10 +459,10 @@ extern "C" { return; } - main->setting.state.status = f_file_remove(main->setting.buffer); + main->setting.state.status = f_file_remove(main->cache.buffer); if (F_status_is_error(main->setting.state.status)) { - kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), main->setting.buffer, f_file_operation_delete_s, fll_error_file_type_file_e); + kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), main->cache.buffer, f_file_operation_delete_s, fll_error_file_type_file_e); return; } diff --git a/sources/c/program/kevux/tools/remove/main/print/simulate.c b/sources/c/program/kevux/tools/remove/main/print/simulate.c index 112b5c5..19e6913 100644 --- a/sources/c/program/kevux/tools/remove/main/print/simulate.c +++ b/sources/c/program/kevux/tools/remove/main/print/simulate.c @@ -67,9 +67,9 @@ extern "C" { } if (status == F_true) { - main->setting.buffer.used = 0; + main->cache.buffer.used = 0; - status = f_file_link_read(path, F_false, &main->setting.buffer); + status = f_file_link_read(path, F_false, &main->cache.buffer); if (F_status_is_error(status)) { fl_print_format(" link_read_failure %ui%r", main->program.output.to, F_status_set_fine(status), f_string_eol_s); @@ -80,7 +80,7 @@ extern "C" { f_file_stream_lock(main->program.output.to); fl_print_format(" follow %r%r", main->program.output.to, (main->setting.flag & kt_remove_main_flag_follow_d) ? kt_remove_yes_s : kt_remove_no_s, f_string_eol_s); - fl_print_format(" to '%Q'%r", main->program.output.to, main->setting.buffer, f_string_eol_s); + fl_print_format(" to '%Q'%r", main->program.output.to, main->cache.buffer, f_string_eol_s); f_file_stream_unlock(main->program.output.to); } diff --git a/sources/c/program/kevux/tools/remove/main/remove.c b/sources/c/program/kevux/tools/remove/main/remove.c index 97e9872..0be2b55 100644 --- a/sources/c/program/kevux/tools/remove/main/remove.c +++ b/sources/c/program/kevux/tools/remove/main/remove.c @@ -59,7 +59,17 @@ extern "C" { for (f_number_unsigned_t i = 0; i < main->setting.files.used; ++i) { - kt_remove_operate_file(main, main->setting.files.array[i]); + main->cache.file.used = 0; + + fl_path_canonical(main->setting.files.array[i], &main->cache.file); + + if (F_status_is_error(main->setting.state.status)) { + kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(fl_path_canonical), main->setting.files.array[i], f_file_operation_process_s, fll_error_file_type_path_e); + + break; + } + + kt_remove_operate_file(main, main->cache.file); if ((main->setting.flag & kt_remove_main_flag_simulate_d) && i + 1 < main->setting.files.used && (F_status_is_error_not(main->setting.state.status) || F_status_set_fine(main->setting.state.status) == F_interrupt)) { f_print_dynamic(f_string_eol_s, main->program.output.to); diff --git a/sources/c/program/kevux/tools/remove/main/remove.h b/sources/c/program/kevux/tools/remove/main/remove.h index 736ceab..c2da234 100644 --- a/sources/c/program/kevux/tools/remove/main/remove.h +++ b/sources/c/program/kevux/tools/remove/main/remove.h @@ -41,6 +41,7 @@ // FLL-1 includes. #include #include +#include #include // FLL-2 includes. -- 1.8.3.1