]> Kevux Git Server - fll/commitdiff
Bugfix: Ensure that fl_directory_do() depth 0 may still list directory contents.
authorKevin Day <Kevin@kevux.org>
Sun, 9 Mar 2025 22:03:20 +0000 (17:03 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 9 Mar 2025 22:24:10 +0000 (17:24 -0500)
The caller may want to check if there are any files within the directory when the max depth is 0.
Load the directory listing if the list flag is passed even when max depth is 0.

level_1/fl_directory/c/directory.c

index 521689f..10b182b 100644 (file)
@@ -147,6 +147,41 @@ extern "C" {
         if (F_status_is_error(recurse->state.status)) return;
       }
 
+      if (recurse->flag & f_directory_recurse_do_flag_list_e) {
+        recurse->state.status = F_okay;
+
+        recurse->listing.block.used = 0;
+        recurse->listing.character.used = 0;
+        recurse->listing.directory.used = 0;
+        recurse->listing.regular.used = 0;
+        recurse->listing.link.used = 0;
+        recurse->listing.fifo.used = 0;
+        recurse->listing.socket.used = 0;
+        recurse->listing.unknown.used = 0;
+
+        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_top_e | f_directory_recurse_do_flag_list_e | f_directory_recurse_do_flag_path_e);
+
+          if (F_status_is_error(recurse->state.status)) return;
+        }
+
+        recurse->action(recurse, path, f_directory_recurse_do_flag_top_e | f_directory_recurse_do_flag_list_e);
+
+        if (F_status_is_error(recurse->state.status)) {
+          private_inline_fl_directory_do_handle(recurse, path, f_directory_recurse_do_flag_top_e | f_directory_recurse_do_flag_list_e);
+
+          if (F_status_is_error(recurse->state.status)) return;
+        }
+
+        if (recurse->state.status == F_done) {
+          recurse->state.status = F_okay;
+
+          return;
+        }
+      }
+
       recurse->state.status = F_okay;
 
       recurse->action(recurse, path, f_directory_recurse_do_flag_top_e | f_directory_recurse_do_flag_directory_e);