From: Kevin Day Date: Sat, 22 Mar 2025 16:41:33 +0000 (-0500) Subject: Progress: Continue working on completing the remove program. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b0881790e5bd2b59610df0578658e693f160a211;p=kevux-tools Progress: Continue working on completing the remove program. The existing program unit tests revealed that the date pre-processing is: 1. Happening even when none of the date flags (access, changed, and updated) are set. 2. Is incorrectly returning `F_yes` due to the initial `F_okay` assignment to `status`. Add `accessed_changed_updated` helper flag and use that flag to ensure the `kt_remove_preprocess_file_dates()` only gets called when needed. Initialize the `status` value to `F_false` in the `kt_remove_preprocess_file_dates()`. The newly added pint functions is resulting in an extra call to `geteuid()`. Add a second wrap call to address this. I may want to use a variable in the future to prevent multiple calls to this function. --- 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 711c35a..880ba41 100644 --- a/sources/c/program/kevux/tools/remove/main/common/define.h +++ b/sources/c/program/kevux/tools/remove/main/common/define.h @@ -207,86 +207,88 @@ extern "C" { * Flags passed to the main function or program. * * kt_remove_main_flag_*_d: - * - none: No flags set. - * - accessed: Remove by last accessed datetime. - * - block: Remove by file type: block. - * - character: Remove by file type: character. - * - copyright: Print copyright. - * - changed: Remove by changed datetime. - * - different: Remove by user different from caller. - * - directory: Remove by file type: directory. - * - empty_all: Helper flag representing all empty flag bits. - * - empty_only: Remove empty directories. - * - empty_only_fail: Fail on empty directories. - * - empty_not: Remove not empty directories. - * - empty_not_fail: Fail on not empty directories. - * - fifo: Remove by file type: FIFO. - * - follow: Follow symbolic links for deleting the file being pointed to rather than the link itself (when not set the link itself is deleted). - * - force: Forcibly delete. - * - group: Remove by GID. - * - help: Print help. - * - link: Remove by file type: link. - * - mode: Remove by mode. - * - option_used: Designates that type match options are in use, overriding the default behavior. - * - prompt_all: Helper flag representing all prompt flag bits. - * - prompt_each: Operate in interactive mode, prompting for every file. - * - prompt_follow: Operate in interactive mode: prompting for every link that is being followed. - * - prompt_never: Do not operate in interactive mode. - * - prompt_once: Operate in interactive mode: prompting if removing 3 or more files. - * - recurse: Recurse directories. - * - regular: Remove by file type: regular. - * - remember: Enable remembering paths already processed. - * - same: Remove by same user as caller. - * - simulate: Do not actually perform deletes, instead print messages (when silent, should still return 0 or 1). - * - socket: Remove by file type: socket. - * - tree: Remove directory tree (parent directories) (remove a/b/c, removes a/b/c, then a/b/, then a). - * - updated: Remove by last updated datetime. - * - user: Remove by UID. - * - unknown: Remove by file type: unknown. - * - utc: Process dates in UTC mode. - * - version: Print version. - * - version_copyright_help: A helper flag representing version, copyright, and help flag bits being set. + * - none: No flags set. + * - accessed: Remove by last accessed datetime. + * - accessed_changed_updated: A helper flag representing accessed, changed, and updated flag bits being set. + * - block: Remove by file type: block. + * - character: Remove by file type: character. + * - copyright: Print copyright. + * - changed: Remove by changed datetime. + * - different: Remove by user different from caller. + * - directory: Remove by file type: directory. + * - empty_all: Helper flag representing all empty flag bits. + * - empty_only: Remove empty directories. + * - empty_only_fail: Fail on empty directories. + * - empty_not: Remove not empty directories. + * - empty_not_fail: Fail on not empty directories. + * - fifo: Remove by file type: FIFO. + * - follow: Follow symbolic links for deleting the file being pointed to rather than the link itself (when not set the link itself is deleted). + * - force: Forcibly delete. + * - group: Remove by GID. + * - help: Print help. + * - link: Remove by file type: link. + * - mode: Remove by mode. + * - option_used: Designates that type match options are in use, overriding the default behavior. + * - prompt_all: Helper flag representing all prompt flag bits. + * - prompt_each: Operate in interactive mode, prompting for every file. + * - prompt_follow: Operate in interactive mode: prompting for every link that is being followed. + * - prompt_never: Do not operate in interactive mode. + * - prompt_once: Operate in interactive mode: prompting if removing 3 or more files. + * - recurse: Recurse directories. + * - regular: Remove by file type: regular. + * - remember: Enable remembering paths already processed. + * - same: Remove by same user as caller. + * - simulate: Do not actually perform deletes, instead print messages (when silent, should still return 0 or 1). + * - socket: Remove by file type: socket. + * - tree: Remove directory tree (parent directories) (remove a/b/c, removes a/b/c, then a/b/, then a). + * - updated: Remove by last updated datetime. + * - user: Remove by UID. + * - unknown: Remove by file type: unknown. + * - utc: Process dates in UTC mode. + * - version: Print version. + * - version_copyright_help: A helper flag representing version, copyright, and help flag bits being set. */ #ifndef _di_kt_remove_main_flag_d_ - #define kt_remove_main_flag_none_d 0x0 - #define kt_remove_main_flag_accessed_d 0x1 - #define kt_remove_main_flag_block_d 0x2 - #define kt_remove_main_flag_character_d 0x4 - #define kt_remove_main_flag_copyright_d 0x8 - #define kt_remove_main_flag_changed_d 0x10 - #define kt_remove_main_flag_different_d 0x20 - #define kt_remove_main_flag_directory_d 0x40 - #define kt_remove_main_flag_empty_all_d 0x780 - #define kt_remove_main_flag_empty_only_d 0x80 - #define kt_remove_main_flag_empty_only_fail_d 0x100 - #define kt_remove_main_flag_empty_not_d 0x200 - #define kt_remove_main_flag_empty_not_fail_d 0x400 - #define kt_remove_main_flag_fifo_d 0x800 - #define kt_remove_main_flag_follow_d 0x1000 - #define kt_remove_main_flag_force_d 0x2000 - #define kt_remove_main_flag_group_d 0x4000 - #define kt_remove_main_flag_help_d 0x8000 - #define kt_remove_main_flag_link_d 0x10000 - #define kt_remove_main_flag_mode_d 0x20000 - #define kt_remove_main_flag_option_used_d 0x40000 - #define kt_remove_main_flag_prompt_all_d 0x780000 - #define kt_remove_main_flag_prompt_each_d 0x80000 - #define kt_remove_main_flag_prompt_follow_d 0x100000 - #define kt_remove_main_flag_prompt_never_d 0x200000 - #define kt_remove_main_flag_prompt_once_d 0x400000 - #define kt_remove_main_flag_recurse_d 0x800000 - #define kt_remove_main_flag_regular_d 0x1000000 - #define kt_remove_main_flag_remember_d 0x2000000 - #define kt_remove_main_flag_same_d 0x4000000 - #define kt_remove_main_flag_simulate_d 0x8000000 - #define kt_remove_main_flag_socket_d 0x10000000 - #define kt_remove_main_flag_tree_d 0x20000000 - #define kt_remove_main_flag_updated_d 0x40000000 - #define kt_remove_main_flag_user_d 0x80000000 - #define kt_remove_main_flag_unknown_d 0x100000000 - #define kt_remove_main_flag_utc_d 0x200000000 - #define kt_remove_main_flag_version_d 0x400000000 - #define kt_remove_main_flag_version_copyright_help_d 0x400008008 + #define kt_remove_main_flag_none_d 0x0 + #define kt_remove_main_flag_accessed_d 0x1 + #define kt_remove_main_flag_accessed_changed_updated_d 0x40000011 + #define kt_remove_main_flag_block_d 0x2 + #define kt_remove_main_flag_character_d 0x4 + #define kt_remove_main_flag_copyright_d 0x8 + #define kt_remove_main_flag_changed_d 0x10 + #define kt_remove_main_flag_different_d 0x20 + #define kt_remove_main_flag_directory_d 0x40 + #define kt_remove_main_flag_empty_all_d 0x780 + #define kt_remove_main_flag_empty_only_d 0x80 + #define kt_remove_main_flag_empty_only_fail_d 0x100 + #define kt_remove_main_flag_empty_not_d 0x200 + #define kt_remove_main_flag_empty_not_fail_d 0x400 + #define kt_remove_main_flag_fifo_d 0x800 + #define kt_remove_main_flag_follow_d 0x1000 + #define kt_remove_main_flag_force_d 0x2000 + #define kt_remove_main_flag_group_d 0x4000 + #define kt_remove_main_flag_help_d 0x8000 + #define kt_remove_main_flag_link_d 0x10000 + #define kt_remove_main_flag_mode_d 0x20000 + #define kt_remove_main_flag_option_used_d 0x40000 + #define kt_remove_main_flag_prompt_all_d 0x780000 + #define kt_remove_main_flag_prompt_each_d 0x80000 + #define kt_remove_main_flag_prompt_follow_d 0x100000 + #define kt_remove_main_flag_prompt_never_d 0x200000 + #define kt_remove_main_flag_prompt_once_d 0x400000 + #define kt_remove_main_flag_recurse_d 0x800000 + #define kt_remove_main_flag_regular_d 0x1000000 + #define kt_remove_main_flag_remember_d 0x2000000 + #define kt_remove_main_flag_same_d 0x4000000 + #define kt_remove_main_flag_simulate_d 0x8000000 + #define kt_remove_main_flag_socket_d 0x10000000 + #define kt_remove_main_flag_tree_d 0x20000000 + #define kt_remove_main_flag_updated_d 0x40000000 + #define kt_remove_main_flag_user_d 0x80000000 + #define kt_remove_main_flag_unknown_d 0x100000000 + #define kt_remove_main_flag_utc_d 0x200000000 + #define kt_remove_main_flag_version_d 0x400000000 + #define kt_remove_main_flag_version_copyright_help_d 0x400008008 #endif // _di_kt_remove_main_flag_e_ /** diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.c b/sources/c/program/kevux/tools/remove/main/preprocess.c index 7d69756..eb6dc8b 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.c +++ b/sources/c/program/kevux/tools/remove/main/preprocess.c @@ -254,11 +254,13 @@ extern "C" { } } - kt_remove_preprocess_file_dates(main, path, flag_operate, statistics); - if (F_status_is_error(main->setting.state.status)) return flag_out; + if (main->setting.flag & kt_remove_main_flag_accessed_changed_updated_d) { + kt_remove_preprocess_file_dates(main, path, flag_operate, statistics); + if (F_status_is_error(main->setting.state.status)) return flag_out; - if (main->setting.state.status == F_yes) { - flag_out |= kt_remove_flag_file_operate_remove_d; + if (main->setting.state.status == F_yes) { + flag_out |= kt_remove_flag_file_operate_remove_d; + } } if (flag_out & kt_remove_flag_file_operate_directory_d) { @@ -463,7 +465,7 @@ extern "C" { &main->setting.updated, }; - f_time_spec_t times[] = { + const f_time_spec_t times[] = { statistics.st_atim, statistics.st_ctim, statistics.st_mtim, @@ -475,7 +477,7 @@ extern "C" { kt_remove_long_updated_s, }; - f_status_t result = F_okay; + f_status_t result = F_false; f_string_static_t name_type = f_string_empty_s; f_number_unsigned_t match_year = 0; f_number_unsigned_t match_second = 0; diff --git a/tests/unit/remove/c/test-remove-user.c b/tests/unit/remove/c/test-remove-user.c index 21b0864..6809448 100644 --- a/tests/unit/remove/c/test-remove-user.c +++ b/tests/unit/remove/c/test-remove-user.c @@ -34,6 +34,7 @@ void test__kt_remove__user__different_works(void **state) { for (uint8_t i = 0; i < total; ++i) { will_return(__wrap_geteuid, user_id); + will_return(__wrap_geteuid, user_id); // Pre-process file. will_return(__wrap_f_file_exists, F_true); @@ -155,6 +156,7 @@ void test__kt_remove__user__same_works(void **state) { for (uint8_t i = 0; i < total; ++i) { will_return(__wrap_geteuid, user_id); + will_return(__wrap_geteuid, user_id); // Pre-process file. will_return(__wrap_f_file_exists, F_true);