From 437be558a893ac70c030794df99a866e8ed01879 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 27 Nov 2025 12:05:49 -0500 Subject: Add `recursive` arg to Path.create_directory() --- src/stdlib/paths.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/stdlib/paths.c') diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 22effad7..6c99cf0b 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -468,11 +468,19 @@ void Path$remove(Path_t path, bool ignore_missing) { } public -void Path$create_directory(Path_t path, int permissions) { +void Path$create_directory(Path_t path, int permissions, bool recursive) { +retry: path = Path$expand_home(path); const char *c_path = Path$as_c_string(path); int status = mkdir(c_path, (mode_t)permissions); - if (status != 0 && errno != EEXIST) fail("Could not create directory: ", c_path, " (", strerror(errno), ")"); + if (status != 0) { + if (recursive && errno == ENOENT) { + Path$create_directory(Path$parent(path), permissions, recursive); + goto retry; + } else if (errno != EEXIST) { + fail("Could not create directory: ", c_path, " (", strerror(errno), ")"); + } + } } static List_t _filtered_children(Path_t path, bool include_hidden, mode_t filter) { -- cgit v1.2.3