]> Kevux Git Server - kevux-tools/commitdiff
Progress: Continue working on completing the remove program.
authorKevin Day <Kevin@kevux.org>
Thu, 20 Feb 2025 04:07:11 +0000 (22:07 -0600)
committerKevin Day <Kevin@kevux.org>
Thu, 20 Feb 2025 04:27:35 +0000 (22:27 -0600)
Implement the memory cache for the remember parameter.

sources/c/program/kevux/tools/remove/main/common/print.c
sources/c/program/kevux/tools/remove/main/common/print.h
sources/c/program/kevux/tools/remove/main/operate.c
sources/c/program/kevux/tools/remove/main/operate.h

index f0cda1ef8b2e68e0d75a7d9b29b8fcf93920f931..091e3311bc85ddf9f2b55fe4c2a9f1e26c2b5582 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
     "kt_remove_dates_resize",
     "kt_remove_get_id",
     "kt_remove_modes_resize",
+    "kt_remove_operate_memory_save",
     "kt_remove_setting_load",
   };
 #endif // _di_kt_remove_f_a_
index 94b14f83c5b9241e41f32b4fe9a52eda451605b0..b9cff65e54ce494396884bb791326613a05f3164 100644 (file)
@@ -64,6 +64,7 @@ extern "C" {
     kt_remove_f_kt_remove_dates_resize_e,
     kt_remove_f_kt_remove_get_id_e,
     kt_remove_f_kt_remove_modes_resize_e,
+    kt_remove_f_kt_remove_operate_memory_save_e,
     kt_remove_f_kt_remove_setting_load_e,
   }; // enum
 #endif // _di_kt_remove_f_e_
index 30c3d2dc927238ce0a9060ac8417494103fb5991..ddb96691136883acd2b537b2a4d5c65962f446ed 100644 (file)
@@ -19,13 +19,17 @@ extern "C" {
 
     const uint16_t flag_operate = kt_remove_preprocess_file(main, path, 0);
 
-    if (F_status_is_error_not(main->setting.state.status) && !(main->setting.flag & (kt_remove_main_flag_simulate_d)) && !(flag_operate & kt_remove_flag_file_operate_processed_d)) {
+    if (F_status_is_error_not(main->setting.state.status) && !(main->setting.flag & kt_remove_main_flag_simulate_d) && !(flag_operate & kt_remove_flag_file_operate_processed_d)) {
       main->setting.state.status = flag_operate & kt_remove_flag_file_operate_directory_d
         ? kt_remove_operate_file_recurse(main, path, flag_operate)
         : kt_remove_operate_file_remove(main, path, flag_operate);
+    }
 
-      if (F_status_is_error_not(main->setting.state.status)) {
-        kt_remove_operate_memory_save(main, path, flag_operate);
+    if (F_status_is_error_not(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);
       }
     }
 
@@ -156,8 +160,60 @@ extern "C" {
 
     if (!main->cache.memory.used) return;
 
-    // @todo check list and then set F_remove_not as appropriate.
-    // *flag_operate |= kt_remove_flag_file_operate_processed_d
+    f_range_t range = f_range_t_initialize;
+    f_number_unsigned_t i = 0;
+
+    if (main->setting.flag & kt_remove_main_flag_recurse_d) {
+      for (; i < main->cache.memory.used; ++i) {
+
+        if (kt_remove_signal_check(main)) return;
+        if (!main->cache.memory.array[i].used) continue;
+
+        // The memory cache is nulless and top-most directories end in slashes.
+        range.start = 0;
+        range.stop = main->cache.memory.array[i].used - 1;
+
+        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;
+
+            break;
+          }
+
+          // Perform exact match without the trailing directory slash.
+          if (range.stop) {
+            --range.stop;
+          }
+
+          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;
+
+            break;
+          }
+        }
+        else {
+          if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) {
+            *flag_operate |= kt_remove_flag_file_operate_processed_d;
+
+            break;
+          }
+        }
+      } // for
+    }
+    else {
+
+      // Only perform exact matches when not using recursion.
+      for (; i < main->cache.memory.used; ++i) {
+
+        if (kt_remove_signal_check(main)) return;
+
+        if (f_compare_dynamic(main->cache.memory.array[i], path) == F_equal_to) {
+          *flag_operate |= kt_remove_flag_file_operate_processed_d;
+
+          break;
+        }
+      } // for
+    }
   }
 #endif // _di_kt_remove_operate_memory_check_
 
