From: Kevin Day Date: Tue, 11 Jun 2024 00:12:18 +0000 (-0500) Subject: Bugfix: The fl_directory_create() needs to also handle F_file_found_not. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=aefd226cd136a0c5e64f52546ea24d470b5b22ce;p=fll Bugfix: The fl_directory_create() needs to also handle F_file_found_not. Creating an entire directory tree is not working as expected when creating non-existent directories that are two levels or greater deep. For example take "a/b/c", if "a" exists but neither "a/b" nor "a/b/c" then the create fails. For example take "a/b", if "a exists but not "a/b" then the create succeeds (or appears to because I never noticed the bug before). The ENOENT (aka: F_file_found_not) is sometimes returned rather than ENOTDIR (aka: F_false) from f_directory_exists(). Process the ENOENT F_file_found_not. I noticed some problems in the logic of the fl_directory_create() function as well. The memcpy() needs to start from the same offset as the source copy offset. Otherwise, the copy is overwriting the string. Make sure to place the NULL at the "at_path" rather at "at_path - at_tree". The initial assignment of "tree.used" is not necessary. --- diff --git a/level_1/fl_directory/c/directory.c b/level_1/fl_directory/c/directory.c index 87fd542..4816021 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -21,19 +21,19 @@ extern "C" { f_char_t tree_string[path.used + 1]; tree.string = tree_string; - tree.used = path.used; tree_string[path.used] = 0; for (; at_path < path.used; ++at_path) { if (at_path && path.string[at_path] == f_path_separator_s.string[0]) { - memcpy(tree.string, path.string + at_tree, sizeof(f_char_t) * (at_path - at_tree)); - tree.string[at_path - at_tree] = 0; + memcpy(tree.string + at_tree, path.string + at_tree, sizeof(f_char_t) * (at_path - at_tree)); + tree.string[at_path] = 0; + tree.used = at_path; status = f_directory_exists(tree); if (F_status_is_error(status)) return status; - if (status == F_false) { + if (status == F_false || status == F_file_found_not) { status = f_directory_create(tree, mode); if (F_status_is_error(status)) return status; }