From: Kevin Day Date: Fri, 25 Apr 2025 04:23:55 +0000 (-0500) Subject: Progress: Continue working on completing the remove program. X-Git-Tag: 0.7.1~3 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=197ffd9719500e4a4cce44bd16c545ab7a8c48ca;p=kevux-tools Progress: Continue working on completing the remove program. Tweak the logic to ensure the simulate prints the simulate message only once for the top-most directory and then only for the second simulate pass (which is after the recursion into the directory children). Make so the `--remember yes` works as intended. Make the `--remember yes` the default for the `remove` program. Print the "skip yes" when simulating and remember state causes a skip. A unit test is failing due to a bug/regression in `kt_remove_operate_recurse_action()`. I belive this line is the concern: ``` if (!(flag & f_directory_recurse_do_flag_action_d) || !kt_remove_operate_shall_remove(recurse->state.code) && !((main->setting.flag & kt_remove_main_flag_simulate_d) && !recurse->depth)) return; ``` This is not yet addressed. --- 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 d902fde..a4b04b9 100644 --- a/sources/c/program/kevux/tools/remove/main/common/define.h +++ b/sources/c/program/kevux/tools/remove/main/common/define.h @@ -151,36 +151,40 @@ extern "C" { /** * Flags associated with performing an operation on a file. * - * kt_remove_flag_file_operate_*_d: - * - none: No flags set. - * - directory: Is a directory. - * - empty: Is an empty directory. - * - follow: Follow the symbolic link. - * - link: The file being operated on is a link or is a followed link. - * - 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. - * - remove: Perform remove. - * - remove_fail: Cannot perform remove due to failure. - * - remove_not: Do not remove, but not a failure. - * - remove_not_fail: Helper used to designate both remove_fail and remove_not being set. - * - simulate_not: Simulate printing is explicitly disabled for the specific file. + * kt_remove_flag_operate_*_d: + * - none: No flags set. + * - directory: Is a directory. + * - empty: Is an empty directory. + * - follow: Follow the symbolic link. + * - link: The file being operated on is a link or is a followed link. + * - 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. + * - remove: Perform remove. + * - remove_fail: Cannot perform remove due to failure. + * - remove_not: Do not remove, but not a failure. + * - remove_not_fail: Helper used to designate both remove_fail and remove_not being set. + * - simulate_not: Simulate printing is explicitly disabled for the specific file. + * - top: Designate that this is a top-level directory file. + * - top_similate_not: Helper used to designate both simulate_not and top being set. */ -#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_link_d 0x8 - #define kt_remove_flag_file_operate_missing_d 0x10 - #define kt_remove_flag_file_operate_parent_d 0x20 - #define kt_remove_flag_file_operate_processed_d 0x40 - #define kt_remove_flag_file_operate_remove_d 0x80 - #define kt_remove_flag_file_operate_remove_fail_d 0x100 - #define kt_remove_flag_file_operate_remove_not_d 0x200 - #define kt_remove_flag_file_operate_remove_not_fail_d 0x300 - #define kt_remove_flag_file_operate_simulate_not_d 0x400 -#endif // _di_kt_remove_flag_file_operate_d_ +#ifndef _di_kt_remove_flag_operate_d_ + #define kt_remove_flag_operate_none_d 0x0 + #define kt_remove_flag_operate_directory_d 0x1 + #define kt_remove_flag_operate_empty_d 0x2 + #define kt_remove_flag_operate_follow_d 0x4 + #define kt_remove_flag_operate_link_d 0x8 + #define kt_remove_flag_operate_missing_d 0x10 + #define kt_remove_flag_operate_parent_d 0x20 + #define kt_remove_flag_operate_processed_d 0x40 + #define kt_remove_flag_operate_remove_d 0x80 + #define kt_remove_flag_operate_remove_fail_d 0x100 + #define kt_remove_flag_operate_remove_not_d 0x200 + #define kt_remove_flag_operate_remove_not_fail_d 0x300 + #define kt_remove_flag_operate_simulate_not_d 0x400 + #define kt_remove_flag_operate_top_d 0x800 + #define kt_remove_flag_operate_top_simulate_not_d 0xc00 +#endif // _di_kt_remove_flag_operate_d_ /** * Flags associated with a mode. diff --git a/sources/c/program/kevux/tools/remove/main/common/string.c b/sources/c/program/kevux/tools/remove/main/common/string.c index 75a81cf..7e5b37b 100644 --- a/sources/c/program/kevux/tools/remove/main/common/string.c +++ b/sources/c/program/kevux/tools/remove/main/common/string.c @@ -36,6 +36,7 @@ extern "C" { const f_string_static_t kt_remove_remove_s = macro_f_string_static_t_initialize_1(KT_REMOVE_remove_s, 0, KT_REMOVE_remove_s_length); const f_string_static_t kt_remove_root_s = macro_f_string_static_t_initialize_1(KT_REMOVE_root_s, 0, KT_REMOVE_root_s_length); const f_string_static_t kt_remove_same_s = macro_f_string_static_t_initialize_1(KT_REMOVE_same_s, 0, KT_REMOVE_same_s_length); + const f_string_static_t kt_remove_skip_s = macro_f_string_static_t_initialize_1(KT_REMOVE_skip_s, 0, KT_REMOVE_skip_s_length); const f_string_static_t kt_remove_today_s = macro_f_string_static_t_initialize_1(KT_REMOVE_today_s, 0, KT_REMOVE_today_s_length); const f_string_static_t kt_remove_tomorrow_s = macro_f_string_static_t_initialize_1(KT_REMOVE_tomorrow_s, 0, KT_REMOVE_tomorrow_s_length); const f_string_static_t kt_remove_tree_s = macro_f_string_static_t_initialize_1(KT_REMOVE_tree_s, 0, KT_REMOVE_tree_s_length); diff --git a/sources/c/program/kevux/tools/remove/main/common/string.h b/sources/c/program/kevux/tools/remove/main/common/string.h index 3617c2a..bac7df0 100644 --- a/sources/c/program/kevux/tools/remove/main/common/string.h +++ b/sources/c/program/kevux/tools/remove/main/common/string.h @@ -92,6 +92,7 @@ extern "C" { #define KT_REMOVE_remove_s "remove" #define KT_REMOVE_root_s "root" #define KT_REMOVE_same_s "same" + #define KT_REMOVE_skip_s "skip" #define KT_REMOVE_today_s "today" #define KT_REMOVE_tomorrow_s "tomorrow" #define KT_REMOVE_tree_s "tree" @@ -122,6 +123,7 @@ extern "C" { #define KT_REMOVE_remove_s_length 6 #define KT_REMOVE_root_s_length 4 #define KT_REMOVE_same_s_length 4 + #define KT_REMOVE_skip_s_length 4 #define KT_REMOVE_today_s_length 5 #define KT_REMOVE_tomorrow_s_length 8 #define KT_REMOVE_tree_s_length 4 @@ -152,6 +154,7 @@ extern "C" { extern const f_string_static_t kt_remove_remove_s; extern const f_string_static_t kt_remove_root_s; extern const f_string_static_t kt_remove_same_s; + extern const f_string_static_t kt_remove_skip_s; extern const f_string_static_t kt_remove_today_s; extern const f_string_static_t kt_remove_tomorrow_s; extern const f_string_static_t kt_remove_tree_s; diff --git a/sources/c/program/kevux/tools/remove/main/operate.c b/sources/c/program/kevux/tools/remove/main/operate.c index 4485f4a..e3260ec 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.c +++ b/sources/c/program/kevux/tools/remove/main/operate.c @@ -7,8 +7,6 @@ extern "C" { #ifndef _di_kt_remove_operate_directory_ f_status_t kt_remove_operate_directory(kt_remove_main_t * const main, const f_string_static_t path, const uint32_t flag_operate) { - if (!kt_remove_operate_shall_remove(flag_operate)) return (flag_operate & kt_remove_flag_file_operate_remove_fail_d) && !(main->setting.flag & kt_remove_main_flag_simulate_d) ? F_status_set_error(F_no) : F_no; - // The recurse.state.code flags represent the top-level directory being recursed on. main->cache.recurse.state.code = (uint64_t) flag_operate; main->cache.recurse.state.custom = (void *) main; @@ -52,9 +50,17 @@ extern "C" { const uint32_t flag_operate = kt_remove_preprocess_file(main, path, 0, recurse); if (F_status_is_error(main->setting.state.status)) return main->setting.state.status; - if (flag_operate & kt_remove_flag_file_operate_processed_d) return F_no; + if (flag_operate & kt_remove_flag_operate_processed_d) return F_no; + + if (flag_operate & kt_remove_flag_operate_missing_d) { + main->setting.state.status = kt_remove_operate_memory_save(main, path, flag_operate); + + if (F_status_is_error(main->setting.state.status)) { + kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(kt_remove_operate_memory_save), path, f_file_operation_process_s, fll_error_file_type_path_e); + + return main->setting.state.status; + } - if (flag_operate & kt_remove_flag_file_operate_missing_d) { if (!(main->setting.flag & kt_remove_main_flag_force_simulate_d)) { main->setting.state.status = F_status_set_error(F_file_found_not); @@ -63,15 +69,13 @@ extern "C" { return main->setting.state.status; } } - else if (main->setting.state.status != F_skip) { + else { main->setting.state.status = kt_remove_operate_file_prompt(main, path, flag_operate); - if (F_status_is_error(main->setting.state.status)) return main->setting.state.status; + if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_skip) return main->setting.state.status; - return (flag_operate & kt_remove_flag_file_operate_directory_d) && !(recurse & kt_remove_flag_recurse_normal_d) + return (flag_operate & kt_remove_flag_operate_directory_d) && !(recurse & kt_remove_flag_recurse_normal_d) ? kt_remove_operate_directory(main, path, flag_operate) - : !(main->setting.flag & kt_remove_main_flag_simulate_d) - ? kt_remove_operate_remove(main, path, flag_operate) - : F_no; + : kt_remove_operate_remove(main, path, flag_operate); } return F_no; @@ -89,12 +93,10 @@ extern "C" { return; } - const uint32_t flag_operate = kt_remove_preprocess_file(main, path, kt_remove_flag_file_operate_parent_d, kt_remove_flag_recurse_none_d); - - if (F_status_is_error(main->setting.state.status)) return; - if (flag_operate & kt_remove_flag_file_operate_processed_d) return; + const uint32_t flag_operate = kt_remove_preprocess_file(main, path, kt_remove_flag_operate_parent_d, kt_remove_flag_recurse_none_d); + if (F_status_is_error(main->setting.state.status) || (flag_operate & kt_remove_flag_operate_processed_d)) return; - if (flag_operate & kt_remove_flag_file_operate_missing_d) { + if (flag_operate & kt_remove_flag_operate_missing_d) { if (!(main->setting.flag & kt_remove_main_flag_force_simulate_d)) { main->setting.state.status = F_status_set_error(F_file_found_not); @@ -103,11 +105,11 @@ extern "C" { return; } } - else if (main->setting.state.status != F_skip) { + else { main->setting.state.status = kt_remove_operate_file_prompt(main, path, flag_operate); if (F_status_is_error(main->setting.state.status)) return; - if (!(main->setting.flag & kt_remove_main_flag_simulate_d)) { + if (main->setting.state.status != F_skip && !(main->setting.flag & kt_remove_main_flag_simulate_d)) { kt_remove_operate_remove(main, path, flag_operate); } } @@ -131,7 +133,7 @@ extern "C" { main->setting.prompt = 1; } else if (main->setting.flag & kt_remove_main_flag_prompt_follow_d) { - if (!(flag_operate & kt_remove_flag_file_operate_link_d)) return F_okay; + if (!(flag_operate & kt_remove_flag_operate_link_d)) return F_okay; } if (main->setting.flag & kt_remove_main_flag_simulate_d) return F_okay; @@ -219,7 +221,7 @@ extern "C" { return; } - *flag_operate &= ~kt_remove_flag_file_operate_processed_d; + *flag_operate &= ~kt_remove_flag_operate_processed_d; main->setting.state.status = F_okay; @@ -240,7 +242,7 @@ extern "C" { if (main->cache.memory.array[i].string[range.stop] == f_path_separator_s.string[0]) { if (f_compare_dynamic_partial_dynamic(main->cache.memory.array[i], path, range) == F_equal_to) { - *flag_operate |= kt_remove_flag_file_operate_processed_d; + *flag_operate |= kt_remove_flag_operate_processed_d; break; } @@ -251,14 +253,14 @@ extern "C" { } if (f_compare_dynamic_partial_dynamic(main->cache.memory.array[i], path, range) == F_equal_to) { - *flag_operate |= kt_remove_flag_file_operate_processed_d; + *flag_operate |= kt_remove_flag_operate_processed_d; break; } } else { if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) { - *flag_operate |= kt_remove_flag_file_operate_processed_d; + *flag_operate |= kt_remove_flag_operate_processed_d; break; } @@ -273,7 +275,7 @@ extern "C" { if (macro_kt_remove_signal_check(&main->program, &main->setting.state)) return; if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) { - *flag_operate |= kt_remove_flag_file_operate_processed_d; + *flag_operate |= kt_remove_flag_operate_processed_d; break; } @@ -292,7 +294,7 @@ extern "C" { f_status_t status = f_memory_array_increase(main->setting.state.step_small, sizeof(f_string_dynamic_t), (void **) &main->cache.memory.array, &main->cache.memory.used, &main->cache.memory.size); // Find any child paths that would be included by this and remove them from the paths list. - if (F_status_is_error_not(status) && (flag_operate & kt_remove_flag_file_operate_directory_d)) { + if (F_status_is_error_not(status) && (flag_operate & kt_remove_flag_operate_directory_d)) { const f_range_t range = macro_f_range_t_initialize_2(path.used); f_number_unsigned_t i = 0; @@ -336,11 +338,18 @@ extern "C" { void kt_remove_operate_recurse_action(f_directory_recurse_do_t * const recurse, const f_string_static_t name, const uint32_t flag) { if (!recurse || !recurse->state.custom || F_status_set_fine(recurse->state.status) == F_interrupt) return; - if (!kt_remove_operate_shall_remove(recurse->state.code) || !(flag & f_directory_recurse_do_flag_action_d)) return; kt_remove_main_t * const main = (kt_remove_main_t *) recurse->state.custom; - recurse->state.status = kt_remove_operate_file(main, recurse->path, recurse->depth ? kt_remove_flag_recurse_normal_d : kt_remove_flag_recurse_normal_parent_d); + if (!(flag & f_directory_recurse_do_flag_action_d) || !kt_remove_operate_shall_remove(recurse->state.code) && !((main->setting.flag & kt_remove_main_flag_simulate_d) && !recurse->depth)) return; + + recurse->state.status = kt_remove_operate_file( + main, + recurse->path, + recurse->depth + ? kt_remove_flag_recurse_normal_d + : kt_remove_flag_recurse_normal_parent_d + ); if (F_status_is_error_not(recurse->state.status)) { recurse->state.status = F_okay; @@ -385,13 +394,17 @@ extern "C" { f_status_t kt_remove_operate_remove(kt_remove_main_t * const main, const f_string_static_t path, const uint32_t flag_operate) { if (!main) return F_status_set_error(F_parameter); - if (!kt_remove_operate_shall_remove(flag_operate)) return (flag_operate & kt_remove_flag_file_operate_remove_fail_d) ? F_status_set_error(F_no) : F_no; + if (flag_operate & kt_remove_flag_operate_processed_d) return F_no; - kt_remove_print_debug_operate_file_remove(&main->program.output, path, flag_operate); + const uint8_t remove = kt_remove_operate_shall_remove(flag_operate) ? F_true : F_false; f_status_t status = F_no; - if (flag_operate & kt_remove_flag_file_operate_follow_d) { + if (remove && !(main->setting.flag & kt_remove_main_flag_simulate_d)) { + kt_remove_print_debug_operate_file_remove(&main->program.output, path, flag_operate); + } + + if (flag_operate & kt_remove_flag_operate_follow_d) { main->cache.buffer.used = 0; status = f_file_link_read(path, F_false, &main->cache.buffer); @@ -401,49 +414,61 @@ extern "C" { return status; } + + status = F_no; } - const f_string_static_t target = (flag_operate & kt_remove_flag_file_operate_follow_d) ? main->cache.buffer : path; + const f_string_static_t target = (flag_operate & kt_remove_flag_operate_follow_d) ? main->cache.buffer : path; - status = flag_operate & kt_remove_flag_file_operate_directory_d - ? f_directory_remove(target, 0, F_false) - : f_file_remove(target); + if (remove && !(main->setting.flag & kt_remove_main_flag_simulate_d)) { + status = flag_operate & kt_remove_flag_operate_directory_d + ? f_directory_remove(target, 0, F_false) + : f_file_remove(target); - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_directory_empty_not && (flag_operate & kt_remove_flag_file_operate_remove_not_d)) { - status = F_no; + if (F_status_is_error(status)) { + if (F_status_set_fine(status) == F_directory_empty_not && (flag_operate & kt_remove_flag_operate_remove_not_d)) { + status = F_no; + } + else { + kt_remove_print_error_file_status( + &main->program.error, + flag_operate & kt_remove_flag_operate_directory_d + ? macro_kt_remove_f(f_directory_remove) + : macro_kt_remove_f(f_file_remove), + flag_operate & kt_remove_flag_operate_follow_d + ? main->cache.buffer + : path, + f_file_operation_delete_s, + flag_operate & kt_remove_flag_operate_directory_d + ? fll_error_file_type_directory_e + : fll_error_file_type_file_e, + status + ); + } } else { - kt_remove_print_error_file_status( - &main->program.error, - flag_operate & kt_remove_flag_file_operate_directory_d - ? macro_kt_remove_f(f_directory_remove) - : macro_kt_remove_f(f_file_remove), - flag_operate & kt_remove_flag_file_operate_follow_d - ? main->cache.buffer - : path, - f_file_operation_delete_s, - flag_operate & kt_remove_flag_file_operate_directory_d - ? fll_error_file_type_directory_e - : fll_error_file_type_file_e, - status - ); + status = F_yes; } } - else { - status = F_yes; - } - if (status == F_yes) { - kt_remove_print_verbose_operate_file_remove(&main->program.output, target, flag_operate); + if (status == F_yes || (main->setting.flag & kt_remove_main_flag_simulate_d) || !remove) { + if (status == F_yes) { + kt_remove_print_verbose_operate_file_remove(&main->program.output, target, flag_operate); + } status = kt_remove_operate_memory_save(main, target, flag_operate); if (F_status_is_error(status)) { - kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(kt_remove_operate_memory_save), path, f_file_operation_process_s, fll_error_file_type_path_e); + kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(kt_remove_operate_memory_save), target, f_file_operation_process_s, fll_error_file_type_path_e); } else { - status = F_yes; + status = remove + ? main->setting.flag & kt_remove_main_flag_simulate_d + ? F_no + : F_yes + : flag_operate & kt_remove_flag_operate_remove_fail_d + ? F_status_set_error(F_no) + : F_no; } } @@ -454,7 +479,7 @@ extern "C" { #ifndef _di_kt_remove_operate_shall_remove_ f_status_t kt_remove_operate_shall_remove(const uint32_t flag) { - return (flag & kt_remove_flag_file_operate_remove_d) && !(flag & kt_remove_flag_file_operate_remove_not_fail_d); + return (flag & kt_remove_flag_operate_remove_d) && !(flag & kt_remove_flag_operate_remove_not_fail_d); } #endif // _di_kt_remove_operate_shall_remove_ diff --git a/sources/c/program/kevux/tools/remove/main/operate.h b/sources/c/program/kevux/tools/remove/main/operate.h index 06bc16c..84b0e89 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.h +++ b/sources/c/program/kevux/tools/remove/main/operate.h @@ -24,7 +24,7 @@ extern "C" { * @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. + * The operate file specific flags from kt_remove_flag_operate_*_e. * * @return * F_yes on success and file remove. @@ -66,9 +66,10 @@ extern "C" { * Set to kt_remove_flag_recurse_none_d when this function is being called outside of directory recursion. * * @return - * F_yes on success and removed. - * F_no on success and not removed. * F_data_not on success but path is an empty string. + * F_no on success and not removed. + * F_skip on success and the file is not removed because it is being skipped. + * F_yes on success and removed. * * F_file_found_not (with error bit) on file not found. * F_interrupt (with error bit) on interrupt. @@ -135,7 +136,7 @@ extern "C" { * @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. + * The operate file specific flags from kt_remove_flag_operate_*_e. * * @return * F_okay on success or if prompting is not requested. @@ -170,9 +171,9 @@ extern "C" { * @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. + * The operate file specific flags from kt_remove_flag_operate_*_e. * - * The kt_remove_flag_file_operate_processed_d is set if the path is found in the memory cache. + * The kt_remove_flag_operate_processed_d is set if the path is found in the memory cache. * * Must not be NULL. * @@ -196,7 +197,7 @@ extern "C" { * @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. + * The operate file specific flags from kt_remove_flag_operate_*_e. * * @return * F_okay on success. @@ -270,7 +271,7 @@ extern "C" { * @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. + * The operate file specific flags from kt_remove_flag_operate_*_e. * * @return * F_no on success but file is not to be removed. @@ -281,6 +282,8 @@ extern "C" { * Errors (with error bit) from: f_file_link_read(). * Errors (with error bit) from: f_file_remove(). * + * Errors (with error bit) from: kt_remove_operate_memory_save(). + * * @see f_file_link_read() * @see f_file_remove() */ diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.c b/sources/c/program/kevux/tools/remove/main/preprocess.c index 3f4337e..c091068 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.c +++ b/sources/c/program/kevux/tools/remove/main/preprocess.c @@ -17,10 +17,17 @@ extern "C" { if (macro_kt_remove_signal_check(&main->program, &main->setting.state)) return 0; - uint32_t flag_out = (main->setting.flag & kt_remove_main_flag_option_type_used_d) ? 0 : kt_remove_flag_file_operate_remove_d; + uint32_t flag_out = (main->setting.flag & kt_remove_main_flag_option_type_used_d) ? 0 : kt_remove_flag_operate_remove_d; kt_remove_operate_memory_check(main, path, &flag_out); - if (F_status_is_error(main->setting.state.status) || (flag_out & kt_remove_flag_file_operate_processed_d)) return flag_out; + + if (F_status_is_error(main->setting.state.status) || (flag_out & kt_remove_flag_operate_processed_d)) { + kt_remove_print_simulate_operate_file(&main->program.output, flag_out, path); + + kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_skip_s, F_true); + + return flag_out; + } f_number_unsigned_t i = 0; @@ -43,7 +50,7 @@ extern "C" { } if (main->setting.state.status == F_true) { - flag_out |= kt_remove_flag_file_operate_link_d; + flag_out |= kt_remove_flag_operate_link_d; } } else if (exists == F_false || F_status_is_error(exists)) { @@ -54,7 +61,7 @@ extern "C" { if (exists == F_false) { kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_ignore_s, main->setting.flag & kt_remove_main_flag_force_d); - return kt_remove_flag_file_operate_missing_d; + return kt_remove_flag_operate_missing_d; } remove_print_warning_file_reason(&main->program.warning, path, kt_remove_print_reason_no_access_s); @@ -65,7 +72,7 @@ extern "C" { if (macro_kt_remove_signal_check(&main->program, &main->setting.state)) return 0; if (main->setting.flag & kt_remove_main_flag_follow_d) { - flag_out |= kt_remove_flag_file_operate_follow_d; + flag_out |= kt_remove_flag_operate_follow_d; } main->setting.state.status = f_file_stat(path, main->setting.flag & kt_remove_main_flag_follow_d, &statistics); @@ -81,11 +88,11 @@ extern "C" { } if (macro_f_file_type_is_directory(statistics.st_mode)) { - flag_out |= kt_remove_flag_file_operate_directory_d; + flag_out |= kt_remove_flag_operate_directory_d; } - if ((flag_out & kt_remove_flag_file_operate_directory_d) && (main->setting.flag & kt_remove_main_flag_recurse_d) && (recurse & kt_remove_flag_recurse_top_d)) { - flag_out |= kt_remove_flag_file_operate_simulate_not_d; + if ((recurse & kt_remove_flag_recurse_top_d) && (flag_out & kt_remove_flag_operate_directory_d)) { + flag_out |= kt_remove_flag_operate_top_simulate_not_d; } kt_remove_print_simulate_operate_file(&main->program.output, flag_out, path); @@ -97,7 +104,7 @@ extern "C" { if (f_compare_dynamic(f_string_ascii_slash_forward_s, path) == F_equal_to) { kt_remove_print_error_file_is_a(&main->program.error, path, kt_remove_not_allowed_s, 0); - flag_out |= kt_remove_flag_file_operate_remove_not_d; + flag_out |= kt_remove_flag_operate_remove_not_d; } } @@ -117,7 +124,7 @@ extern "C" { kt_remove_preprocess_file_type(main, kt_remove_flag_simulate_none_d, path, macro_f_file_type_is_unknown(statistics.st_mode), f_file_type_name_unknown_s, kt_remove_main_flag_unknown_d, kt_remove_main_flag_unknown_ignore_d, &flag_out); - 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_simulate_d) && (flag_out & kt_remove_flag_operate_remove_fail_d)) return flag_out; if (main->setting.flag & kt_remove_main_flag_user_d) { for (i = 0; i < main->setting.users.used; ++i) { @@ -129,7 +136,7 @@ extern "C" { kt_remove_print_simulate_operate_id(&main->program.output, flag_out, (f_number_unsigned_t) statistics.st_uid, F_true); if (i < main->setting.users.used) { - flag_out |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_operate_remove_d; } } @@ -137,7 +144,7 @@ extern "C" { kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_same_s, statistics.st_uid == geteuid()); if (statistics.st_uid == geteuid()) { - flag_out |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_operate_remove_d; } } @@ -145,7 +152,7 @@ extern "C" { kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_different_s, statistics.st_uid != geteuid()); if (statistics.st_uid != geteuid()) { - flag_out |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_operate_remove_d; } } @@ -159,7 +166,7 @@ extern "C" { kt_remove_print_simulate_operate_id(&main->program.output, flag_out, (f_number_unsigned_t) statistics.st_gid, F_false); if (i < main->setting.groups.used) { - flag_out |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_operate_remove_d; } } @@ -210,7 +217,7 @@ extern "C" { } } // for - flag_out |= kt_remove_flag_file_operate_remove_d; + flag_out |= kt_remove_flag_operate_remove_d; } } @@ -219,41 +226,41 @@ extern "C" { 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; + flag_out |= kt_remove_flag_operate_remove_d; } } - if (flag_out & kt_remove_flag_file_operate_directory_d) { + if (flag_out & kt_remove_flag_operate_directory_d) { main->setting.state.status = f_directory_empty(path); if (F_status_is_error(main->setting.state.status)) return flag_out; if (main->setting.state.status == F_true || main->setting.state.status == F_false) { - kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_empty_s, main->setting.state.status); - if (main->setting.state.status == F_true) { - flag_out |= kt_remove_flag_file_operate_empty_d; + flag_out |= kt_remove_flag_operate_empty_d; } - if (!(flag_out & kt_remove_flag_file_operate_remove_not_d)) { + kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_empty_s, main->setting.state.status); + + if (!(flag_out & kt_remove_flag_operate_remove_not_d)) { if (main->setting.flag & kt_remove_main_flag_empty_all_d) { if (main->setting.state.status == F_true) { if (main->setting.flag & kt_remove_main_flag_empty_not_fail_d) { kt_remove_print_error_file_is_a(&main->program.error, path, kt_remove_empty_s, 0); - flag_out |= kt_remove_flag_file_operate_remove_fail_d; + flag_out |= kt_remove_flag_operate_remove_fail_d; } else if (main->setting.flag & kt_remove_main_flag_empty_not_d) { - flag_out |= kt_remove_flag_file_operate_remove_not_d; + flag_out |= kt_remove_flag_operate_remove_not_d; } } else if (main->setting.state.status == F_false) { if (main->setting.flag & kt_remove_main_flag_empty_only_fail_d) { kt_remove_print_error_file_is_a(&main->program.error, path, kt_remove_not_empty_s, 0); - flag_out |= kt_remove_flag_file_operate_remove_fail_d; + flag_out |= kt_remove_flag_operate_remove_fail_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; + flag_out |= kt_remove_flag_operate_remove_not_d; } } } @@ -261,19 +268,19 @@ extern "C" { if (!(main->setting.flag & kt_remove_main_flag_recurse_d)) { kt_remove_print_error_file_is_a(&main->program.error, path, kt_remove_not_empty_s, 0); - flag_out |= kt_remove_flag_file_operate_remove_fail_d; + flag_out |= kt_remove_flag_operate_remove_fail_d; } } } } } - if (flag_out & kt_remove_flag_file_operate_directory_d) { - kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_recurse_s, (main->setting.flag & kt_remove_main_flag_recurse_d) && !(flag_operate & kt_remove_flag_file_operate_parent_d)); + if (flag_out & kt_remove_flag_operate_directory_d) { + kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_recurse_s, (main->setting.flag & kt_remove_main_flag_recurse_d) && !(flag_operate & kt_remove_flag_operate_parent_d)); } if (main->setting.flag & kt_remove_main_flag_tree_d) { - kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_parent_s, flag_operate & kt_remove_flag_file_operate_parent_d); + kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_parent_s, flag_operate & kt_remove_flag_operate_parent_d); } if (main->setting.flag & kt_remove_main_flag_prompt_all_d) { @@ -281,7 +288,7 @@ extern "C" { kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_prompt_s, main->setting.flag & kt_remove_main_flag_prompt_each_d); } else if (main->setting.flag & kt_remove_main_flag_prompt_follow_d) { - kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_prompt_s, (main->setting.flag & kt_remove_main_flag_follow_d) && (flag_out & kt_remove_flag_file_operate_link_d)); + kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_prompt_s, (main->setting.flag & kt_remove_main_flag_follow_d) && (flag_out & kt_remove_flag_operate_link_d)); } else if (main->setting.flag & kt_remove_main_flag_prompt_once_d) { kt_remove_print_simulate_operate_boolean(&main->program.output, flag_out, kt_remove_prompt_s, !(main->setting.prompt)); @@ -607,12 +614,12 @@ extern "C" { if (is) { if (main->setting.flag & type) { - *flag_out |= kt_remove_flag_file_operate_remove_d; + *flag_out |= kt_remove_flag_operate_remove_d; } else if (main->setting.flag & kt_remove_main_flag_option_type_d) { kt_remove_print_error_file_is_a(&main->program.error, path, name, simulate & kt_remove_flag_simulate_is_a_file_d); - *flag_out |= kt_remove_flag_file_operate_remove_fail_d; + *flag_out |= kt_remove_flag_operate_remove_fail_d; } } diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.h b/sources/c/program/kevux/tools/remove/main/preprocess.h index 886da8c..2d254a7 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.h +++ b/sources/c/program/kevux/tools/remove/main/preprocess.h @@ -32,7 +32,7 @@ extern "C" { * @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. + * The operate file specific flags from kt_remove_flag_operate_*_e. * @param recurse * One of the kt_remove_flag_recurse_*_d flags. * Set to kt_remove_flag_recurse_none_d when this function is being called outside of directory recursion. @@ -65,7 +65,7 @@ extern "C" { * @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. + * The operate file specific flags from kt_remove_flag_operate_*_e. * @param statistics * The already loaded file statistics. */ 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 dacc16c..f233fe6 100644 --- a/sources/c/program/kevux/tools/remove/main/print/simulate.c +++ b/sources/c/program/kevux/tools/remove/main/print/simulate.c @@ -34,7 +34,7 @@ extern "C" { kt_remove_main_t * const main = (kt_remove_main_t *) print->custom; - if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_file_operate_simulate_not_d)) return F_output_not; + if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_operate_simulate_not_d)) return F_output_not; fll_print_format(" %r %r%r", print->to, name, yes ? kt_remove_yes_s : kt_remove_no_s, f_string_eol_s); @@ -49,7 +49,7 @@ extern "C" { kt_remove_main_t * const main = (kt_remove_main_t *) print->custom; - if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_file_operate_simulate_not_d)) return F_output_not; + if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_operate_simulate_not_d)) return F_output_not; const f_number_unsigned_t match_year = kt_remove_time_year_unix_epoch_d + (time.tv_sec / kt_remove_time_seconds_in_year_d); const f_number_unsigned_t match_second = time.tv_sec % kt_remove_time_seconds_in_year_d; @@ -76,7 +76,7 @@ extern "C" { kt_remove_main_t * const main = (kt_remove_main_t *) print->custom; - if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_file_operate_simulate_not_d)) return F_output_not; + if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_operate_simulate_not_d)) return F_output_not; fll_print_format("%r%[Remove '%Q'%]:%r", print->to, f_string_eol_s, print->set->notable, path, print->set->notable, f_string_eol_s); @@ -91,7 +91,7 @@ extern "C" { kt_remove_main_t * const main = (kt_remove_main_t *) print->custom; - if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_file_operate_simulate_not_d)) return F_output_not; + if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_operate_simulate_not_d)) return F_output_not; if (F_status_is_error(exists)) { fl_print_format(" file_access_failure %ui%r", print->to, F_status_set_fine(exists), f_string_eol_s); @@ -99,7 +99,7 @@ extern "C" { return F_status_set_error(F_output_not); } - if (flag_operate & kt_remove_flag_file_operate_link_d) { + if (flag_operate & kt_remove_flag_operate_link_d) { main->cache.buffer.used = 0; const f_status_t status = f_file_link_read(path, F_false, &main->cache.buffer); @@ -131,7 +131,7 @@ extern "C" { kt_remove_main_t * const main = (kt_remove_main_t *) print->custom; - if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_file_operate_simulate_not_d)) return F_output_not; + if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_operate_simulate_not_d)) return F_output_not; fll_print_format(" %r %un%r", print->to, is_user ? kt_remove_user_s : kt_remove_group_s, id, f_string_eol_s); @@ -146,7 +146,7 @@ extern "C" { kt_remove_main_t * const main = (kt_remove_main_t *) print->custom; - if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_file_operate_simulate_not_d)) return F_output_not; + if (!(main->setting.flag & kt_remove_main_flag_simulate_d) || (flag_operate & kt_remove_flag_operate_simulate_not_d)) return F_output_not; if (match.used) { fll_print_format(" mode_matched %Q %@03un%r", print->to, match, mode, f_string_eol_s); diff --git a/sources/c/program/kevux/tools/remove/main/print/simulate.h b/sources/c/program/kevux/tools/remove/main/print/simulate.h index 1e2d608..6f1b470 100644 --- a/sources/c/program/kevux/tools/remove/main/print/simulate.h +++ b/sources/c/program/kevux/tools/remove/main/print/simulate.h @@ -54,7 +54,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param flag_operate - * The operate file specific flags from kt_remove_flag_file_operate_*_e. + * The operate file specific flags from kt_remove_flag_operate_*_e. * @param name * The name to be associated with the boolean value. * @param yes @@ -85,7 +85,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param flag_operate - * The operate file specific flags from kt_remove_flag_file_operate_*_e. + * The operate file specific flags from kt_remove_flag_operate_*_e. * @param name * The name to be associated with the boolean value. * @param yes @@ -122,7 +122,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param flag_operate - * The operate file specific flags from kt_remove_flag_file_operate_*_e. + * The operate file specific flags from kt_remove_flag_operate_*_e. * @param path * The path to the file to operate on. * @@ -150,9 +150,9 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param flag_operate - * The operate file specific flags from kt_remove_flag_file_operate_*_e. + * The operate file specific flags from kt_remove_flag_operate_*_e. * - * The kt_remove_flag_file_operate_link_d is of specific interest here. + * The kt_remove_flag_operate_link_d is of specific interest here. * @param path * The path to the file to operate on. * @param exists @@ -183,7 +183,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param flag_operate - * The operate file specific flags from kt_remove_flag_file_operate_*_e. + * The operate file specific flags from kt_remove_flag_operate_*_e. * @param id * The user or group ID. * @param is_user @@ -214,7 +214,7 @@ extern "C" { * * This does not alter print.custom.setting.state.status. * @param flag_operate - * The operate file specific flags from kt_remove_flag_file_operate_*_e. + * The operate file specific flags from kt_remove_flag_operate_*_e. * @param mode * The mode of the file. * @param match diff --git a/sources/c/program/kevux/tools/remove/remove/main.c b/sources/c/program/kevux/tools/remove/remove/main.c index 751f2c1..de5a823 100644 --- a/sources/c/program/kevux/tools/remove/remove/main.c +++ b/sources/c/program/kevux/tools/remove/remove/main.c @@ -33,9 +33,11 @@ int data.call.print_help = &kt_remove_print_message_help; #ifdef _en_kt_default_to_utc_ - data.setting.flag |= kt_remove_flag_utc_d; + data.setting.flag |= kt_remove_main_flag_utc_d; #endif // _en_kt_default_to_utc_ + data.setting.flag |= kt_remove_main_flag_remember_d; + f_console_parameter_t parameters[] = kt_remove_console_parameter_t_initialize; data.program.parameters.array = parameters; diff --git a/sources/c/program/kevux/tools/remove/rm/main.c b/sources/c/program/kevux/tools/remove/rm/main.c index cd15282..e6993c4 100644 --- a/sources/c/program/kevux/tools/remove/rm/main.c +++ b/sources/c/program/kevux/tools/remove/rm/main.c @@ -27,7 +27,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.call.print_help = &kt_remove_rm_print_message_help; #ifdef _en_kt_default_to_utc_ - data.setting.flag |= kt_remove_flag_utc_d; + data.setting.flag |= kt_remove_main_flag_utc_d; #endif // _en_kt_default_to_utc_ f_console_parameter_t parameters[] = kt_remove_rm_console_parameter_t_initialize; diff --git a/sources/c/program/kevux/tools/remove/rmdir/main.c b/sources/c/program/kevux/tools/remove/rmdir/main.c index 4d824af..6dc1098 100644 --- a/sources/c/program/kevux/tools/remove/rmdir/main.c +++ b/sources/c/program/kevux/tools/remove/rmdir/main.c @@ -27,7 +27,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.call.print_help = &kt_remove_rmdir_print_message_help; #ifdef _en_kt_default_to_utc_ - data.setting.flag |= kt_remove_flag_utc_d; + data.setting.flag |= kt_remove_main_flag_utc_d; #endif // _en_kt_default_to_utc_ f_console_parameter_t parameters[] = kt_remove_rmdir_console_parameter_t_initialize; diff --git a/sources/c/program/kevux/tools/remove/unlink/main.c b/sources/c/program/kevux/tools/remove/unlink/main.c index e6fc1de..103f9a5 100644 --- a/sources/c/program/kevux/tools/remove/unlink/main.c +++ b/sources/c/program/kevux/tools/remove/unlink/main.c @@ -27,7 +27,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { data.call.print_help = &kt_remove_unlink_print_message_help; #ifdef _en_kt_default_to_utc_ - data.setting.flag |= kt_remove_flag_utc_d; + data.setting.flag |= kt_remove_main_flag_utc_d; #endif // _en_kt_default_to_utc_ f_console_parameter_t parameters[] = kt_remove_unlink_console_parameter_t_initialize; diff --git a/tests/unit/remove/c/main-test-remove.c b/tests/unit/remove/c/main-test-remove.c index a41d352..d2080fe 100644 --- a/tests/unit/remove/c/main-test-remove.c +++ b/tests/unit/remove/c/main-test-remove.c @@ -26,7 +26,7 @@ int main_test__remove(const int argc, const f_string_t *argv, const f_string_t * data.call.print_help = &kt_remove_print_message_help; #ifdef _en_kt_default_to_utc_ - data.setting.flag |= kt_remove_flag_utc_d; + data.setting.flag |= kt_remove_main_flag_utc_d; #endif // _en_kt_default_to_utc_ f_console_parameter_t parameters[] = kt_remove_console_parameter_t_initialize; diff --git a/tests/unit/remove/c/test-remove-date_accessed.c b/tests/unit/remove/c/test-remove-date_accessed.c index 0abadb1..005fe03 100644 --- a/tests/unit/remove/c/test-remove-date_accessed.c +++ b/tests/unit/remove/c/test-remove-date_accessed.c @@ -117,7 +117,7 @@ void test__kt_remove__date_accessed__date_works(void **state) { uint8_t date = 0; uint8_t param = 0; - for (; type < types_total; ++type) { + for (type = 0; type < types_total; ++type) { for (date = 0; date < dates_total; ++date) { @@ -135,14 +135,15 @@ void test__kt_remove__date_accessed__date_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -300,12 +301,15 @@ void test__kt_remove__date_accessed__now_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -462,12 +466,15 @@ void test__kt_remove__date_accessed__today_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -624,12 +631,15 @@ void test__kt_remove__date_accessed__tomorrow_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -786,12 +796,15 @@ void test__kt_remove__date_accessed__yesterday_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); diff --git a/tests/unit/remove/c/test-remove-date_changed.c b/tests/unit/remove/c/test-remove-date_changed.c index 59efe80..2c1aea3 100644 --- a/tests/unit/remove/c/test-remove-date_changed.c +++ b/tests/unit/remove/c/test-remove-date_changed.c @@ -135,14 +135,15 @@ void test__kt_remove__date_changed__date_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -300,12 +301,15 @@ void test__kt_remove__date_changed__now_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -462,12 +466,15 @@ void test__kt_remove__date_changed__today_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -624,12 +631,15 @@ void test__kt_remove__date_changed__tomorrow_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -786,12 +796,15 @@ void test__kt_remove__date_changed__yesterday_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); diff --git a/tests/unit/remove/c/test-remove-date_updated.c b/tests/unit/remove/c/test-remove-date_updated.c index faa76c8..c53ddd2 100644 --- a/tests/unit/remove/c/test-remove-date_updated.c +++ b/tests/unit/remove/c/test-remove-date_updated.c @@ -135,14 +135,15 @@ void test__kt_remove__date_updated__date_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -300,12 +301,15 @@ void test__kt_remove__date_updated__now_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -462,12 +466,15 @@ void test__kt_remove__date_updated__today_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -624,12 +631,15 @@ void test__kt_remove__date_updated__tomorrow_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -786,12 +796,15 @@ void test__kt_remove__date_updated__yesterday_works(void **state) { will_return(__wrap_f_time_clock_get, &time_spec_clocks); will_return(__wrap_f_time_clock_get, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); 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 fe417c2..75f61f2 100644 --- a/tests/unit/remove/c/test-remove-directory_no_args.c +++ b/tests/unit/remove/c/test-remove-directory_no_args.c @@ -20,11 +20,11 @@ void test__kt_remove__directory_no_args__one_empty_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", target.string, 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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -54,11 +54,11 @@ void test__kt_remove__directory_no_args__one_empty_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", target.string, "+" F_console_standard_short_verbose_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -88,11 +88,11 @@ void test__kt_remove__directory_no_args__one_empty_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", target.string, "+" F_console_standard_short_debug_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -132,11 +132,11 @@ void test__kt_remove__directory_no_args__one_empty_exists_link_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, 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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -166,11 +166,11 @@ void test__kt_remove__directory_no_args__one_empty_exists_link_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, "+" F_console_standard_short_verbose_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -200,11 +200,11 @@ void test__kt_remove__directory_no_args__one_empty_exists_link_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, "+" F_console_standard_short_debug_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -283,19 +283,19 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) const f_string_t argv[] = { "mocked_main", target.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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. memset(&statistics_regular, 0, sizeof(struct stat)); - statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. - will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_file_operate_empty_d is set. + will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_operate_empty_d is set. will_return(__wrap_fl_directory_do, 1); will_return(__wrap_fl_directory_do, &target); will_return(__wrap_fl_directory_do, &target); @@ -303,12 +303,11 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_directory_empty, F_false); - // @fixme when removal is attempted on non-empty directory due to empty not flag being set this likely should fail to remove on error that directory is not empty (recursive would need to be passed to succeed). // 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); @@ -321,19 +320,19 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) const f_string_t argv[] = { "mocked_main", target.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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. memset(&statistics_regular, 0, sizeof(struct stat)); - statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. - will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_file_operate_empty_d is set. + will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_operate_empty_d is set. will_return(__wrap_fl_directory_do, 1); will_return(__wrap_fl_directory_do, &target); will_return(__wrap_fl_directory_do, &target); @@ -341,7 +340,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_directory_empty, F_false); @@ -358,19 +357,19 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) const f_string_t argv[] = { "mocked_main", target.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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. memset(&statistics_regular, 0, sizeof(struct stat)); - statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. - will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_file_operate_empty_d is set. + will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_operate_empty_d is set. will_return(__wrap_fl_directory_do, 1); will_return(__wrap_fl_directory_do, &target); will_return(__wrap_fl_directory_do, &target); @@ -378,7 +377,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_directory_empty, F_false); @@ -407,26 +406,26 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st const f_string_t argv[] = { "mocked_main", target.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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. memset(&statistics_regular, 0, sizeof(struct stat)); - statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. - will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_file_operate_empty_d is set. + will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_operate_empty_d is set. will_return(__wrap_fl_directory_do, 2); will_return(__wrap_fl_directory_do, &child); will_return(__wrap_fl_directory_do, &child); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -438,7 +437,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_directory_empty, F_false); @@ -455,26 +454,26 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st const f_string_t argv[] = { "mocked_main", target.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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. memset(&statistics_regular, 0, sizeof(struct stat)); - statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. - will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_file_operate_empty_d is set. + will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_operate_empty_d is set. will_return(__wrap_fl_directory_do, 2); will_return(__wrap_fl_directory_do, &child); will_return(__wrap_fl_directory_do, &child); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -486,7 +485,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_directory_empty, F_false); @@ -503,26 +502,26 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st const f_string_t argv[] = { "mocked_main", target.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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. memset(&statistics_regular, 0, sizeof(struct stat)); - statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics_regular.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. - will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_file_operate_empty_d is set. + will_return(__wrap_f_directory_empty, F_false); // kt_remove_flag_operate_empty_d is set. will_return(__wrap_fl_directory_do, 2); will_return(__wrap_fl_directory_do, &child); will_return(__wrap_fl_directory_do, &child); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -534,7 +533,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_directory_empty, F_false); @@ -562,7 +561,7 @@ void test__kt_remove__directory_no_args__two_empty_exists_and_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, target_also.string, 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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_false); @@ -576,7 +575,7 @@ void test__kt_remove__directory_no_args__two_empty_exists_and_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, target_also.string, "+" F_console_standard_short_verbose_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_false); @@ -590,7 +589,7 @@ void test__kt_remove__directory_no_args__two_empty_exists_and_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, target_also.string, "+" F_console_standard_short_debug_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_false); @@ -615,11 +614,11 @@ void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", target.string, target_also.string, 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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -642,15 +641,15 @@ void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) { // Pre-process target 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. will_return(__wrap_f_directory_empty, F_true); will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target_also); + will_return(__wrap_fl_directory_do, &target_also); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. @@ -672,11 +671,11 @@ void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", target.string, target_also.string, "+" F_console_standard_short_verbose_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -699,15 +698,15 @@ void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) { // Pre-process target 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. will_return(__wrap_f_directory_empty, F_true); will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target_also); + will_return(__wrap_fl_directory_do, &target_also); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. @@ -729,11 +728,11 @@ void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", target.string, target_also.string, "+" F_console_standard_short_debug_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -756,15 +755,15 @@ void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) { // Pre-process target 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. will_return(__wrap_f_directory_empty, F_true); will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target_also); + will_return(__wrap_fl_directory_do, &target_also); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. @@ -797,11 +796,11 @@ void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, target_also.string, 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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -824,15 +823,15 @@ void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state) // Pre-process target 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. will_return(__wrap_f_directory_empty, F_true); will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target_also); + will_return(__wrap_fl_directory_do, &target_also); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. @@ -854,11 +853,11 @@ void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, target_also.string, "+" F_console_standard_short_verbose_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -881,15 +880,15 @@ void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state) // Pre-process target 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. will_return(__wrap_f_directory_empty, F_true); will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target_also); + will_return(__wrap_fl_directory_do, &target_also); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. @@ -911,11 +910,11 @@ void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state) const f_string_t argv[] = { "mocked_main", target.string, target_also.string, "+" F_console_standard_short_debug_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. + statistics.st_mode = F_file_mode_all_d | F_file_type_directory_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process target 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -938,15 +937,15 @@ void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state) // Pre-process target 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); // Directory processing. will_return(__wrap_f_directory_empty, F_true); will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target_also); + will_return(__wrap_fl_directory_do, &target_also); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. diff --git a/tests/unit/remove/c/test-remove-directory_recurse_simple.c b/tests/unit/remove/c/test-remove-directory_recurse_simple.c index 0c04b1a..7968a0d 100644 --- a/tests/unit/remove/c/test-remove-directory_recurse_simple.c +++ b/tests/unit/remove/c/test-remove-directory_recurse_simple.c @@ -29,7 +29,7 @@ void test__kt_remove__directory_recurse_simple__one_child_one_exists_link(void * // Pre-process file. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); @@ -42,7 +42,7 @@ void test__kt_remove__directory_recurse_simple__one_child_one_exists_link(void * will_return(__wrap_fl_directory_do, &child_1); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -89,7 +89,7 @@ void test__kt_remove__directory_recurse_simple__one_child_one_exists_link_not(vo // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); @@ -102,7 +102,7 @@ void test__kt_remove__directory_recurse_simple__one_child_one_exists_link_not(vo will_return(__wrap_fl_directory_do, &child_1); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -150,7 +150,7 @@ void test__kt_remove__directory_recurse_simple__one_child_two_exists_link(void * // Pre-process file. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); @@ -163,7 +163,7 @@ void test__kt_remove__directory_recurse_simple__one_child_two_exists_link(void * will_return(__wrap_fl_directory_do, &child_1); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -173,7 +173,7 @@ void test__kt_remove__directory_recurse_simple__one_child_two_exists_link(void * will_return(__wrap_fl_directory_do, &child_2); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -221,7 +221,7 @@ void test__kt_remove__directory_recurse_simple__one_child_two_exists_link_not(vo // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_directory); will_return(__wrap_f_file_stat, F_okay); @@ -234,7 +234,7 @@ void test__kt_remove__directory_recurse_simple__one_child_two_exists_link_not(vo will_return(__wrap_fl_directory_do, &child_1); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); @@ -244,7 +244,7 @@ void test__kt_remove__directory_recurse_simple__one_child_two_exists_link_not(vo will_return(__wrap_fl_directory_do, &child_2); will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_regular_d); will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_file_remove, F_okay); 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 13afcb2..046e160 100644 --- a/tests/unit/remove/c/test-remove-directory_tree_simple.c +++ b/tests/unit/remove/c/test-remove-directory_tree_simple.c @@ -28,7 +28,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li // Pre-process file. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); @@ -37,7 +37,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li // Pre-process parent directory 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_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_true); @@ -72,7 +72,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); @@ -81,7 +81,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li // Pre-process parent directory 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_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_true); @@ -116,7 +116,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li // Pre-process file. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); @@ -125,7 +125,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li // Pre-process parent directory 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_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_true); @@ -135,7 +135,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li // Pre-process parent directory 2. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_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_true); @@ -170,7 +170,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stat_regular); will_return(__wrap_f_file_stat, F_okay); @@ -179,7 +179,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li // Pre-process parent directory 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_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_true); @@ -189,7 +189,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li // Pre-process parent directory 2. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_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_true); diff --git a/tests/unit/remove/c/test-remove-epochtime.c b/tests/unit/remove/c/test-remove-epochtime.c index 6721fa4..10204b9 100644 --- a/tests/unit/remove/c/test-remove-epochtime.c +++ b/tests/unit/remove/c/test-remove-epochtime.c @@ -140,14 +140,15 @@ void test__kt_remove__epochtime__accessed_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -305,14 +306,15 @@ void test__kt_remove__epochtime__changed_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -470,14 +472,15 @@ void test__kt_remove__epochtime__updated_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); diff --git a/tests/unit/remove/c/test-remove-file_mode.c b/tests/unit/remove/c/test-remove-file_mode.c index 13a6451..81ea302 100644 --- a/tests/unit/remove/c/test-remove-file_mode.c +++ b/tests/unit/remove/c/test-remove-file_mode.c @@ -84,14 +84,18 @@ void test__kt_remove__file_mode__different_works(void **state) { will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(statistics.st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (param != mode) { if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -106,11 +110,6 @@ void test__kt_remove__file_mode__different_works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(5, argv, 0); @@ -198,14 +197,18 @@ void test__kt_remove__file_mode__same_works(void **state) { will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(statistics.st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (param == mode) { if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -220,11 +223,6 @@ void test__kt_remove__file_mode__same_works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(5, argv, 0); @@ -312,14 +310,17 @@ void test__kt_remove__file_mode__similar_works(void **state) { will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(statistics.st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (modes[param] & modes[mode]) { if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -334,11 +335,6 @@ void test__kt_remove__file_mode__similar_works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(5, argv, 0); @@ -426,14 +422,18 @@ void test__kt_remove__file_mode__not_works(void **state) { will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(statistics.st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (modes[param] != modes[mode]) { if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -448,11 +448,6 @@ void test__kt_remove__file_mode__not_works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(statistics.st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(5, argv, 0); diff --git a/tests/unit/remove/c/test-remove-file_type.c b/tests/unit/remove/c/test-remove-file_type.c index 9539b9f..6f88be0 100644 --- a/tests/unit/remove/c/test-remove-file_type.c +++ b/tests/unit/remove/c/test-remove-file_type.c @@ -56,19 +56,23 @@ void test__kt_remove__file_type__works(void **state) { will_return(__wrap_f_file_stat, &stats[i]); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(stats[i].st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (i == type) { if (macro_f_file_type_is_directory(stats[i].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, macro_f_file_type_is_link(stats[type].st_mode)); - will_return(__wrap_f_file_stat, &stats[type]); + will_return(__wrap_f_file_is, macro_f_file_type_is_link(stats[i].st_mode)); + will_return(__wrap_f_file_stat, &stats[i]); will_return(__wrap_f_file_stat, F_okay); will_return(__wrap_f_directory_empty, F_true); diff --git a/tests/unit/remove/c/test-remove-group.c b/tests/unit/remove/c/test-remove-group.c index 90c6c8d..2f5a093 100644 --- a/tests/unit/remove/c/test-remove-group.c +++ b/tests/unit/remove/c/test-remove-group.c @@ -39,18 +39,22 @@ void test__kt_remove__group__name_works(void **state) { // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stats[type]); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (stats[type].st_gid == group_id) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -65,11 +69,6 @@ void test__kt_remove__group__name_works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(4, argv, 0); diff --git a/tests/unit/remove/c/test-remove-regular_no_args.c b/tests/unit/remove/c/test-remove-regular_no_args.c index ad74fea..9d98695 100644 --- a/tests/unit/remove/c/test-remove-regular_no_args.c +++ b/tests/unit/remove/c/test-remove-regular_no_args.c @@ -18,11 +18,11 @@ void test__kt_remove__regular_no_args__one_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -38,11 +38,11 @@ void test__kt_remove__regular_no_args__one_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "+" F_console_standard_short_verbose_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -58,11 +58,11 @@ void test__kt_remove__regular_no_args__one_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "+" F_console_standard_short_debug_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -86,11 +86,11 @@ void test__kt_remove__regular_no_args__one_exists_link_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -106,11 +106,11 @@ void test__kt_remove__regular_no_args__one_exists_link_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "+" F_console_standard_short_verbose_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -126,11 +126,11 @@ void test__kt_remove__regular_no_args__one_exists_link_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "+" F_console_standard_short_debug_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -190,7 +190,7 @@ void test__kt_remove__regular_no_args__two_exists_and_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_false); @@ -204,7 +204,7 @@ void test__kt_remove__regular_no_args__two_exists_and_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", "+" F_console_standard_short_verbose_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_false); @@ -218,7 +218,7 @@ void test__kt_remove__regular_no_args__two_exists_and_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", "+" F_console_standard_short_debug_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_false); @@ -240,11 +240,11 @@ void test__kt_remove__regular_no_args__two_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -253,7 +253,7 @@ void test__kt_remove__regular_no_args__two_exists_link(void **state) { // Pre-process file 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -269,11 +269,11 @@ void test__kt_remove__regular_no_args__two_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", "+" F_console_standard_short_verbose_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -282,7 +282,7 @@ void test__kt_remove__regular_no_args__two_exists_link(void **state) { // Pre-process file 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -298,11 +298,11 @@ void test__kt_remove__regular_no_args__two_exists_link(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", "+" F_console_standard_short_debug_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -311,7 +311,7 @@ void test__kt_remove__regular_no_args__two_exists_link(void **state) { // Pre-process file 2. will_return(__wrap_f_file_exists, F_true); - will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_file_operate_link_d is set. + will_return(__wrap_f_file_is, F_true); // A link, kt_remove_flag_operate_link_d is set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -335,11 +335,11 @@ void test__kt_remove__regular_no_args__two_exists_link_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -348,7 +348,7 @@ void test__kt_remove__regular_no_args__two_exists_link_not(void **state) { // Pre-process file 2. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -364,11 +364,11 @@ void test__kt_remove__regular_no_args__two_exists_link_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", "+" F_console_standard_short_verbose_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -377,7 +377,7 @@ void test__kt_remove__regular_no_args__two_exists_link_not(void **state) { // Pre-process file 2. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -393,11 +393,11 @@ void test__kt_remove__regular_no_args__two_exists_link_not(void **state) { const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", "+" F_console_standard_short_debug_s, 0 }; memset(&statistics, 0, sizeof(struct stat)); - statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_file_operate_remove_d. + statistics.st_mode = F_file_mode_all_d | F_file_type_regular_d; // Should result in kt_remove_flag_operate_remove_d. // Pre-process file 1. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); @@ -406,7 +406,7 @@ void test__kt_remove__regular_no_args__two_exists_link_not(void **state) { // Pre-process file 2. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &statistics); will_return(__wrap_f_file_stat, F_okay); diff --git a/tests/unit/remove/c/test-remove-time.c b/tests/unit/remove/c/test-remove-time.c index bc51ed6..f13a3ca 100644 --- a/tests/unit/remove/c/test-remove-time.c +++ b/tests/unit/remove/c/test-remove-time.c @@ -147,14 +147,15 @@ void test__kt_remove__time__accessed_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -319,14 +320,15 @@ void test__kt_remove__time__changed_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -491,14 +493,15 @@ void test__kt_remove__time__updated_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); diff --git a/tests/unit/remove/c/test-remove-unix.c b/tests/unit/remove/c/test-remove-unix.c index 0845b72..41824b0 100644 --- a/tests/unit/remove/c/test-remove-unix.c +++ b/tests/unit/remove/c/test-remove-unix.c @@ -134,14 +134,15 @@ void test__kt_remove__unix__accessed_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -291,14 +292,15 @@ void test__kt_remove__unix__changed_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -448,14 +450,15 @@ void test__kt_remove__unix__updated_works(void **state) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { will_return(__wrap_f_directory_empty, F_true); + + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } if (time_spec_removes[date]) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); diff --git a/tests/unit/remove/c/test-remove-user.c b/tests/unit/remove/c/test-remove-user.c index a3a4503..05ecfe5 100644 --- a/tests/unit/remove/c/test-remove-user.c +++ b/tests/unit/remove/c/test-remove-user.c @@ -39,23 +39,21 @@ void test__kt_remove__user__different_works(void **state) { // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stats[type]); will_return(__wrap_f_file_stat, F_okay); - // Process file. - if (stats[type].st_uid == user_id) { - if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); } - else { + + // Process file. + if (stats[type].st_uid != user_id) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_geteuid, user_id); @@ -111,18 +109,21 @@ void test__kt_remove__user__name_works(void **state) { // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stats[type]); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (stats[type].st_uid == user_id) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_f_file_exists, F_true); @@ -137,11 +138,6 @@ void test__kt_remove__user__name_works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(4, argv, 0); @@ -181,18 +177,21 @@ void test__kt_remove__user__same_works(void **state) { // Pre-process file. will_return(__wrap_f_file_exists, F_true); - 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_is, F_false); // Not a link, kt_remove_flag_operate_link_d is not set. will_return(__wrap_f_file_stat, &stats[type]); will_return(__wrap_f_file_stat, F_okay); + if (macro_f_file_type_is_directory(stats[type].st_mode)) { + will_return(__wrap_f_directory_empty, F_true); + will_return(__wrap_fl_directory_do, 1); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, &target); + will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); + } + // Process file. if (stats[type].st_uid == user_id) { if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - will_return(__wrap_fl_directory_do, 1); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, &target); - will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_d | f_directory_recurse_do_flag_directory_d); // The pre-process gets called again before the final removal for directories. will_return(__wrap_geteuid, user_id); @@ -209,11 +208,6 @@ void test__kt_remove__user__same_works(void **state) { will_return(__wrap_f_file_remove, F_okay); } } - else { - if (macro_f_file_type_is_directory(stats[type].st_mode)) { - will_return(__wrap_f_directory_empty, F_true); - } - } const int result = kt_main_test__remove(3, argv, 0);