]> Kevux Git Server - fll/commitdiff
Update: The fake program should check file existence when clean is combined with...
authorKevin Day <thekevinday@gmail.com>
Thu, 23 Jun 2022 23:52:19 +0000 (18:52 -0500)
committerKevin Day <thekevinday@gmail.com>
Thu, 23 Jun 2022 23:52:19 +0000 (18:52 -0500)
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
level_3/fake/c/private-common.c
level_3/fake/c/private-common.h
level_3/fake/c/private-fake.c
level_3/fake/c/private-fake.h

index da714a378606517cd950c93fc8d6f20882a1df18..628554b0435e51954ff057fdee2db50235b46070 100644 (file)
@@ -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)) {
index 6275c884a6e20030e5a3cf9658300beefd2f6ed2..6eccc554ee3f55d7cfb03c85787a9257f9683083 100644 (file)
@@ -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);
index 38ecfdce9e13bfae6522fc4bb91085919cebc086..ef5bbd1c7f7ca0a7093467631632a3c643bbdfdd 100644 (file)
@@ -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;
index 795119c32d4a760270d7b9c1dacbd3c6686dd7eb..cdf06001cebb5b6606861989270dd400d062c3bf 100644 (file)
@@ -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) {
index 77e5f733496cdb4d5432fb8a989784e375e2c486..2114c9df3cc031118d03cb86396b1b7fb61398aa 100644 (file)
@@ -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.