]> Kevux Git Server - kevux-tools/commitdiff
Progress: Continue working on completing the remove program.
authorKevin Day <Kevin@kevux.org>
Tue, 21 Jan 2025 02:02:23 +0000 (20:02 -0600)
committerKevin Day <Kevin@kevux.org>
Tue, 21 Jan 2025 02:02:23 +0000 (20:02 -0600)
Add fl_path dependency to utilize fl_path_canonical().

Replace project specific array reallocations with FLL array reallocations.

Add missing directory parameter processing.

13 files changed:
data/build/remove/dependencies
data/build/remove/settings
sources/c/program/kevux/tools/remove/main/common.c
sources/c/program/kevux/tools/remove/main/common.h
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/common/type.c
sources/c/program/kevux/tools/remove/main/common/type.h
sources/c/program/kevux/tools/remove/main/convert.c
sources/c/program/kevux/tools/remove/main/operate.c
sources/c/program/kevux/tools/remove/main/print/simulate.c
sources/c/program/kevux/tools/remove/main/remove.c
sources/c/program/kevux/tools/remove/main/remove.h

index e8ee0867faa56cf2360a88f2d656423c0237d357..48d231b451d2c2ad6164d23fa0ee9af0e811e37a 100644 (file)
@@ -23,6 +23,7 @@ f_time
 
 fl_conversion
 fl_directory
+fl_path
 fl_print
 
 fll_error
index bbcbb26c15dc4d22a6e94520581d1c10bef429b6..d7c7ab2153e3634bac28a4583d25b6892f72c2eb 100644 (file)
@@ -38,7 +38,7 @@ build_language c
 
 build_libraries -lc
 build_libraries-individual -lfll_error -lfll_print -lfll_program
-build_libraries-individual -lfl_conversion -fl_directory -lfl_print
+build_libraries-individual -lfl_conversion -fl_directory -lfl_path -lfl_print
 build_libraries-individual -lf_account -lf_color -lf_compare -lf_console -lf_conversion -lf_directory -lf_file -lf_memory -lf_path -lf_pipe -lf_print -lf_rip -lf_signal -lf_string -lf_time -lf_type_array -lf_utf
 build_libraries-individual_thread -lf_thread
 build_libraries-level -lfll_2 -lfll_1 -lfll_0
