From: Kevin Day Date: Tue, 11 Jun 2024 00:05:21 +0000 (-0500) Subject: Bugfix: The fl_directory_create() needs to also handle F_file_found_not. X-Git-Tag: 0.6.11~45 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=f66a812055c38d5614afd4b93a0e7eb04afc3a8e;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 f1646a2..23cb7b2 100644 --- a/level_1/fl_directory/c/directory.c +++ b/level_1/fl_directory/c/directory.c @@ -26,19 +26,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; }