From: Kevin Day Date: Thu, 3 Apr 2025 03:28:22 +0000 (-0500) Subject: Progress: Continue working on completing the remove program. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=HEAD;p=kevux-tools Progress: Continue working on completing the remove program. Make sure to not set the `kt_remove_main_flag_option_type_d` for the "different" and "same" parameters. Make sure to not set the `kt_remove_main_flag_option_used_d` for the "empty" parameters. The `kt_remove_flag_file_operate_recurse_d` flag is being set on a directory, but it is always being set without regard to te recursive parameter. Remove it an and just check the recurse parameter instead. The empty not flag should be checked when checking empty states. Remove accidental assignment of `kt_remove_flag_file_operate_remove_d` when `is` is true for the `kt_remove_preprocess_file_type()`. Address the program unit tests. Add the empty parameters in places where the tests were originally expecting the remove command to remove non-empty directories by default. The directory tree tests were improperly returning false on the mocked empty for the parent directory after the child directory was mock deleted. I'm currently investigating problems where the following does not work as expect: ```shell clear ; md a/b/c ; touch a/b/file ; remove a/b/ -r +V ; t a ``` Cast the `flag_operate` when transfering to/from the `recurse.state.code`. --- diff --git a/sources/c/program/kevux/tools/remove/main/common.c b/sources/c/program/kevux/tools/remove/main/common.c index 30c09e5..8f15738 100644 --- a/sources/c/program/kevux/tools/remove/main/common.c +++ b/sources/c/program/kevux/tools/remove/main/common.c @@ -30,7 +30,7 @@ extern "C" { if (main->program.parameters.array[kt_remove_parameter_different_e].result & f_console_result_found_e) { main->setting.flag &= ~kt_remove_main_flag_same_d; - main->setting.flag |= kt_remove_main_flag_different_d | kt_remove_main_flag_option_type_d | kt_remove_main_flag_option_used_d; + main->setting.flag |= kt_remove_main_flag_different_d | kt_remove_main_flag_option_used_d; if (main->program.parameters.array[kt_remove_parameter_same_e].result & f_console_result_found_e) { index = main->program.parameters.array[kt_remove_parameter_different_e].locations.used; @@ -44,7 +44,7 @@ extern "C" { } else if (main->program.parameters.array[kt_remove_parameter_same_e].result & f_console_result_found_e) { main->setting.flag &= ~kt_remove_main_flag_different_d; - main->setting.flag |= kt_remove_main_flag_same_d | kt_remove_main_flag_option_type_d | kt_remove_main_flag_option_used_d; + main->setting.flag |= kt_remove_main_flag_same_d | kt_remove_main_flag_option_used_d; } if (main->program.parameters.array[kt_remove_parameter_fifo_e].result & f_console_result_found_e) { @@ -99,6 +99,10 @@ extern "C" { main->setting.flag |= kt_remove_main_flag_tree_d; } + if (main->program.parameters.array[kt_remove_parameter_unknown_e].result & f_console_result_found_e) { + main->setting.flag |= kt_remove_main_flag_unknown_d | kt_remove_main_flag_option_type_d | kt_remove_main_flag_option_used_d; + } + { f_console_parameter_t * const parameters[] = { &main->program.parameters.array[kt_remove_parameter_accessed_e], @@ -246,7 +250,6 @@ extern "C" { index = main->program.parameters.array[kt_remove_parameter_empty_e].values.array[total_arguments - 1]; main->setting.flag &= ~kt_remove_main_flag_empty_all_d; - main->setting.flag |= kt_remove_main_flag_option_used_d; if (f_compare_dynamic(kt_remove_not_s, main->program.parameters.arguments.array[index]) == F_equal_to) { main->setting.flag |= kt_remove_main_flag_empty_not_d; @@ -452,10 +455,6 @@ extern "C" { } } - if (main->program.parameters.array[kt_remove_parameter_unknown_e].result & f_console_result_found_e) { - main->setting.flag |= kt_remove_main_flag_unknown_d | kt_remove_main_flag_option_type_d | kt_remove_main_flag_option_used_d; - } - if (main->program.parameters.array[kt_remove_parameter_utc_e].result & f_console_result_found_e) { main->setting.flag |= kt_remove_main_flag_utc_d; 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 593b01f..c8958b8 100644 --- a/sources/c/program/kevux/tools/remove/main/common/define.h +++ b/sources/c/program/kevux/tools/remove/main/common/define.h @@ -160,7 +160,6 @@ extern "C" { * - missing: The file is not found. * - parent: This is a parent of a file for some other file tree operation process. * - processed: This path is already processed. - * - recurse: Perform recursively (only on directories). * - remove: Perform remove. * - remove_fail: Cannot perform remove due to failure. * - remove_not: Do not remove, but not a failure. @@ -177,11 +176,10 @@ extern "C" { #define kt_remove_flag_file_operate_missing_d 0x20 #define kt_remove_flag_file_operate_parent_d 0x40 #define kt_remove_flag_file_operate_processed_d 0x80 - #define kt_remove_flag_file_operate_recurse_d 0x100 - #define kt_remove_flag_file_operate_remove_d 0x200 - #define kt_remove_flag_file_operate_remove_fail_d 0x400 - #define kt_remove_flag_file_operate_remove_not_d 0x800 - #define kt_remove_flag_file_operate_remove_not_fail_d 0xc00 + #define kt_remove_flag_file_operate_remove_d 0x100 + #define kt_remove_flag_file_operate_remove_fail_d 0x200 + #define kt_remove_flag_file_operate_remove_not_d 0x400 + #define kt_remove_flag_file_operate_remove_not_fail_d 0x600 #endif // _di_kt_remove_flag_file_operate_d_ /** diff --git a/sources/c/program/kevux/tools/remove/main/operate.c b/sources/c/program/kevux/tools/remove/main/operate.c index 547c086..00e2c2c 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.c +++ b/sources/c/program/kevux/tools/remove/main/operate.c @@ -12,7 +12,7 @@ extern "C" { f_directory_recurse_do_t recurse = f_directory_recurse_do_t_initialize; // The recurse.state.code flags represent the top-level directory being recursed on. - recurse.state.code = flag_operate; + recurse.state.code = (uint64_t) flag_operate; recurse.state.custom = (void *) main; recurse.state.interrupt = &kt_remove_signal_check_recurse; @@ -379,16 +379,14 @@ extern "C" { main, path, flag & f_directory_recurse_do_flag_top_after_e - ? recurse->state.code + ? (uint32_t) recurse->state.code : flag & f_directory_recurse_do_flag_directory_e - ? (recurse->state.code | kt_remove_flag_file_operate_child_d | kt_remove_flag_file_operate_directory_d) & ~kt_remove_flag_file_operate_parent_d - : (recurse->state.code | kt_remove_flag_file_operate_child_d) & ~kt_remove_flag_file_operate_directory_parent_d + ? (((uint32_t) recurse->state.code) | kt_remove_flag_file_operate_child_d | kt_remove_flag_file_operate_directory_d) & ~kt_remove_flag_file_operate_parent_d + : (((uint32_t) recurse->state.code) | kt_remove_flag_file_operate_child_d) & ~kt_remove_flag_file_operate_directory_parent_d ); - if (recurse->state.status == F_done) { + if (F_status_is_error_not(recurse->state.status)) { recurse->state.status = F_okay; - - return; } } #endif // _di_kt_remove_operate_recurse_action_ @@ -454,7 +452,7 @@ extern "C" { } status = flag_operate & kt_remove_flag_file_operate_directory_d - ? f_directory_remove((flag_operate & kt_remove_flag_file_operate_follow_d) ? main->cache.buffer : path, (flag_operate & kt_remove_flag_file_operate_recurse_d) ? kt_remove_depth_max_d : 0, F_false) + ? f_directory_remove((flag_operate & kt_remove_flag_file_operate_follow_d) ? main->cache.buffer : path, (main->setting.state.status & kt_remove_main_flag_recurse_d) ? kt_remove_depth_max_d : 0, F_false) : f_file_remove((flag_operate & kt_remove_flag_file_operate_follow_d) ? main->cache.buffer : path); if (F_status_is_error(status)) { diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.c b/sources/c/program/kevux/tools/remove/main/preprocess.c index f749724..2b2f236 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.c +++ b/sources/c/program/kevux/tools/remove/main/preprocess.c @@ -90,6 +90,10 @@ extern "C" { kt_remove_preprocess_file_type(main, path, macro_f_file_type_is_directory(statistics.st_mode), f_file_type_name_directory_s, kt_remove_main_flag_directory_d, 0x1, &flag_out); + if (macro_f_file_type_is_directory(statistics.st_mode)) { + flag_out |= kt_remove_flag_file_operate_directory_d; + } + kt_remove_preprocess_file_type(main, path, macro_f_file_type_is_fifo(statistics.st_mode), f_file_type_name_fifo_s, kt_remove_main_flag_fifo_d, 0x1, &flag_out); kt_remove_preprocess_file_type(main, path, macro_f_file_type_is_link(statistics.st_mode), f_file_type_name_link_s, kt_remove_main_flag_link_d, 0x1, &flag_out); @@ -100,10 +104,6 @@ extern "C" { kt_remove_preprocess_file_type(main, path, macro_f_file_type_is_unknown(statistics.st_mode), f_file_type_name_unknown_s, kt_remove_main_flag_unknown_d, 0x0, &flag_out); - if (macro_f_file_type_is_directory(statistics.st_mode)) { - flag_out |= kt_remove_flag_file_operate_directory_d; - } - if (!(main->setting.flag & kt_remove_main_flag_simulate_d) && (flag_out & kt_remove_flag_file_operate_remove_fail_d)) return flag_out; if (main->setting.flag & kt_remove_main_flag_user_d) { @@ -211,8 +211,6 @@ extern "C" { } 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_out; @@ -240,7 +238,7 @@ extern "C" { 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)) { + else if (main->setting.flag & kt_remove_main_flag_empty_only_d || !(main->setting.flag & (kt_remove_main_flag_empty_not_d | kt_remove_main_flag_recurse_d))) { flag_out |= kt_remove_flag_file_operate_remove_not_d; } } @@ -630,13 +628,11 @@ extern "C" { #endif // _di_kt_remove_preprocess_file_dates_ #ifndef _di_kt_remove_preprocess_file_type_ - void kt_remove_preprocess_file_type(kt_remove_main_t * const main, const f_string_static_t path, const uint32_t is, f_string_static_t name, const uint64_t type, const uint8_t code, uint32_t * const flag_out) { + void kt_remove_preprocess_file_type(kt_remove_main_t * const main, const f_string_static_t path, const bool is, f_string_static_t name, const uint64_t type, const uint8_t code, uint32_t * const flag_out) { if (!main || !flag_out) return; if (is) { - *flag_out |= kt_remove_flag_file_operate_remove_d; - if (main->setting.flag & type) { *flag_out |= kt_remove_flag_file_operate_remove_d; } diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.h b/sources/c/program/kevux/tools/remove/main/preprocess.h index a7de410..4f48405 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.h +++ b/sources/c/program/kevux/tools/remove/main/preprocess.h @@ -131,7 +131,7 @@ extern "C" { * Must not be NULL. */ #ifndef _di_kt_remove_preprocess_file_type_ - extern void kt_remove_preprocess_file_type(kt_remove_main_t * const main, const f_string_static_t path, const uint32_t is, f_string_static_t name, const uint64_t type, const uint8_t code, uint32_t * const flag_out); + extern void kt_remove_preprocess_file_type(kt_remove_main_t * const main, const f_string_static_t path, const bool is, f_string_static_t name, const uint64_t type, const uint8_t code, uint32_t * const flag_out); #endif // _di_kt_remove_preprocess_file_type_ /** diff --git a/tests/unit/remove/c/test-remove-directory_no_args.c b/tests/unit/remove/c/test-remove-directory_no_args.c index 23cdef5..faa1de4 100644 --- a/tests/unit/remove/c/test-remove-directory_no_args.c +++ b/tests/unit/remove/c/test-remove-directory_no_args.c @@ -238,7 +238,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) struct stat statistics_regular; { - const f_string_t argv[] = { "mocked_main", file.string, 0 }; + const f_string_t argv[] = { "mocked_main", file.string, "-" KT_REMOVE_short_empty_s, KT_REMOVE_not_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_file_operate_remove_d. @@ -262,13 +262,13 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) // This will fail if f_directory_remove() is not called, therefore success here means f_directory_remove has been called. will_return(__wrap_f_directory_remove, F_okay); - const int result = kt_main_test__remove(2, argv, 0); + const int result = kt_main_test__remove(4, argv, 0); assert_int_equal(result, 0); } { - const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_verbose_s, 0 }; + const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_verbose_s, "-" KT_REMOVE_short_empty_s, KT_REMOVE_not_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_file_operate_remove_d. @@ -292,13 +292,13 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) // This will fail if f_directory_remove() is not called, therefore success here means f_directory_remove has been called. will_return(__wrap_f_directory_remove, F_okay); - const int result = kt_main_test__remove(3, argv, 0); + const int result = kt_main_test__remove(5, argv, 0); assert_int_equal(result, 0); } { - const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_debug_s, 0 }; + const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_debug_s, "-" KT_REMOVE_short_empty_s, KT_REMOVE_not_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_file_operate_remove_d. @@ -322,7 +322,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) // This will fail if f_directory_remove() is not called, therefore success here means f_directory_remove has been called. will_return(__wrap_f_directory_remove, F_okay); - const int result = kt_main_test__remove(3, argv, 0); + const int result = kt_main_test__remove(5, argv, 0); assert_int_equal(result, 0); } @@ -339,7 +339,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st struct stat statistics_regular; { - const f_string_t argv[] = { "mocked_main", file.string, 0 }; + const f_string_t argv[] = { "mocked_main", file.string, "-" KT_REMOVE_short_empty_s, KT_REMOVE_not_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_file_operate_remove_d. @@ -363,13 +363,13 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st // This will fail if f_directory_remove() is not called, therefore success here means f_directory_remove has been called. will_return(__wrap_f_directory_remove, F_okay); - const int result = kt_main_test__remove(2, argv, 0); + const int result = kt_main_test__remove(4, argv, 0); assert_int_equal(result, 0); } { - const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_verbose_s, 0 }; + const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_verbose_s, "-" KT_REMOVE_short_empty_s, KT_REMOVE_not_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_file_operate_remove_d. @@ -393,13 +393,13 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st // This will fail if f_directory_remove() is not called, therefore success here means f_directory_remove has been called. will_return(__wrap_f_directory_remove, F_okay); - const int result = kt_main_test__remove(3, argv, 0); + const int result = kt_main_test__remove(5, argv, 0); assert_int_equal(result, 0); } { - const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_debug_s, 0 }; + const f_string_t argv[] = { "mocked_main", file.string, "+" F_console_standard_short_debug_s, "-" KT_REMOVE_short_empty_s, KT_REMOVE_not_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_file_operate_remove_d. @@ -423,7 +423,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st // This will fail if f_directory_remove() is not called, therefore success here means f_directory_remove has been called. will_return(__wrap_f_directory_remove, F_okay); - const int result = kt_main_test__remove(3, argv, 0); + const int result = kt_main_test__remove(5, argv, 0); assert_int_equal(result, 0); } diff --git a/tests/unit/remove/c/test-remove-directory_tree_simple.c b/tests/unit/remove/c/test-remove-directory_tree_simple.c index 359d68c..13afcb2 100644 --- a/tests/unit/remove/c/test-remove-directory_tree_simple.c +++ b/tests/unit/remove/c/test-remove-directory_tree_simple.c @@ -40,7 +40,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li will_return(__wrap_f_file_is, F_false); // Not a link, kt_remove_flag_file_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); - will_return(__wrap_f_directory_empty, F_false); + will_return(__wrap_f_directory_empty, F_true); // Parent 1 processing. will_return(__wrap_f_directory_remove, F_okay); @@ -84,7 +84,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li will_return(__wrap_f_file_is, F_false); // Not a link, kt_remove_flag_file_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); - will_return(__wrap_f_directory_empty, F_false); + will_return(__wrap_f_directory_empty, F_true); // Parent 1 processing. will_return(__wrap_f_directory_remove, F_okay); @@ -128,7 +128,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li will_return(__wrap_f_file_is, F_false); // Not a link, kt_remove_flag_file_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); - will_return(__wrap_f_directory_empty, F_false); + will_return(__wrap_f_directory_empty, F_true); // Parent 1 processing. will_return(__wrap_f_directory_remove, F_okay); @@ -138,7 +138,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li will_return(__wrap_f_file_is, F_false); // Not a link, kt_remove_flag_file_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); - will_return(__wrap_f_directory_empty, F_false); + will_return(__wrap_f_directory_empty, F_true); // Parent 2 processing. will_return(__wrap_f_directory_remove, F_okay); @@ -182,7 +182,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li will_return(__wrap_f_file_is, F_false); // Not a link, kt_remove_flag_file_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); - will_return(__wrap_f_directory_empty, F_false); + will_return(__wrap_f_directory_empty, F_true); // Parent 1 processing. will_return(__wrap_f_directory_remove, F_okay); @@ -192,7 +192,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li will_return(__wrap_f_file_is, F_false); // Not a link, kt_remove_flag_file_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); - will_return(__wrap_f_directory_empty, F_false); + will_return(__wrap_f_directory_empty, F_true); // Parent 2 processing. will_return(__wrap_f_directory_remove, F_okay); diff --git a/tests/unit/remove/c/test-remove-file_type.c b/tests/unit/remove/c/test-remove-file_type.c index b15f6f7..90a9646 100644 --- a/tests/unit/remove/c/test-remove-file_type.c +++ b/tests/unit/remove/c/test-remove-file_type.c @@ -70,15 +70,10 @@ void test__kt_remove__file_type__works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(stats[i].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(3, argv, 0); - assert_int_equal(result, 0); + assert_int_equal(result, i == type ? 0 : 1); } // for } // for }