]> Kevux Git Server - fll/commitdiff
Feature: Add list support for directory recurse processing.
authorKevin Day <kevin@kevux.org>
Mon, 19 Jun 2023 19:42:19 +0000 (14:42 -0500)
committerKevin Day <kevin@kevux.org>
Mon, 19 Jun 2023 19:42:19 +0000 (14:42 -0500)
The fl_directory_do() now provides support for the callback to handle the directory list process.

level_0/f_directory/c/directory/common.h
level_0/f_directory/c/directory/type.h
level_1/fl_directory/c/private-directory.c

index 4a79b0edeebd0581423192abfed674bf267ee5e0..39ddce7f3842819f4a9eae31cfc03668ac1a63b7 100644 (file)
@@ -111,6 +111,7 @@ extern "C" {
  *   - after:       Perform this action after recursion befo a single directory path.
  *   - before:      Perform this action before recursion on a single directory path.
  *   - dereference: Dereference symbolic links rather than operating on the link itself.
+ *   - list:        Perform this action after directory listing is loaded.
  *   - top:         Operate on top-most directory, or for the callback parameter, designate that this is the top path.
  *
  *   For the actiona and handle callback parameter:
@@ -132,18 +133,19 @@ extern "C" {
     f_directory_recurse_do_flag_after_e       = 0x1,
     f_directory_recurse_do_flag_before_e      = 0x2,
     f_directory_recurse_do_flag_dereference_e = 0x4,
-    f_directory_recurse_do_flag_top_e         = 0x8,
+    f_directory_recurse_do_flag_list_e        = 0x8,
+    f_directory_recurse_do_flag_top_e         = 0x10,
 
     // For the action callback parameter.
-    f_directory_recurse_do_flag_block_e     = 0x10,
-    f_directory_recurse_do_flag_character_e = 0x20,
-    f_directory_recurse_do_flag_directory_e = 0x40,
-    f_directory_recurse_do_flag_fifo_e      = 0x80,
-    f_directory_recurse_do_flag_link_e      = 0x100,
-    f_directory_recurse_do_flag_path_e      = 0x200,
-    f_directory_recurse_do_flag_regular_e   = 0x400,
-    f_directory_recurse_do_flag_socket_e    = 0x800,
-    f_directory_recurse_do_flag_unknown_e   = 0x1000,
+    f_directory_recurse_do_flag_block_e     = 0x20,
+    f_directory_recurse_do_flag_character_e = 0x40,
+    f_directory_recurse_do_flag_directory_e = 0x80,
+    f_directory_recurse_do_flag_fifo_e      = 0x100,
+    f_directory_recurse_do_flag_link_e      = 0x200,
+    f_directory_recurse_do_flag_path_e      = 0x400,
+    f_directory_recurse_do_flag_regular_e   = 0x800,
+    f_directory_recurse_do_flag_socket_e    = 0x1000,
+    f_directory_recurse_do_flag_unknown_e   = 0x2000,
   }; // enum
 #endif // _di_f_directory_recurse_do_flag_e_
 
index 94af61e3e2b54d90690e93d7c28e7d8813ebc0f8..4eb516e854b145f4b882f2d1dc67cd59ffded660 100644 (file)
@@ -122,7 +122,7 @@ extern "C" {
  *   - F_done:                          Immedately return as success but do nothing else in this recursion.
  *
  * The action parameters are:
- *   - recurse: Must be of type f_directory_recurse_do_t and represents this data.
+ *   - recurse: Must be of type f_directory_recurse_do_t and represents this data. Must not be NULL.
  *   - name:    The name of the file or directory the action is being performed on (does not have the parent directory path) (may be empty at the top level).
  *   - flag:    A flag representing the particular action being performed.
  *
index 0e756ba6bb56ce1cb2129cc79fe3d3a9212b2119..335569b6dfe49e6c8f3f8eb2eb6ec79f6a936771 100644 (file)
@@ -31,7 +31,7 @@ extern "C" {
     recurse->state.status = private_fl_directory_list(recurse->path, 0, 0, recurse->flag & f_directory_recurse_do_flag_dereference_e, &recurse->listing);
 
     if (F_status_is_error(recurse->state.status)) {
-      private_inline_fl_directory_do_handle(recurse, f_string_empty_s, f_directory_recurse_do_flag_path_e);
+      private_inline_fl_directory_do_handle(recurse, f_string_empty_s, f_directory_recurse_do_flag_list_e | f_directory_recurse_do_flag_path_e);
 
       // Only the directory is to be freed because all others are preserved between recursions.
       if (F_status_is_error(recurse->state.status)) {
@@ -47,6 +47,19 @@ extern "C" {
 
     recurse->state.status = F_none;
 
+    if (recurse->flag & f_directory_recurse_do_flag_list_e) {
+      recurse->action((void *) recurse, recurse->path, f_directory_recurse_do_flag_list_e);
+
+      if (F_status_is_error(recurse->state.status)) {
+        private_inline_fl_directory_do_handle(recurse, recurse->path, f_directory_recurse_do_flag_list_e);
+        if (F_status_is_error(recurse->state.status)) return;
+      }
+
+      if (recurse->state.status != F_done && F_status_is_error_not(recurse->state.status)) {
+        recurse->state.status = F_none;
+      }
+    }
+
     f_number_unsigned_t i = 0;
     uint8_t j = 0;
     const f_number_unsigned_t used_original = recurse->path.used;
@@ -67,7 +80,7 @@ extern "C" {
       f_directory_recurse_do_flag_unknown_e,
     };
 
-    {
+    if (recurse->state.status != F_done && F_status_is_error_not(recurse->state.status)) {
       f_string_dynamics_t * const list[] = {
         &recurse->listing.block,
         &recurse->listing.character,