From 763a19619bc6bf010971f69cec05f07d9c59a0c5 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 23 Jun 2022 18:52:19 -0500 Subject: [PATCH] Update: The fake program should check file existence when clean is combined with another command like build or make. When the make or build command is specified after a clean command, the clean command should do an appropriate file dependency check. This acts as a safety measure such that if the make or build command could not normally be run due to the missing required files, then the clean operation should not be run. Rename a related function to a shorter name. --- level_3/fake/c/fake.c | 153 ++++++++++++++++++++++++++-------------- level_3/fake/c/private-common.c | 1 + level_3/fake/c/private-common.h | 3 + level_3/fake/c/private-fake.c | 6 +- level_3/fake/c/private-fake.h | 6 +- 5 files changed, 110 insertions(+), 59 deletions(-) diff --git a/level_3/fake/c/fake.c b/level_3/fake/c/fake.c index da714a3..628554b 100644 --- a/level_3/fake/c/fake.c +++ b/level_3/fake/c/fake.c @@ -264,7 +264,7 @@ extern "C" { } if (operations_length) { - bool validate_parameter_directories = F_true; + bool validate_parameter_paths = F_true; status = fake_process_console_parameters(&data); @@ -278,69 +278,118 @@ extern "C" { return F_status_set_error(status); } - for (uint8_t i = 0; i < operations_length; ++i) { + { + uint8_t i = 0; - data.operation = operations[i]; + // Pre-process and perform validation when "clean" is before a "build" or "make" command as a safety check. + for (uint8_t has_clean = F_false; i < operations_length; ++i) { - if (data.operation == fake_operation_build_e) { - operations_name = fake_other_operation_build_s; - } - else if (data.operation == fake_operation_clean_e) { - operations_name = fake_other_operation_clean_s; - } - else if (data.operation == fake_operation_make_e) { - operations_name = fake_other_operation_make_s; - } - else if (data.operation == fake_operation_skeleton_e) { - operations_name = fake_other_operation_skeleton_s; - } - - if (data.operation == fake_operation_build_e) { - if (validate_parameter_directories) { - status = fake_validate_parameter_directories(&data); - validate_parameter_directories = F_false; + if (operations[i] == fake_operation_clean_e) { + has_clean = F_true; } + else if (operations[i] == fake_operation_build_e || operations[i] == fake_operation_make_e) { - if (F_status_is_error_not(status)) { - status = fake_build_operate(&data, 0); - } - } - else if (data.operation == fake_operation_clean_e) { - status = fake_clean_operate(&data); + // If the first operation is clean and a make or build operation exists, then the clean operation requires the appropriate settings file or fakefile file. + if (has_clean) { + operations_name = fake_other_operation_clean_s; + data.operation = operations[i]; - // Reset in case next operation needs files. - validate_parameter_directories = F_true; - } - else if (data.operation == fake_operation_make_e) { - if (validate_parameter_directories) { - status = fake_validate_parameter_directories(&data); - validate_parameter_directories = F_false; - } + status = fake_validate_parameter_paths(&data); - if (F_status_is_error_not(status)) { - status = fake_make_operate(&data); - if (status == F_child) break; - } - } - else if (data.operation == fake_operation_skeleton_e) { - status = fake_skeleton_operate(&data); + if (F_status_is_error_not(status)) { + f_string_static_t *path = 0; - // Skeleton is supposed to guarantee these. - validate_parameter_directories = F_false; - } + if (operations[i] == fake_operation_build_e) { + path = &data.file_data_build_settings; + } + else { + path = &data.file_data_build_fakefile; + } - if (status == F_child) break; + status = f_file_is(*path, F_file_type_regular_d, F_false); - if (F_status_set_fine(status) == F_interrupt || !(i % fake_signal_check_short_d)) { - if (fll_program_standard_signal_received(main)) { - fake_print_signal_received(&data); + if (status == F_false) { + status = F_status_set_error(F_file_not); + } - status = F_status_set_error(F_interrupt); + if (F_status_is_error(status)) { + fll_error_file_print(data.main->error, F_status_set_fine(status), "f_file_is", F_true, *path, fake_common_file_path_access_s, fll_error_file_type_file_e); + } + } + } break; } + } // for + + if (F_status_is_error_not(status)) { + for (i = 0; i < operations_length; ++i) { + + data.operation = operations[i]; + + if (data.operation == fake_operation_build_e) { + operations_name = fake_other_operation_build_s; + } + else if (data.operation == fake_operation_clean_e) { + operations_name = fake_other_operation_clean_s; + } + else if (data.operation == fake_operation_make_e) { + operations_name = fake_other_operation_make_s; + } + else if (data.operation == fake_operation_skeleton_e) { + operations_name = fake_other_operation_skeleton_s; + } + + if (data.operation == fake_operation_build_e) { + if (validate_parameter_paths) { + status = fake_validate_parameter_paths(&data); + validate_parameter_paths = F_false; + } + + if (F_status_is_error_not(status)) { + status = fake_build_operate(&data, 0); + } + } + else if (data.operation == fake_operation_clean_e) { + status = fake_clean_operate(&data); + + // Reset in case next operation needs files. + validate_parameter_paths = F_true; + } + else if (data.operation == fake_operation_make_e) { + if (validate_parameter_paths) { + status = fake_validate_parameter_paths(&data); + validate_parameter_paths = F_false; + } + + if (F_status_is_error_not(status)) { + status = fake_make_operate(&data); + if (status == F_child) break; + } + } + else if (data.operation == fake_operation_skeleton_e) { + status = fake_skeleton_operate(&data); + + // Skeleton is supposed to guarantee these. + validate_parameter_paths = F_false; + } + + if (status == F_child) break; + + if (F_status_set_fine(status) == F_interrupt || !(i % fake_signal_check_short_d)) { + if (fll_program_standard_signal_received(main)) { + fake_print_signal_received(&data); - main->signal_check = 0; + status = F_status_set_error(F_interrupt); + + break; + } + + main->signal_check = 0; + } + + if (F_status_is_error(status)) break; + } // for } if (F_status_is_error(status)) { @@ -353,10 +402,8 @@ extern "C" { funlockfile(main->error.to.stream); } - - break; } - } // for + } if (main->error.verbosity != f_console_verbosity_quiet_e) { if (F_status_is_error(status)) { diff --git a/level_3/fake/c/private-common.c b/level_3/fake/c/private-common.c index 6275c88..6eccc55 100644 --- a/level_3/fake/c/private-common.c +++ b/level_3/fake/c/private-common.c @@ -143,6 +143,7 @@ extern "C" { #endif // _di_fake_build_parameter_ #ifndef _di_fake_common_ + const f_string_static_t fake_common_file_path_access_s = macro_f_string_static_t_initialize(FAKE_common_file_path_access_s, 0, FAKE_common_file_path_access_s_length); const f_string_static_t fake_common_file_directory_copy_s = macro_f_string_static_t_initialize(FAKE_common_file_directory_copy_s, 0, FAKE_common_file_directory_copy_s_length); const f_string_static_t fake_common_file_path_change_to_s = macro_f_string_static_t_initialize(FAKE_common_file_path_change_to_s, 0, FAKE_common_file_path_change_to_s_length); const f_string_static_t fake_common_file_path_determine_real_s = macro_f_string_static_t_initialize(FAKE_common_file_path_determine_real_s, 0, FAKE_common_file_path_determine_real_s_length); diff --git a/level_3/fake/c/private-common.h b/level_3/fake/c/private-common.h index 38ecfdc..ef5bbd1 100644 --- a/level_3/fake/c/private-common.h +++ b/level_3/fake/c/private-common.h @@ -950,6 +950,7 @@ extern "C" { #define fake_common_allocation_small_d 16 #define FAKE_common_file_directory_copy_s "copy directory" + #define FAKE_common_file_path_access_s "access" #define FAKE_common_file_path_change_to_s "change path to" #define FAKE_common_file_path_determine_real_s "determine real path of" #define FAKE_common_file_path_stack_s "path stack" @@ -961,6 +962,7 @@ extern "C" { #define FAKE_common_setting_list_s "list" #define FAKE_common_file_directory_copy_s_length 14 + #define FAKE_common_file_path_access_s_length 6 #define FAKE_common_file_path_change_to_s_length 14 #define FAKE_common_file_path_determine_real_s_length 22 #define FAKE_common_file_path_stack_s_length 10 @@ -972,6 +974,7 @@ extern "C" { #define FAKE_common_setting_list_s_length 4 extern const f_string_static_t fake_common_file_directory_copy_s; + extern const f_string_static_t fake_common_file_path_access_s; extern const f_string_static_t fake_common_file_path_change_to_s; extern const f_string_static_t fake_common_file_path_determine_real_s; extern const f_string_static_t fake_common_file_path_stack_s; diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index 795119c..cdf0600 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -510,8 +510,8 @@ extern "C" { } #endif // _di_fake_process_console_parameters_ -#ifndef _di_fake_validate_directories_ - f_status_t fake_validate_parameter_directories(fake_data_t * const data) { +#ifndef _di_fake_validate_parameter_paths_ + f_status_t fake_validate_parameter_paths(fake_data_t * const data) { if (fll_program_standard_signal_received(data->main)) { fake_print_signal_received(data); @@ -596,7 +596,7 @@ extern "C" { return F_none; } -#endif // _di_fake_validate_parameter_directories_ +#endif // _di_fake_validate_parameter_paths_ #ifndef _di_fake_verbose_print_clone_ void fake_verbose_print_clone(const f_file_t output, const f_string_static_t source, const f_string_static_t destination) { diff --git a/level_3/fake/c/private-fake.h b/level_3/fake/c/private-fake.h index 77e5f73..2114c9d 100644 --- a/level_3/fake/c/private-fake.h +++ b/level_3/fake/c/private-fake.h @@ -89,9 +89,9 @@ extern "C" { * * Status codes (with error bit) are returned on any problem. */ -#ifndef _di_fake_validate_parameter_directories_ - extern f_status_t fake_validate_parameter_directories(fake_data_t * const data) F_attribute_visibility_internal_d; -#endif // _di_fake_validate_parameter_directories_ +#ifndef _di_fake_validate_parameter_paths_ + extern f_status_t fake_validate_parameter_paths(fake_data_t * const data) F_attribute_visibility_internal_d; +#endif // _di_fake_validate_parameter_paths_ /** * Helper function for performing a verbose print for a file clone operation. -- 1.8.3.1