From 5828314cd05de720fbb644a4230b3d6ba68a2525 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 9 Mar 2025 17:03:20 -0500 Subject: [PATCH] Bugfix: Ensure that fl_directory_do() depth 0 may still list directory contents. 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 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index 521689f..10b182b 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -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); -- 1.8.3.1