From af94cf83e5f02bde3763b9249772e7b3bb4794d5 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 27 Jan 2025 23:10:46 -0600 Subject: [PATCH] Progress: Continue working on completing the remove program. Bring in recent signal change logic from other FLL projects and code. Start working on the `--tree` parameter. Other minor improvements. --- data/build/stand_alone/configs/remove-config.h | 2 +- sources/c/program/kevux/tools/remove/main/common.c | 14 +- .../kevux/tools/remove/main/common/define.h | 28 +-- .../program/kevux/tools/remove/main/common/print.c | 1 + .../program/kevux/tools/remove/main/common/print.h | 1 + .../program/kevux/tools/remove/main/common/type.c | 2 +- .../program/kevux/tools/remove/main/common/type.h | 10 +- .../c/program/kevux/tools/remove/main/convert.c | 74 ++++--- .../c/program/kevux/tools/remove/main/operate.c | 231 ++++++++++++--------- .../c/program/kevux/tools/remove/main/operate.h | 20 +- .../program/kevux/tools/remove/main/print/error.c | 8 +- .../kevux/tools/remove/main/print/simulate.c | 76 +++---- sources/c/program/kevux/tools/remove/main/remove.c | 18 +- sources/c/program/kevux/tools/remove/main/signal.c | 24 +-- .../c/program/kevux/tools/tacocat/main/signal.c | 8 +- .../c/program/kevux/tools/tacocat/main/tacocat.c | 8 +- 16 files changed, 278 insertions(+), 247 deletions(-) diff --git a/data/build/stand_alone/configs/remove-config.h b/data/build/stand_alone/configs/remove-config.h index 9bef11e..a29a165 100644 --- a/data/build/stand_alone/configs/remove-config.h +++ b/data/build/stand_alone/configs/remove-config.h @@ -903,7 +903,7 @@ #define _di_f_string_dynamic_seek_line_to_ #define _di_f_string_dynamic_seek_line_to_back_ #define _di_f_string_dynamic_seek_to_ -#define _di_f_string_dynamic_seek_to_back_ +//#define _di_f_string_dynamic_seek_to_back_ #define _di_f_string_dynamic_strip_null_ #define _di_f_string_dynamic_strip_null_range_ //#define _di_f_string_dynamic_t_ diff --git a/sources/c/program/kevux/tools/remove/main/common.c b/sources/c/program/kevux/tools/remove/main/common.c index 36c2c72..277115c 100644 --- a/sources/c/program/kevux/tools/remove/main/common.c +++ b/sources/c/program/kevux/tools/remove/main/common.c @@ -583,13 +583,19 @@ extern "C" { return; } - for (i = 0; i < main->program.parameters.remaining.used; ++i) { + for (i = 0; i < main->program.parameters.remaining.used; ++i, ++main->setting.files.used) { index = main->program.parameters.remaining.array[i]; - main->setting.files.array[main->setting.files.used].string = main->program.parameters.arguments.array[index].string; - main->setting.files.array[main->setting.files.used].used = main->program.parameters.arguments.array[index].used; - main->setting.files.array[main->setting.files.used++].size = 0; + main->setting.files.array[main->setting.files.used].used = 0; + + fl_path_clean(main->program.parameters.arguments.array[index], &main->setting.files.array[main->setting.files.used]); + + if (F_status_is_error(main->setting.state.status)) { + kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(fl_path_clean), main->program.parameters.arguments.array[index], f_file_operation_process_s, fll_error_file_type_path_e); + + return; + } } // for } } diff --git a/sources/c/program/kevux/tools/remove/main/common/define.h b/sources/c/program/kevux/tools/remove/main/common/define.h index b5b1fb9..94ab57e 100644 --- a/sources/c/program/kevux/tools/remove/main/common/define.h +++ b/sources/c/program/kevux/tools/remove/main/common/define.h @@ -144,9 +144,11 @@ extern "C" { * * kt_remove_flag_file_operate_*_d: * - none: No flags set. + * - child: This is a child of a file for some other file operation process. * - directory: Is a directory. * - empty: Is an empty directory. * - follow: Follow the symbolic link. + * - parent: This is a parent of a file for some other file operation process. * - recurse: Perform recursively (only on directories). * - remove: Perform remove. * - remove_fail: Cannot perform remove due to failure. @@ -155,14 +157,16 @@ extern "C" { */ #ifndef _di_kt_remove_flag_file_operate_d_ #define kt_remove_flag_file_operate_none_d 0x0 - #define kt_remove_flag_file_operate_directory_d 0x1 - #define kt_remove_flag_file_operate_empty_d 0x2 - #define kt_remove_flag_file_operate_follow_d 0x4 - #define kt_remove_flag_file_operate_recurse_d 0x8 - #define kt_remove_flag_file_operate_remove_d 0x10 - #define kt_remove_flag_file_operate_remove_fail_d 0x20 - #define kt_remove_flag_file_operate_remove_not_d 0x40 - #define kt_remove_flag_file_operate_remove_not_fail_d 0x60 + #define kt_remove_flag_file_operate_child_d 0x1 + #define kt_remove_flag_file_operate_directory_d 0x2 + #define kt_remove_flag_file_operate_empty_d 0x4 + #define kt_remove_flag_file_operate_follow_d 0x8 + #define kt_remove_flag_file_operate_parent_d 0x10 + #define kt_remove_flag_file_operate_recurse_d 0x20 + #define kt_remove_flag_file_operate_remove_d 0x40 + #define kt_remove_flag_file_operate_remove_fail_d 0x80 + #define kt_remove_flag_file_operate_remove_not_d 0x100 + #define kt_remove_flag_file_operate_remove_not_fail_d 0x200 #endif // _di_kt_remove_flag_file_operate_d_ /** @@ -171,16 +175,16 @@ extern "C" { * kt_remove_flag_mode_*_e: * - none: No flags set. * - different: Remove by mode matching different parts ('~~' or 'different'). + * - not: Remove by not exact mode match ('<>' or 'not'). * - same: Remove by exact mode match ('==' or 'same'). * - similar: Remove by mode matching same parts ('~=' or 'similar'). - * - not: Remove by not exact mode match ('<>' or 'not'). */ #ifndef _di_kt_remove_flag_mode_d_ #define kt_remove_flag_mode_none_d 0x0 #define kt_remove_flag_mode_different_d 0x1 - #define kt_remove_flag_mode_same_d 0x2 - #define kt_remove_flag_mode_similar_d 0x4 - #define kt_remove_flag_mode_not_d 0x8 + #define kt_remove_flag_mode_not_d 0x2 + #define kt_remove_flag_mode_same_d 0x4 + #define kt_remove_flag_mode_similar_d 0x8 #endif // _di_kt_remove_flag_mode_d_ /** 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 6c6cab4..e3de23c 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.c +++ b/sources/c/program/kevux/tools/remove/main/common/print.c @@ -13,6 +13,7 @@ extern "C" { "f_file_remove", "f_memory_array_increase_by", "f_memory_array_resize", + "f_string_dynamic_seek_to_back", "f_thread_create", "f_utf_is_digit", "f_utf_is_whitespace", 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 83d74fd..de67b89 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.h +++ b/sources/c/program/kevux/tools/remove/main/common/print.h @@ -46,6 +46,7 @@ extern "C" { kt_remove_f_f_file_remove_e, kt_remove_f_f_memory_array_increase_by_e, kt_remove_f_f_memory_array_resize_e, + kt_remove_f_f_string_dynamic_seek_to_back_e, kt_remove_f_f_thread_create_e, kt_remove_f_f_utf_is_digit_e, kt_remove_f_f_utf_is_whitespace_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 5639d40..ec0cf6f 100644 --- a/sources/c/program/kevux/tools/remove/main/common/type.c +++ b/sources/c/program/kevux/tools/remove/main/common/type.c @@ -11,7 +11,7 @@ extern "C" { 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); + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &cache->files.array, &cache->files.used, &cache->files.size, &f_string_dynamics_delete_callback); } #endif // _di_kt_remove_cache_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 ab1d8ce..6c19965 100644 --- a/sources/c/program/kevux/tools/remove/main/common/type.h +++ b/sources/c/program/kevux/tools/remove/main/common/type.h @@ -141,18 +141,18 @@ extern "C" { * The program cache. * * buffer: The generic buffer. - * file: The current file being processed (generally cleaned up). + * files: A collection of files, often used during path recursion like those associated with the tree parameter. */ #ifndef _di_kt_remove_cache_t_ typedef struct { f_string_dynamic_t buffer; - f_string_dynamic_t file; + f_string_dynamics_t files; } kt_remove_cache_t; #define kt_remove_cache_t_initialize \ { \ f_string_dynamic_t_initialize, \ - f_string_dynamic_t_initialize, \ + f_string_dynamics_t_initialize, \ } #endif // _di_kt_remove_cache_t_ @@ -207,8 +207,8 @@ extern "C" { f_status_t (*print_help)(fl_print_t * const print, const f_color_context_t context); void (*process_normal)(kt_remove_main_t * const main); - void (*process_operate_file)(kt_remove_main_t * const main, const f_string_static_t path, const struct stat statistics, uint8_t * const flag); - void (*process_operate_file_simulate)(kt_remove_main_t * const main, const f_string_static_t path, const struct stat statistics, uint8_t * const flag); + void (*process_operate_file)(kt_remove_main_t * const main, const f_string_static_t path, const struct stat statistics, uint16_t * const flag); + void (*process_operate_file_simulate)(kt_remove_main_t * const main, const f_string_static_t path, const struct stat statistics, const uint16_t flag_operate, uint16_t * const flag); } kt_remove_setting_t; #define kt_remove_setting_t_initialize \ diff --git a/sources/c/program/kevux/tools/remove/main/convert.c b/sources/c/program/kevux/tools/remove/main/convert.c index 51cf74b..83f1ba4 100644 --- a/sources/c/program/kevux/tools/remove/main/convert.c +++ b/sources/c/program/kevux/tools/remove/main/convert.c @@ -439,36 +439,35 @@ extern "C" { main->cache.buffer.used = 0; 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; + if (F_status_is_error_not(main->setting.state.status)) { + gid_t gid = 0; - 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; + main->setting.state.status = f_account_group_id_by_name(main->cache.buffer, &gid); - if (main->setting.state.status == F_exist_not) { - main->setting.state.status = F_status_set_error(F_exist_not); + if (F_status_is_error_not(main->setting.state.status)) { + if (F_status_set_fine(main->setting.state.status) == F_exist_not) { + main->setting.state.status = F_status_set_error(F_exist_not); + } + else { + main->setting.state.status = F_okay; - return 0; + return (uint32_t) gid; + } + } } - - main->setting.state.status = F_okay; - - return (uint32_t) gid; } - - return 0; } - - if (number > F_type_size_32_unsigned_d) { + else if (number > F_type_size_32_unsigned_d) { main->setting.state.status = F_status_set_error(F_number_too_large); - - return 0; } + else { + main->setting.state.status = F_okay; - main->setting.state.status = F_okay; + return (uint32_t) number; + } - return (uint32_t) number; + return 0; } #endif // _di_kt_remove_get_id_group_ @@ -486,36 +485,35 @@ extern "C" { main->cache.buffer.used = 0; 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; + if (F_status_is_error_not(main->setting.state.status)) { + uid_t uid = 0; - main->setting.state.status = f_account_id_by_name(main->cache.buffer, &uid); - if (F_status_is_error(main->setting.state.status)) return 0; + main->setting.state.status = f_account_id_by_name(main->cache.buffer, &uid); - if (main->setting.state.status == F_exist_not) { - main->setting.state.status = F_status_set_error(F_exist_not); + if (F_status_is_error_not(main->setting.state.status)) { + if (F_status_set_fine(main->setting.state.status) == F_exist_not) { + main->setting.state.status = F_status_set_error(F_exist_not); + } + else { + main->setting.state.status = F_okay; - return 0; + return (uint32_t) uid; + } + } } - - main->setting.state.status = F_okay; - - return (uint32_t) uid; } - - return 0; } - - if (number > F_type_size_32_unsigned_d) { + else if (number > F_type_size_32_unsigned_d) { main->setting.state.status = F_status_set_error(F_number_too_large); - - return 0; } + else { + main->setting.state.status = F_okay; - main->setting.state.status = F_okay; + return (uint32_t) number; + } - return (uint32_t) number; + return 0; } #endif // _di_kt_remove_get_id_user_ diff --git a/sources/c/program/kevux/tools/remove/main/operate.c b/sources/c/program/kevux/tools/remove/main/operate.c index 6ced5dc..443de5c 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.c +++ b/sources/c/program/kevux/tools/remove/main/operate.c @@ -17,15 +17,15 @@ extern "C" { if (kt_remove_signal_check(main)) return; - const uint8_t flag = kt_remove_operate_file_simulate(main, path); + const uint16_t flag_operate = kt_remove_operate_file_simulate(main, path, 0); if (F_status_is_error(main->setting.state.status)) return; if (!(main->setting.flag & kt_remove_main_flag_simulate_d)) { - if (flag & kt_remove_flag_file_operate_directory_d) { - kt_remove_operate_file_directory(main, path, flag); + if (flag_operate & kt_remove_flag_file_operate_directory_d) { + kt_remove_operate_file_directory(main, path, flag_operate); } else { - kt_remove_operate_file_normal(main, path, flag); + kt_remove_operate_file_normal(main, path, flag_operate); } if (F_status_is_error(main->setting.state.status)) return; @@ -36,21 +36,21 @@ extern "C" { #endif // _di_kt_remove_operate_file_ #ifndef _di_kt_remove_operate_file_directory_ - void kt_remove_operate_file_directory(kt_remove_main_t * const main, const f_string_static_t path, const uint8_t flag) { + void kt_remove_operate_file_directory(kt_remove_main_t * const main, const f_string_static_t path, const uint16_t flag_operate) { - if (!(flag & kt_remove_flag_file_operate_remove_d) || flag & kt_remove_flag_file_operate_remove_not_fail_d) { - main->setting.state.status = (flag & kt_remove_flag_file_operate_remove_fail_d) ? F_status_set_error(F_no) : F_no; + if (!(flag_operate & kt_remove_flag_file_operate_remove_d) || flag_operate & kt_remove_flag_file_operate_remove_not_fail_d) { + main->setting.state.status = (flag_operate & kt_remove_flag_file_operate_remove_fail_d) ? F_status_set_error(F_no) : F_no; return; } main->setting.recurse.state.custom = (void *) main; - main->setting.recurse.state.code = flag; + main->setting.recurse.state.code = flag_operate; main->setting.recurse.flag = f_directory_recurse_do_flag_list_e | f_directory_recurse_do_flag_after_e; // @todo consider this in recursion and maybe provide a new parameter follow_recurse for this. - /*if (flag & kt_remove_flag_file_operate_follow_d) { - data.setting.recurse.flag |= f_directory_recurse_do_flag_dereference_e; + /*if (flag_operate & kt_remove_flag_file_operate_follow_d) { + main->setting.recurse.flag |= f_directory_recurse_do_flag_dereference_e; }*/ fl_directory_do(path, &main->setting.recurse); @@ -105,17 +105,17 @@ extern "C" { kt_remove_operate_file(main, name); recurse->state.status = main->setting.state.status; - const uint8_t flag = kt_remove_operate_file_simulate(main, name); + const uint16_t flag_operate = kt_remove_operate_file_simulate(main, name, 0); if (F_status_is_error(main->setting.state.status)) return; if (!(main->setting.flag & kt_remove_main_flag_simulate_d)) { // @todo needs empty check to see if directory contents are fully removed (because of removal conditions). - if (flag & kt_remove_flag_file_operate_directory_d) { - kt_remove_operate_file_directory(main, name, flag); + if (flag_operate & kt_remove_flag_file_operate_directory_d) { + kt_remove_operate_file_directory(main, name, flag_operate); } else { - kt_remove_operate_file_normal(main, name, flag); + kt_remove_operate_file_normal(main, name, flag_operate); } if (F_status_is_error(main->setting.state.status)) return; @@ -183,8 +183,51 @@ extern "C" { } #endif // _di_kt_remove_operate_file_directory_recurse_handle_ +#ifndef _di_kt_remove_operate_file_normal_ + void kt_remove_operate_file_normal(kt_remove_main_t * const main, const f_string_static_t path, const uint16_t flag_operate) { + + if (!(flag_operate & kt_remove_flag_file_operate_remove_d) || flag_operate & kt_remove_flag_file_operate_remove_not_fail_d) { + main->setting.state.status = (flag_operate & kt_remove_flag_file_operate_remove_fail_d) ? F_status_set_error(F_no) : F_no; + + return; + } + + // @todo consider providing a "follow deep" parameter for recursively following until a non-link is reached. + if (flag_operate & kt_remove_flag_file_operate_follow_d) { + main->cache.buffer.used = 0; + + 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); + + return; + } + + 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->cache.buffer, f_file_operation_delete_s, fll_error_file_type_file_e); + + return; + } + } + else { + main->setting.state.status = f_file_remove(path); + + 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_delete_s, fll_error_file_type_file_e); + + return; + } + } + + main->setting.state.status = F_yes; + } +#endif // _di_kt_remove_operate_file_normal_ + #ifndef _di_kt_remove_operate_file_simulate_ - uint8_t kt_remove_operate_file_simulate(kt_remove_main_t * const main, const f_string_static_t path) { + uint16_t kt_remove_operate_file_simulate(kt_remove_main_t * const main, const f_string_static_t path, const uint16_t flag_operate) { if (!main) return 0; @@ -227,10 +270,10 @@ extern "C" { if (kt_remove_signal_check(main)) return 0; f_number_unsigned_t i = 0; - uint8_t flag = (main->setting.flag & kt_remove_main_flag_option_used_d) ? 0 : kt_remove_flag_file_operate_remove_d; + uint16_t flag_out = (main->setting.flag & kt_remove_main_flag_option_used_d) ? 0 : kt_remove_flag_file_operate_remove_d; if (main->setting.flag & kt_remove_main_flag_follow_d) { - flag |= kt_remove_flag_file_operate_follow_d; + flag_out |= kt_remove_flag_file_operate_follow_d; } struct stat statistics; @@ -246,86 +289,86 @@ extern "C" { remove_print_warning_file_reason(&main->program.warning, path, kt_remove_print_reason_stat_fail_s); } - return flag; + return flag_out; } if (main->setting.flag & kt_remove_main_flag_block_d) { if (macro_f_file_type_is_block(statistics.st_mode)) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_character_d) { if (macro_f_file_type_is_character(statistics.st_mode)) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (macro_f_file_type_is_directory(statistics.st_mode)) { - flag |= kt_remove_flag_file_operate_directory_d; + flag_out |= kt_remove_flag_file_operate_directory_d; if (main->setting.flag & kt_remove_main_flag_directory_d) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_fifo_d) { if (macro_f_file_type_is_fifo(statistics.st_mode)) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_link_d) { if (macro_f_file_type_is_link(statistics.st_mode)) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_regular_d) { if (macro_f_file_type_is_regular(statistics.st_mode)) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_socket_d) { if (macro_f_file_type_is_socket(statistics.st_mode)) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_user_d) { for (i = 0; i < main->setting.users.used; ++i) { - if (kt_remove_signal_check(main)) return flag; + if (kt_remove_signal_check(main)) return flag_out; if (statistics.st_uid == (uid_t) main->setting.users.array[i]) break; } // for if (i < main->setting.users.used) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_same_d) { if (statistics.st_uid != geteuid()) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_different_d) { if (statistics.st_uid == geteuid()) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } if (main->setting.flag & kt_remove_main_flag_group_d) { for (i = 0; i < main->setting.groups.used; ++i) { - if (kt_remove_signal_check(main)) return flag; + if (kt_remove_signal_check(main)) return flag_out; if (statistics.st_gid == (gid_t) main->setting.groups.array[i]) break; } // for if (i < main->setting.groups.used) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } @@ -334,7 +377,7 @@ extern "C" { for (i = 0; i < main->setting.modes.used; ++i) { - if (kt_remove_signal_check(main)) return flag; + if (kt_remove_signal_check(main)) return flag_out; if (main->setting.modes.array[i].type == kt_remove_flag_mode_different_d) { if (main->setting.modes.array[i].mode & ~mode) break; @@ -351,135 +394,123 @@ extern "C" { } // for if (i < main->setting.modes.used) { - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } } - if (flag & kt_remove_flag_file_operate_directory_d) { - flag |= kt_remove_flag_file_operate_recurse_d; + if (flag_out & kt_remove_flag_file_operate_directory_d) { + flag_out |= kt_remove_flag_file_operate_recurse_d; main->setting.state.status = f_directory_empty(path); - if (F_status_is_error(main->setting.state.status)) return flag; + if (F_status_is_error(main->setting.state.status)) return flag_out; if (main->setting.state.status) { - flag |= kt_remove_flag_file_operate_empty_d; + flag_out |= kt_remove_flag_file_operate_empty_d; } if (main->setting.flag & kt_remove_main_flag_empty_all_d) { if (main->setting.state.status) { if (main->setting.flag & kt_remove_main_flag_empty_not_fail_d) { - flag |= kt_remove_flag_file_operate_remove_fail_d; + flag_out |= kt_remove_flag_file_operate_remove_fail_d; } else if (main->setting.flag & kt_remove_main_flag_empty_not_d) { - flag |= kt_remove_flag_file_operate_remove_not_d; + flag_out |= kt_remove_flag_file_operate_remove_not_d; } } else { if (main->setting.flag & kt_remove_main_flag_empty_only_fail_d) { - flag |= kt_remove_flag_file_operate_remove_fail_d; + flag_out |= kt_remove_flag_file_operate_remove_fail_d; } else if (main->setting.flag & kt_remove_main_flag_empty_only_d || !(main->setting.flag & kt_remove_main_flag_recurse_d)) { - flag |= kt_remove_flag_file_operate_remove_not_d; + flag_out |= kt_remove_flag_file_operate_remove_not_d; } } } else if (!main->setting.state.status) { if (!(main->setting.flag & kt_remove_main_flag_recurse_d)) { - flag |= kt_remove_flag_file_operate_remove_not_d; + flag_out |= kt_remove_flag_file_operate_remove_not_d; } } - - main->setting.state.status = F_okay; - - if (main->setting.flag & kt_remove_main_flag_tree_d) { - f_range_t range = macro_f_range_t_initialize_2(path.used); - // @todo do backwards searches on the path. - } - - // @todo call a similate fl_directory_do() or move this into the kt_remove_operate_file_directory() process. - } - - if (main->setting.process_operate_file_simulate) { - main->setting.state.status = F_okay; - - main->setting.process_operate_file_simulate(main, path, statistics, &flag); - if (F_status_is_error(main->setting.state.status)) return flag; - - if (main->setting.state.status == F_done) { - main->setting.state.status = F_okay; - - return flag; - } } if (main->setting.flag & kt_remove_main_flag_force_d) { kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_force_s, F_true); - flag |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_file_operate_remove_d; } - if (flag & kt_remove_flag_file_operate_directory_d) { - kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_recurse_s, main->setting.flag & kt_remove_main_flag_recurse_d); + if (flag_out & kt_remove_flag_file_operate_directory_d) { + kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_recurse_s, (main->setting.flag & kt_remove_main_flag_recurse_d) && !(flag_operate & kt_remove_flag_file_operate_parent_d)); } // @todo not boolean, set prompt of yes/no based on conditions, however, if kt_remove_main_flag_prompt_each_d is set, then its always prompt. if (main->setting.flag & kt_remove_main_flag_prompt_each_d) { - //kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_prompt_s, flag & kt_remove_main_flag_prompt_each_d); + //kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_prompt_s, main->setting.flag & kt_remove_main_flag_prompt_each_d); } // @todo determine if this path is part of a delete tree path. //kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_tree_s, main->setting.flag & kt_remove_main_flag_tree_d); - kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_remove_s, (flag & kt_remove_flag_file_operate_remove_d) && !(flag & kt_remove_flag_file_operate_remove_not_fail_d)); + kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_remove_s, (flag_out & kt_remove_flag_file_operate_remove_d) && !(flag_out & kt_remove_flag_file_operate_remove_not_fail_d)); - main->setting.state.status = F_okay; + if (main->setting.process_operate_file_simulate) { + main->setting.state.status = F_okay; - return flag; - } -#endif // _di_kt_remove_operate_file_simulate_ + main->setting.process_operate_file_simulate(main, path, statistics, flag_operate, &flag_out); + if (F_status_is_error(main->setting.state.status)) return flag_out; -#ifndef _di_kt_remove_operate_file_normal_ - void kt_remove_operate_file_normal(kt_remove_main_t * const main, const f_string_static_t path, const uint8_t flag) { - - if (!(flag & kt_remove_flag_file_operate_remove_d) || flag & kt_remove_flag_file_operate_remove_not_fail_d) { - main->setting.state.status = (flag & kt_remove_flag_file_operate_remove_fail_d) ? F_status_set_error(F_no) : F_no; + if (main->setting.state.status == F_done) { + main->setting.state.status = F_okay; - return; + return flag_out; + } } - // @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->cache.buffer.used = 0; + if (flag_out & kt_remove_flag_file_operate_directory_d) { + main->setting.state.status = F_okay; - main->setting.state.status = f_file_link_read(path, F_false, &main->cache.buffer); + // @todo The parent paths (really all paths) need to be added to a set of known paths to help ensure directories duplicate paths in the removal are handled properly. + if (main->setting.flag & kt_remove_main_flag_tree_d) { + f_range_t range = macro_f_range_t_initialize_2(path.used); - 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); + if (range.stop > range.start) { + main->setting.state.status = f_string_dynamic_seek_to_back(path, f_string_ascii_slash_forward_s.string[0], &range); - return; - } + if (F_status_is_error_not(main->setting.state.status) && F_status_set_fine(main->setting.state.status) == F_okay && range.stop > range.start) { - main->setting.state.status = f_file_remove(main->cache.buffer); + // This does not add the "+1" to the path_length because the trailing slash is not to be included. + const f_number_unsigned_t path_length = range.stop - range.start; + char path_parent_string[path_length + 1]; + const f_string_static_t path_parent = macro_f_string_static_t_initialize_2(path_parent_string, path_length); - 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->cache.buffer, f_file_operation_delete_s, fll_error_file_type_file_e); + memcpy(path_parent_string, path.string, path_length); + path_parent_string[path_length] = 0; - return; + f_print_dynamic(f_string_eol_s, main->program.output.to); + + kt_remove_operate_file_simulate(main, path_parent, kt_remove_flag_file_operate_parent_d); + } + } + + if (F_status_is_error(main->setting.state.status)) { + kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_string_dynamic_seek_to_back), path, f_file_operation_process_s, fll_error_file_type_path_e); + + return flag_out; + } } - } - else { - main->setting.state.status = f_file_remove(path); - 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_delete_s, fll_error_file_type_file_e); + if (!(flag_operate & kt_remove_flag_file_operate_parent_d)) { + const uint16_t flag_child = kt_remove_flag_file_operate_child_d; - return; + // @todo call this function on every child path, but this is not the kt_remove_operate_file_directory_recurse_action() call. } } - main->setting.state.status = F_yes; + main->setting.state.status = F_okay; + + return flag_out; } -#endif // _di_kt_remove_operate_file_normal_ +#endif // _di_kt_remove_operate_file_simulate_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/program/kevux/tools/remove/main/operate.h b/sources/c/program/kevux/tools/remove/main/operate.h index 7472293..b27d541 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.h +++ b/sources/c/program/kevux/tools/remove/main/operate.h @@ -68,17 +68,17 @@ extern "C" { * Errors (with error bit) from: f_file_remove(). * @param path * The path to the file to operate on. - * @param flag + * @param flag_operate * The operate file specific flags from kt_remove_flag_file_operate_*_e. * * @see f_file_remove() */ #ifndef _di_kt_remove_operate_file_directory_ - extern void kt_remove_operate_file_directory(kt_remove_main_t * const main, const f_string_static_t path, const uint8_t flag); + extern void kt_remove_operate_file_directory(kt_remove_main_t * const main, const f_string_static_t path, const uint16_t flag_operate); #endif // _di_kt_remove_operate_file_directory_ /** - * Perform directory recurse file operation action. + * Perform directory recurse for a single file operation action. * * @param recurse * The directory recurse data. @@ -90,7 +90,7 @@ extern "C" { * Does not have the parent directory path. * May be empty at the top level. * @param flag - * A flag representing the particular action being performed. + * A flag representing the particular directory action being performed. * * @see f_directory_remove() * @see fl_directory_do() @@ -100,7 +100,7 @@ extern "C" { #endif // _di_kt_remove_operate_file_directory_recurse_action_ /** - * Handle errors while performing directory recurse file operation action. + * Handle errors while performing directory recurse for a single file operation action. * * @param recurse * The directory recurse data. @@ -112,7 +112,7 @@ extern "C" { * Does not have the parent directory path. * May be empty at the top level. * @param flag - * A flag representing the particular action being performed. + * A flag representing the particular directory action being performed. * * @see fl_directory_do() */ @@ -138,14 +138,14 @@ extern "C" { * Errors (with error bit) from: f_file_remove(). * @param path * The path to the file to operate on. - * @param flag + * @param flag_operate * The operate file specific flags from kt_remove_flag_file_operate_*_e. * * @see f_file_link_read() * @see f_file_remove() */ #ifndef _di_kt_remove_operate_file_normal_ - extern void kt_remove_operate_file_normal(kt_remove_main_t * const main, const f_string_static_t path, const uint8_t flag); + extern void kt_remove_operate_file_normal(kt_remove_main_t * const main, const f_string_static_t path, const uint16_t flag_operate); #endif // _di_kt_remove_operate_file_normal_ /** @@ -167,6 +167,8 @@ extern "C" { * Errors (with error bit) from: f_file_remove(). * @param path * The path to the file to operate on. + * @param flag_operate + * The operate file specific flags from kt_remove_flag_file_operate_*_e. * * @return * The resulting flags determined by the simulation analysis. @@ -175,7 +177,7 @@ extern "C" { * @see f_file_remove() */ #ifndef _di_kt_remove_operate_file_simulate_ - extern uint8_t kt_remove_operate_file_simulate(kt_remove_main_t * const main, const f_string_static_t path); + extern uint16_t kt_remove_operate_file_simulate(kt_remove_main_t * const main, const f_string_static_t path, const uint16_t flag_operate); #endif // _di_kt_remove_operate_file_simulate_ #ifdef __cplusplus diff --git a/sources/c/program/kevux/tools/remove/main/print/error.c b/sources/c/program/kevux/tools/remove/main/print/error.c index 67d836e..d625de2 100644 --- a/sources/c/program/kevux/tools/remove/main/print/error.c +++ b/sources/c/program/kevux/tools/remove/main/print/error.c @@ -10,7 +10,9 @@ extern "C" { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - fll_error_print(print, F_status_set_fine(((kt_remove_main_t *) print->custom)->setting.state.status), function, F_true); + if (F_status_set_fine(((kt_remove_main_t *) print->custom)->setting.state.status) != F_interrupt) { + fll_error_print(print, F_status_set_fine(((kt_remove_main_t *) print->custom)->setting.state.status), function, F_true); + } return F_okay; } @@ -22,7 +24,9 @@ extern "C" { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - fll_error_file_print(print, F_status_set_fine(((kt_remove_main_t *) print->custom)->setting.state.status), function, F_true, name, operation, type); + if (F_status_set_fine(((kt_remove_main_t *) print->custom)->setting.state.status) != F_interrupt) { + fll_error_file_print(print, F_status_set_fine(((kt_remove_main_t *) print->custom)->setting.state.status), function, F_true, name, operation, type); + } return F_okay; } 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 19e6913..be7edf0 100644 --- a/sources/c/program/kevux/tools/remove/main/print/simulate.c +++ b/sources/c/program/kevux/tools/remove/main/print/simulate.c @@ -127,6 +127,7 @@ extern "C" { } f_number_unsigned_t i = 0; + uint8_t j = 0; if (main->setting.flag & kt_remove_main_flag_user_d) { for (; i < main->setting.users.used; ++i) { @@ -198,7 +199,7 @@ extern "C" { kt_remove_mode_word_not_s, }; - for (uint8_t j = 0; j < 4; ++j) { + for (j = 0; j < 4; ++j) { if (main->setting.modes.array[i].type == types[j]) { fll_print_format(" mode_matched %Q %@03un%r", main->program.output.to, strings[j], (f_number_unsigned_t) main->setting.modes.array[i].mode, f_string_eol_s); @@ -228,7 +229,6 @@ extern "C" { &kt_remove_long_updated_s, }; - uint8_t p = 0; f_status_t result = F_okay; f_string_static_t name_type = f_string_empty_s; f_number_unsigned_t match_year = 0; @@ -238,26 +238,26 @@ extern "C" { f_number_unsigned_t stop_year = 0; f_number_unsigned_t stop_second = 0; - for (; p < 3; ++p) { + for (j = 0; j < 3; ++j) { - for (i = 0; i < dates[p]->used; ++i) { + for (i = 0; i < dates[j]->used; ++i) { if (kt_remove_signal_check(main)) return; - match_year = kt_remove_time_year_unix_epoch_d + (times[p].tv_sec / kt_remove_time_seconds_in_year_d); - match_second = times[p].tv_sec % kt_remove_time_seconds_in_year_d; + match_year = kt_remove_time_year_unix_epoch_d + (times[j].tv_sec / kt_remove_time_seconds_in_year_d); + match_second = times[j].tv_sec % kt_remove_time_seconds_in_year_d; - start_year = dates[p]->array[i].start_year + (dates[p]->array[i].start_second / kt_remove_time_seconds_in_year_d); - start_second = dates[p]->array[i].start_second % kt_remove_time_seconds_in_year_d; + start_year = dates[j]->array[i].start_year + (dates[j]->array[i].start_second / kt_remove_time_seconds_in_year_d); + start_second = dates[j]->array[i].start_second % kt_remove_time_seconds_in_year_d; name_type = f_string_empty_s; result = F_okay; - if (dates[p]->array[i].type == kt_remove_flag_date_today_d || dates[p]->array[i].type == kt_remove_flag_date_tomorrow_d || dates[p]->array[i].type == kt_remove_flag_date_yesterday_d) { - stop_year = dates[p]->array[i].stop_year + (dates[p]->array[i].stop_second / kt_remove_time_seconds_in_year_d); - stop_second = dates[p]->array[i].stop_second % kt_remove_time_seconds_in_year_d; + if (dates[j]->array[i].type == kt_remove_flag_date_today_d || dates[j]->array[i].type == kt_remove_flag_date_tomorrow_d || dates[j]->array[i].type == kt_remove_flag_date_yesterday_d) { + stop_year = dates[j]->array[i].stop_year + (dates[j]->array[i].stop_second / kt_remove_time_seconds_in_year_d); + stop_second = dates[j]->array[i].stop_second % kt_remove_time_seconds_in_year_d; - if (dates[p]->array[i].operation == kt_remove_flag_date_equal_d) { + if (dates[j]->array[i].operation == kt_remove_flag_date_equal_d) { name_type = kt_remove_date_symbol_equal_s; result = F_false; @@ -265,12 +265,12 @@ extern "C" { if (match_second > start_second && match_second < stop_second) { result = F_true; } - else if (match_second == start_second && times[p].tv_nsec >= dates[p]->array[i].start_nanosecond && times[p].tv_nsec < dates[p]->array[i].stop_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec >= dates[j]->array[i].start_nanosecond && times[j].tv_nsec < dates[j]->array[i].stop_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_less_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_less_d) { name_type = kt_remove_date_symbol_less_s; result = F_false; @@ -281,12 +281,12 @@ extern "C" { if (match_second < start_second) { result = F_true; } - else if (match_second == start_second && times[p].tv_nsec < dates[p]->array[i].start_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec < dates[j]->array[i].start_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_less_equal_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_less_equal_d) { name_type = kt_remove_date_symbol_less_equal_s; result = F_false; @@ -297,12 +297,12 @@ extern "C" { if (match_second < stop_second) { result = F_true; } - else if (match_second == stop_second && times[p].tv_nsec < dates[p]->array[i].stop_nanosecond) { + else if (match_second == stop_second && times[j].tv_nsec < dates[j]->array[i].stop_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_more_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_more_d) { name_type = kt_remove_date_symbol_more_s; result = F_false; @@ -313,12 +313,12 @@ extern "C" { if (match_second > stop_second) { result = F_true; } - else if (match_second == stop_second && times[p].tv_nsec >= dates[p]->array[i].stop_nanosecond) { + else if (match_second == stop_second && times[j].tv_nsec >= dates[j]->array[i].stop_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_more_equal_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_more_equal_d) { name_type = kt_remove_date_symbol_more_equal_s; result = F_false; @@ -329,12 +329,12 @@ extern "C" { if (match_second > start_second) { result = F_true; } - else if (match_second == start_second && times[p].tv_nsec >= dates[p]->array[i].start_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec >= dates[j]->array[i].start_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_not_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_not_d) { name_type = kt_remove_date_symbol_not_s; result = F_true; @@ -342,23 +342,23 @@ extern "C" { if (match_second > start_second && match_second < stop_second) { result = F_false; } - else if (match_second == start_second && times[p].tv_nsec >= dates[p]->array[i].start_nanosecond && times[p].tv_nsec < dates[p]->array[i].stop_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec >= dates[j]->array[i].start_nanosecond && times[j].tv_nsec < dates[j]->array[i].stop_nanosecond) { result = F_false; } } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_equal_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_equal_d) { name_type = kt_remove_date_symbol_equal_s; - if (match_year == start_year && match_second == start_second && times[p].tv_nsec == dates[p]->array[i].start_nanosecond) { + if (match_year == start_year && match_second == start_second && times[j].tv_nsec == dates[j]->array[i].start_nanosecond) { result = F_true; } else { result = F_false; } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_less_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_less_d) { name_type = kt_remove_date_symbol_less_s; result = F_false; @@ -369,12 +369,12 @@ extern "C" { if (match_second < start_second) { result = F_true; } - else if (match_second == start_second && times[p].tv_nsec < dates[p]->array[i].start_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec < dates[j]->array[i].start_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_less_equal_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_less_equal_d) { name_type = kt_remove_date_symbol_less_equal_s; result = F_false; @@ -385,12 +385,12 @@ extern "C" { if (match_second < start_second) { result = F_true; } - else if (match_second == start_second && times[p].tv_nsec <= dates[p]->array[i].start_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec <= dates[j]->array[i].start_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_more_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_more_d) { name_type = kt_remove_date_symbol_more_s; result = F_false; @@ -401,12 +401,12 @@ extern "C" { if (match_second > start_second) { result = F_true; } - else if (match_second == start_second && times[p].tv_nsec > dates[p]->array[i].start_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec > dates[j]->array[i].start_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_more_equal_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_more_equal_d) { name_type = kt_remove_date_symbol_more_equal_s; result = F_false; @@ -417,15 +417,15 @@ extern "C" { if (match_second > start_second) { result = F_true; } - else if (match_second == start_second && times[p].tv_nsec >= dates[p]->array[i].start_nanosecond) { + else if (match_second == start_second && times[j].tv_nsec >= dates[j]->array[i].start_nanosecond) { result = F_true; } } } - else if (dates[p]->array[i].operation == kt_remove_flag_date_not_d) { + else if (dates[j]->array[i].operation == kt_remove_flag_date_not_d) { name_type = kt_remove_date_symbol_not_s; - if (match_year != start_year || match_second != start_second || times[p].tv_nsec != dates[p]->array[i].start_nanosecond) { + if (match_year != start_year || match_second != start_second || times[j].tv_nsec != dates[j]->array[i].start_nanosecond) { result = F_true; } else { @@ -434,9 +434,9 @@ extern "C" { } if (name_type.used) { - fll_print_format(" %Q %Q ", main->program.output.to, *names[p], result ? kt_remove_yes_s : kt_remove_no_s); - fll_print_format("%u::%un 0:%un %Q ", main->program.output.to, match_year, (f_number_unsigned_t) times[p].tv_sec, (f_number_unsigned_t) times[p].tv_nsec, name_type); - fll_print_format("%u::%un 0:%un%r", main->program.output.to, dates[p]->array[i].start_year, dates[p]->array[i].start_second, dates[p]->array[i].start_nanosecond, f_string_eol_s); + fll_print_format(" %Q %Q ", main->program.output.to, *names[j], result ? kt_remove_yes_s : kt_remove_no_s); + fll_print_format("%u::%un 0:%un %Q ", main->program.output.to, match_year, (f_number_unsigned_t) times[j].tv_sec, (f_number_unsigned_t) times[j].tv_nsec, name_type); + fll_print_format("%u::%un 0:%un%r", main->program.output.to, dates[j]->array[i].start_year, dates[j]->array[i].start_second, dates[j]->array[i].start_nanosecond, f_string_eol_s); break; } diff --git a/sources/c/program/kevux/tools/remove/main/remove.c b/sources/c/program/kevux/tools/remove/main/remove.c index d42b992..df0546c 100644 --- a/sources/c/program/kevux/tools/remove/main/remove.c +++ b/sources/c/program/kevux/tools/remove/main/remove.c @@ -24,6 +24,10 @@ extern "C" { fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s); } + if (main->program.signal_received) { + fll_program_print_signal_received(&main->program.warning, main->program.signal_received); + } + return; } @@ -32,8 +36,6 @@ extern "C" { } if (kt_remove_signal_check(main)) { - main->setting.state.status = F_status_set_error(F_interrupt); - fll_program_print_signal_received(&main->program.warning, main->program.signal_received); } } @@ -56,17 +58,7 @@ extern "C" { for (f_number_unsigned_t i = 0; i < main->setting.files.used; ++i) { - main->cache.file.used = 0; - - fl_path_clean(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_clean), 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); + kt_remove_operate_file(main, main->setting.files.array[i]); 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/signal.c b/sources/c/program/kevux/tools/remove/main/signal.c index aead2f6..65d1595 100644 --- a/sources/c/program/kevux/tools/remove/main/signal.c +++ b/sources/c/program/kevux/tools/remove/main/signal.c @@ -7,11 +7,15 @@ extern "C" { #if !defined(_di_kt_remove_signal_check_) && defined(_di_thread_support_) f_status_t kt_remove_signal_check(kt_remove_main_t * const main) { - if (!main || main->program.signal.id == -1) return F_false; + if (!main) return F_false; if (main->program.signal_received) return F_true; if (!((++main->program.signal_check) % kt_remove_signal_check_d)) { - if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interupt) return F_true; + if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) { + main->setting.state.status = F_status_set_error(F_interrupt); + + return F_true; + } main->program.signal_check = 0; } @@ -26,8 +30,6 @@ extern "C" { if (!main) return F_false; if (main->program.signal_received) { - fll_program_print_signal_received(&main->program.warning, main->program.signal_received); - main->setting.state.status = F_status_set_error(F_interrupt); return F_true; @@ -50,21 +52,9 @@ extern "C" { f_signal_set_add(F_signal_quit, &main->program.signal.set); f_signal_set_add(F_signal_termination, &main->program.signal.set); - if (main->program.signal.id == -1) { - main->program.signal_status = f_signal_open(&main->program.signal); - - if (F_status_is_error(main->program.signal_status)) { - main->program.signal_received = F_signal_abort; - - return; - } - } - fll_program_standard_signal_received_wait(&main->program, kt_remove_signal_check_failsafe_d); - f_signal_close(&main->program.signal); - - if (F_status_is_error(main->program.signal_status)) { + if (F_status_is_error(main->program.signal_status) && F_status_set_fine(main->program.signal_status) != F_interrupt) { main->program.signal_received = F_signal_abort; } } diff --git a/sources/c/program/kevux/tools/tacocat/main/signal.c b/sources/c/program/kevux/tools/tacocat/main/signal.c index 2d3c95b..2c61dff 100644 --- a/sources/c/program/kevux/tools/tacocat/main/signal.c +++ b/sources/c/program/kevux/tools/tacocat/main/signal.c @@ -11,7 +11,11 @@ extern "C" { if (main->program.signal_received) return F_true; if (!((++main->program.signal_check) % kt_tacocat_signal_check_d)) { - if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interupt) return F_true; + if (F_status_set_fine(fll_program_standard_signal_received(&main->program)) == F_interrupt) { + main->setting.state.status = F_status_set_error(F_interrupt); + + return F_true; + } main->program.signal_check = 0; } @@ -26,8 +30,6 @@ extern "C" { if (!main) return F_false; if (main->program.signal_received) { - fll_program_print_signal_received(&main->program.warning, main->program.signal_received); - main->setting.state.status = F_status_set_error(F_interrupt); return F_true; diff --git a/sources/c/program/kevux/tools/tacocat/main/tacocat.c b/sources/c/program/kevux/tools/tacocat/main/tacocat.c index 1a85aa9..d076726 100644 --- a/sources/c/program/kevux/tools/tacocat/main/tacocat.c +++ b/sources/c/program/kevux/tools/tacocat/main/tacocat.c @@ -24,6 +24,10 @@ extern "C" { fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s); } + if (main->program.signal_received) { + fll_program_print_signal_received(&main->program.warning, main->program.signal_received); + } + return; } @@ -49,10 +53,6 @@ extern "C" { kt_tacocat_process_main(main); if (main->program.signal_received) { - main->setting.state.status = F_status_set_error(F_interrupt); - } - - if (main->setting.state.status == F_status_set_error(F_interrupt)) { fll_program_print_signal_received(&main->program.warning, main->program.signal_received); } } -- 1.8.3.1