From: Kevin Day Date: Sun, 9 Mar 2025 22:03:20 +0000 (-0500) Subject: Bugfix: Ensure that fl_directory_do() depth 0 may still list directory contents. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=5828314cd05de720fbb644a4230b3d6ba68a2525;p=fll 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. --- 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);