index 82a4b9b10e7af47e5c96dfaec2c93eda7bd1e900..802ee47c1b03d4786d0c19377f8eb86ce3e8d4d0 100644 (file)
@@ -4,46 +4,6 @@
 extern "C" {
 #endif
 
-#ifndef _di_kt_remove_dates_resize_
-  f_status_t kt_remove_dates_resize(const f_number_unsigned_t length, kt_remove_dates_t * const dates) {
-
-    if (!dates) return F_status_set_error(F_parameter);
-
-    if (dates->used + length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
-
-    const f_status_t status = f_memory_resize(dates->size, length, sizeof(kt_remove_date_t), (void **) & dates->array);
-    if (F_status_is_error(status)) return status;
-
-    dates->size = length;
-
-    if (dates->used > dates->size) {
-      dates->used = length;
-    }
-
-    return F_okay;
-  }
-#endif // _di_kt_remove_dates_resize_
-
-#ifndef _di_kt_remove_modes_resize_
-  f_status_t kt_remove_modes_resize(const f_number_unsigned_t length, kt_remove_modes_t * const modes) {
-
-    if (!modes) return F_status_set_error(F_parameter);
-
-    if (modes->used + length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
-
-    const f_status_t status = f_memory_resize(modes->size, length, sizeof(kt_remove_mode_t), (void **) & modes->array);
-    if (F_status_is_error(status)) return status;
-
-    modes->size = length;
-
-    if (modes->used > modes->size) {
-      modes->used = length;
-    }
-
-    return F_okay;
-  }
-#endif // _di_kt_remove_modes_resize_
-
 #ifndef _di_kt_remove_setting_load_
   void kt_remove_setting_load(const f_console_arguments_t arguments, kt_remove_main_t * const main) {
 
@@ -209,6 +169,11 @@ extern "C" {
       }
     }
 
+    if (main->program.parameters.array[kt_remove_parameter_directory_e].result & f_console_result_found_e) {
+      main->setting.flag |= kt_remove_main_flag_directory_d;
+      main->setting.flag |= kt_remove_main_flag_option_used_d;
+    }
+
     if (main->program.parameters.array[kt_remove_parameter_force_e].result & f_console_result_found_e) {
       main->setting.flag |= kt_remove_main_flag_force_d;
     }
@@ -276,10 +241,10 @@ extern "C" {
           }
 
           if (dates[p]->used + total_locations > dates[p]->size) {
-            main->setting.state.status = kt_remove_dates_resize(dates[p]->size + (total_locations - dates[p]->size), dates[p]);
+            main->setting.state.status = f_memory_array_resize(dates[p]->size + (total_locations - dates[p]->size), sizeof(kt_remove_date_t), (void **) &dates[p]->array, &dates[p]->used, &dates[p]->size);
 
             if (F_status_is_error(main->setting.state.status)) {
-              kt_remove_print_error(&main->program.error, macro_kt_remove_f(kt_remove_dates_resize));
+              kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_memory_array_resize));
 
               return;
             }
@@ -518,10 +483,10 @@ extern "C" {
         }
 
         if (main->setting.modes.used + total_locations > main->setting.modes.size) {
-          main->setting.state.status = kt_remove_modes_resize(main->setting.modes.size + (total_locations - main->setting.modes.size), &main->setting.modes);
+          main->setting.state.status = f_memory_array_resize(main->setting.modes.size + (total_locations - main->setting.modes.size), sizeof(kt_remove_mode_t), (void **) &main->setting.modes.array, &main->setting.modes.used, &main->setting.modes.size);
 
           if (F_status_is_error(main->setting.state.status)) {
-            kt_remove_print_error(&main->program.error, macro_kt_remove_f(kt_remove_modes_resize));
+            kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_memory_array_resize));
 
             return;
           }
index e2f7ac9e7d31c0b5e677fc3a7ad126f71d884aa7..64ba7a6d504c3794a786b53c030a5d9afce6179f 100644 (file)
@@ -17,50 +17,6 @@ extern "C" {
 #endif
 
 /**
- * Resize a date array. @todo migrate this?
- *
- * @param length
- *   The new size to use.
- * @param dates
- *   The array to resize.
- *
- *   Must not be NULL.
- *
- * @return
- *   F_okay on success.
- *
- *   F_array_too_large (with error bit) if the combined array is too large.
- *   F_parameter (with error bit) if a parameter is invalid.
- *
- *   Errors (with error bit) from: f_memory_resize().
- */
-#ifndef _di_kt_remove_dates_resize_
-  extern f_status_t kt_remove_dates_resize(const f_number_unsigned_t length, kt_remove_dates_t * const dates);
-#endif // _di_kt_remove_dates_resize_
-
-/**
- * Resize a mode array. @todo migrate this?
- *
- * @param length
- *   The new size to use.
- * @param modes
- *   The array to resize.
- *
- *   Must not be NULL.
- *
- * @return
- *   F_okay on success.
- *
- *   F_array_too_large (with error bit) if the combined array is too large.
- *   F_parameter (with error bit) if a parameter is invalid.
- *
- *   Errors (with error bit) from: f_memory_resize().
- */
-#ifndef _di_kt_remove_modes_resize_
-  extern f_status_t kt_remove_modes_resize(const f_number_unsigned_t length, kt_remove_modes_t * const modes);
-#endif // _di_kt_remove_modes_resize_
-
-/**
  * Perform the standard program setting load process.
  *
  * This prints error messages as appropriate.
index 18038001e319b3df5239adfadbf1e9720daf0db7..9174dccde9b4536b103029ad2048033d3e4d62ec 100644 (file)
@@ -18,15 +18,14 @@ extern "C" {
     "f_utf_is_whitespace",
     "fl_conversion_dynamic_partial_to_unsigned_detect",
     "fl_conversion_dynamic_to_unsigned_detect",
+    "fl_path_canonical",
     "fll_program_parameter_process_context",
     "fll_program_parameter_process_empty",
     "fll_program_parameter_process_verbosity",
     "kt_remove_convert_date_relative",
     "kt_remove_convert_timezone",
-    "kt_remove_dates_resize",
     "kt_remove_get_id_group",
     "kt_remove_get_id_user",
-    "kt_remove_modes_resize",
   };
 #endif // _di_kt_remove_f_a_
 
index 40cf000d7e6b4bfcc113b9bf31ac2a1d58a0f3d8..c7a7296cb388139047f6b3eb666846918a5372bd 100644 (file)
@@ -51,6 +51,7 @@ extern "C" {
     kt_remove_f_f_utf_is_whitespace_e,
     kt_remove_f_fl_conversion_dynamic_partial_to_unsigned_detect_e,
     kt_remove_f_fl_conversion_dynamic_to_unsigned_detect_e,
+    kt_remove_f_fl_path_canonical_e,
     kt_remove_f_fll_program_parameter_process_context_e,
     kt_remove_f_fll_program_parameter_process_empty_e,
     kt_remove_f_fll_program_parameter_process_verbosity_e,
index 0f7e09dddd6590336b138c29e86203b35748bb35..5639d403a3e896f1988894b444e8aed4c5339f57 100644 (file)
@@ -4,35 +4,45 @@
 extern "C" {
 #endif
 
+
+#ifndef _di_kt_remove_cache_delete_
+  void kt_remove_cache_delete(kt_remove_cache_t * const cache) {
+
+    if (!cache) return;
+
+    f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size);
+    f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->file.string, &cache->file.used, &cache->file.size);
+  }
+#endif // _di_kt_remove_cache_delete_
+
 #ifndef _di_kt_remove_main_delete_
   void kt_remove_main_delete(kt_remove_main_t * const main) {
 
     if (!main) return;
 
     fll_program_data_delete(&main->program);
+
+    kt_remove_cache_delete(&main->cache);
     kt_remove_setting_delete(&main->setting);
   }
 #endif // _di_kt_remove_main_delete_
 
 #ifndef _di_kt_remove_setting_delete_
-  f_status_t kt_remove_setting_delete(kt_remove_setting_t * const setting) {
+  void kt_remove_setting_delete(kt_remove_setting_t * const setting) {
 
-    if (!setting) return F_status_set_error(F_parameter);
+    if (!setting) return;
 
-    f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->buffer.string, &setting->buffer.used, &setting->buffer.size);
     f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &setting->files.array, &setting->files.used, &setting->files.size, &f_string_dynamics_delete_callback);
 
-    kt_remove_dates_resize(0, &setting->accessed);
-    kt_remove_dates_resize(0, &setting->changed);
-    kt_remove_dates_resize(0, &setting->updated);
-    kt_remove_modes_resize(0, &setting->modes);
+    f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->accessed.array, &setting->accessed.used, &setting->accessed.size);
+    f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->changed.array, &setting->changed.used, &setting->changed.size);
+    f_memory_array_resize(0, sizeof(kt_remove_date_t), (void **) &setting->updated.array, &setting->updated.used, &setting->updated.size);
+    f_memory_array_resize(0, sizeof(kt_remove_mode_t), (void **) &setting->modes.array, &setting->modes.used, &setting->modes.size);
 
     f_memory_array_resize(0, sizeof(uint32_t), (void **) &setting->groups.array, &setting->groups.used, &setting->groups.size);
     f_memory_array_resize(0, sizeof(uint32_t), (void **) &setting->users.array, &setting->users.used, &setting->users.size);
 
     f_directory_recurse_do_delete(&setting->recurse);
-
-    return F_okay;
   }
 #endif // _di_kt_remove_setting_delete_
 
index a7ddb124b7a638de83dcd3b574edad0c550d11ec..4d0ca342422f3b49fee5aa67606671641933d7e3 100644 (file)
@@ -138,6 +138,25 @@ extern "C" {
 #endif // _di_kt_remove_modes_t_
 
 /**
+ * The program cache.
+ *
+ * buffer: The generic buffer.
+ * file:   The current file being processed (generally canonicalized).
+ */
+#ifndef _di_kt_remove_cache_t_
+  typedef struct {
+    f_string_dynamic_t buffer;
+    f_string_dynamic_t file;
+  } kt_remove_cache_t;
+
+  #define kt_remove_cache_t_initialize \
+    { \
+      f_string_dynamic_t_initialize, \
+      f_string_dynamic_t_initialize, \
+    }
+#endif // _di_kt_remove_cache_t_
+
+/**
  * The main program settings.
  *
  * This is passed to the program-specific main entry point to designate program settings.
@@ -151,7 +170,6 @@ extern "C" {
  * program_name:      The short name of the program.
  * program_name_long: The human friendly name of the program.
  *
- * buffer: A string buffer used for caching purposes.
  * files:  An array of file names (full paths to the files) to remove.
  *
  * accessed: An array of last accessed dates used for comparison.
@@ -173,7 +191,6 @@ extern "C" {
     f_status_t status_thread;
     f_state_t state;
 
-    f_string_dynamic_t buffer;
     f_string_dynamics_t files;
 
     kt_remove_dates_t accessed;
@@ -199,7 +216,6 @@ extern "C" {
       kt_remove_main_flag_none_d, \
       F_okay, \
       macro_f_state_t_initialize_1(kt_remove_allocation_large_d, kt_remove_allocation_small_d, F_okay, 0, 0, &fll_program_standard_signal_handle, 0, 0, 0, 0), \
-      f_string_dynamic_t_initialize, \
       f_string_dynamics_t_initialize, \
       kt_remove_dates_t_initialize, \
       kt_remove_dates_t_initialize, \
@@ -227,16 +243,30 @@ extern "C" {
   struct kt_remove_main_t_ {
     fll_program_data_t program;
     kt_remove_setting_t setting;
+    kt_remove_cache_t cache;
   };
 
   #define kt_remove_main_t_initialize \
     { \
       fll_program_data_t_initialize, \
       kt_remove_setting_t_initialize, \
+      kt_remove_cache_t_initialize, \
     }
 #endif // _di_kt_remove_main_t_
 
 /**
+ * Delete the program main setting data.
+ *
+ * @param cache
+ *   The program main cache data.
+ *
+ *   This does not alter setting.state.status.
+ */
+#ifndef _di_kt_remove_cache_delete_
+  extern void kt_remove_cache_delete(kt_remove_cache_t * const cache);
+#endif // _di_kt_remove_cache_delete_
+
+/**
  * Deallocate main program data.
  *
  * @param setting_make
@@ -255,14 +285,9 @@ extern "C" {
  *   The program main setting data.
  *
  *   This does not alter setting.state.status.
- *
- * @return
- *   F_okay on success.
- *
- *   F_parameter (with error bit) if a parameter is invalid.
  */
 #ifndef _di_kt_remove_setting_delete_
-  extern f_status_t kt_remove_setting_delete(kt_remove_setting_t * const setting);
+  extern void kt_remove_setting_delete(kt_remove_setting_t * const setting);
 #endif // _di_kt_remove_setting_delete_
 
 #ifdef __cplusplus
index 64d1c42e6bbeff858fc9fb09d79d005bc1d5a2e5..51cf74b39d617be4308875dd753a3d06f70a840c 100644 (file)
@@ -436,14 +436,14 @@ extern "C" {
 
     if (F_status_is_error(main->setting.state.status)) {
       if (F_status_set_fine(main->setting.state.status) == F_number) {
-        main->setting.buffer.used = 0;
+        main->cache.buffer.used = 0;
 
-        main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->setting.buffer);
+        main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->cache.buffer);
         if (F_status_is_error(main->setting.state.status)) return 0;
 
         gid_t gid = 0;
 
-        main->setting.state.status = f_account_group_id_by_name(main->setting.buffer, &gid);
+        main->setting.state.status = f_account_group_id_by_name(main->cache.buffer, &gid);
         if (F_status_is_error(main->setting.state.status)) return 0;
 
         if (main->setting.state.status == F_exist_not) {
@@ -483,14 +483,14 @@ extern "C" {
 
     if (F_status_is_error(main->setting.state.status)) {
       if (F_status_set_fine(main->setting.state.status) == F_number) {
-        main->setting.buffer.used = 0;
+        main->cache.buffer.used = 0;
 
-        main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->setting.buffer);
+        main->setting.state.status = f_rip_dynamic_nulless(buffer, &main->cache.buffer);
         if (F_status_is_error(main->setting.state.status)) return 0;
 
         uid_t uid = 0;
 
-        main->setting.state.status = f_account_id_by_name(main->setting.buffer, &uid);
+        main->setting.state.status = f_account_id_by_name(main->cache.buffer, &uid);
         if (F_status_is_error(main->setting.state.status)) return 0;
 
         if (main->setting.state.status == F_exist_not) {
index 0755455086ed3122909b2d3ff0da540153490729..76742e23428a75b7a4604b3ed8ca63995226126a 100644 (file)
@@ -449,9 +449,9 @@ extern "C" {
 
     // @todo consider providing a "follow deep" parameter for recursively following until a non-link is reached.
     if (flag & kt_remove_flag_file_operate_follow_d) {
-      main->setting.buffer.used = 0;
+      main->cache.buffer.used = 0;
 
-      main->setting.state.status = f_file_link_read(path, F_false, &main->setting.buffer);
+      main->setting.state.status = f_file_link_read(path, F_false, &main->cache.buffer);
 
       if (F_status_is_error(main->setting.state.status)) {
         kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), path, f_file_operation_stat_s, fll_error_file_type_link_e);
@@ -459,10 +459,10 @@ extern "C" {
         return;
       }
 
-      main->setting.state.status = f_file_remove(main->setting.buffer);
+      main->setting.state.status = f_file_remove(main->cache.buffer);
 
       if (F_status_is_error(main->setting.state.status)) {
-        kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), main->setting.buffer, f_file_operation_delete_s, fll_error_file_type_file_e);
+        kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(f_file_remove), main->cache.buffer, f_file_operation_delete_s, fll_error_file_type_file_e);
 
         return;
       }
index 112b5c53cdc9912d5fc05e7e7d20f00e73d73eac..19e6913d2939af1545e99ded13ccd62056a6ce7f 100644 (file)
@@ -67,9 +67,9 @@ extern "C" {
     }
 
     if (status == F_true) {
-      main->setting.buffer.used = 0;
+      main->cache.buffer.used = 0;
 
-      status = f_file_link_read(path, F_false, &main->setting.buffer);
+      status = f_file_link_read(path, F_false, &main->cache.buffer);
 
       if (F_status_is_error(status)) {
         fl_print_format("  link_read_failure %ui%r", main->program.output.to, F_status_set_fine(status), f_string_eol_s);
@@ -80,7 +80,7 @@ extern "C" {
       f_file_stream_lock(main->program.output.to);
 
       fl_print_format("  follow %r%r", main->program.output.to, (main->setting.flag & kt_remove_main_flag_follow_d) ? kt_remove_yes_s : kt_remove_no_s, f_string_eol_s);
-      fl_print_format("  to '%Q'%r", main->program.output.to, main->setting.buffer, f_string_eol_s);
+      fl_print_format("  to '%Q'%r", main->program.output.to, main->cache.buffer, f_string_eol_s);
 
       f_file_stream_unlock(main->program.output.to);
     }
index 97e98725a378caedfb57de66616cc14558dfdd8c..0be2b55f09fe198bfb7002c22fffe614a4cb2819 100644 (file)
@@ -59,7 +59,17 @@ extern "C" {
 
     for (f_number_unsigned_t i = 0; i < main->setting.files.used; ++i) {
 
-      kt_remove_operate_file(main, main->setting.files.array[i]);
+      main->cache.file.used = 0;
+
+      fl_path_canonical(main->setting.files.array[i], &main->cache.file);
+
+      if (F_status_is_error(main->setting.state.status)) {
+        kt_remove_print_error_file(&main->program.error, macro_kt_remove_f(fl_path_canonical), main->setting.files.array[i], f_file_operation_process_s, fll_error_file_type_path_e);
+
+        break;
+      }
+
+      kt_remove_operate_file(main, main->cache.file);
 
       if ((main->setting.flag & kt_remove_main_flag_simulate_d) && i + 1 < main->setting.files.used && (F_status_is_error_not(main->setting.state.status) || F_status_set_fine(main->setting.state.status) == F_interrupt)) {
         f_print_dynamic(f_string_eol_s, main->program.output.to);
index 736ceabc70a41e9e579ce1a7b9569132d8f433d3..c2da2344c1ae645fb7e45042db38fffbf859a302 100644 (file)
@@ -41,6 +41,7 @@
 // FLL-1 includes.
 #include <fll/level_1/conversion.h>
 #include <fll/level_1/directory.h>
+#include <fll/level_1/path.h>
 #include <fll/level_1/print.h>
 
 // FLL-2 includes.