@@ -178,7 +234,71 @@ extern "C" {
       return;
     }
 
-    // @todo
+    main->setting.state.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(main->setting.state.status) && (flag_operate & kt_remove_flag_file_operate_directory_d)) {
+      main->cache.buffer.used = 0;
+
+      main->setting.state.status = f_memory_array_increase_by(path.used + f_path_separator_s.used, sizeof(f_char_t), (void **) &main->cache.buffer.string, &main->cache.buffer.used, &main->cache.buffer.size);
+
+      if (F_status_is_error_not(main->setting.state.status)) {
+        main->setting.state.status = f_string_dynamic_append_nulless(path, &main->cache.buffer);
+      }
+
+      if (F_status_is_error_not(main->setting.state.status)) {
+        main->setting.state.status = f_string_dynamic_append_nulless(f_path_separator_s, &main->cache.buffer);
+      }
+
+      if (F_status_is_error_not(main->setting.state.status)) {
+        const f_range_t range = macro_f_range_t_initialize_2(main->cache.buffer.used);
+        f_number_unsigned_t i = 0;
+
+        for (; i < main->cache.memory.used; ++i) {
+
+          if (kt_remove_signal_check(main)) return;
+          if (main->cache.buffer.used > main->cache.memory.array[i].used) continue;
+
+          if (f_compare_dynamic_partial_dynamic(main->cache.buffer, main->cache.memory.array[i], range) == F_equal_to) break;
+        } // for
+
+        // Swap the first and the last paths and then remove the last path.
+        if (i < main->cache.memory.used) {
+          const f_string_static_t temporary = macro_f_string_dynamic_t_initialize_1(main->cache.memory.array[i].string, main->cache.memory.array[i].size, main->cache.memory.array[i].used);
+
+          main->cache.memory.array[i].string = main->cache.memory.array[main->cache.memory.used].string;
+          main->cache.memory.array[i].size = main->cache.memory.array[main->cache.memory.used].size;
+          main->cache.memory.array[i].used = main->cache.memory.array[main->cache.memory.used].used;
+
+          main->cache.memory.array[main->cache.memory.used].string = temporary.string;
+          main->cache.memory.array[main->cache.memory.used].size = temporary.size;
+          main->cache.memory.array[main->cache.memory.used--].used = 0;
+        }
+      }
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->cache.memory.array[main->cache.memory.used].used = 0;
+
+      if (flag_operate & kt_remove_flag_file_operate_directory_d) {
+        main->setting.state.status = f_memory_array_increase_by(path.used + f_path_separator_s.used, sizeof(f_char_t), (void **) &main->cache.memory.array[main->cache.memory.used].string, &main->cache.memory.array[main->cache.memory.used].used, &main->cache.memory.array[main->cache.memory.used].size);
+      }
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      main->setting.state.status = f_string_dynamic_append_nulless(path, &main->cache.memory.array[main->cache.memory.used]);
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      if (flag_operate & kt_remove_flag_file_operate_directory_d) {
+        main->setting.state.status = f_string_dynamic_append_nulless(f_path_separator_s, &main->cache.memory.array[main->cache.memory.used]);
+      }
+    }
+
+    if (F_status_is_error_not(main->setting.state.status)) {
+      ++main->cache.memory.used;
+      main->setting.state.status = F_okay;
+    }
   }
 #endif // _di_kt_remove_operate_memory_save_
 
index fd5712d46315fa7a14102710787f19480f1090db..d752f263531500d374ab91346cb3d181cfda3ccc 100644 (file)
@@ -196,7 +196,7 @@ extern "C" {
  *   Must not be NULL.
  *
  *   This alters main.setting.state.status:
- *     F_okay on success and the path is to be processed.
+ *     F_okay on success.
  *     F_data_not on success but path is an empty string.
  *
  *     Errors (with error bit) from: f_string_dynamic_append().