aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/paths.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-27 12:05:49 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-27 12:07:34 -0500
commit437be558a893ac70c030794df99a866e8ed01879 (patch)
tree63126858e06f14db9e23306d7d9d4c7e25f3f421 /src/stdlib/paths.c
parent35053e65b946264715aca2b348ee25313b55d2f6 (diff)
Add `recursive` arg to Path.create_directory()
Diffstat (limited to 'src/stdlib/paths.c')
-rw-r--r--src/stdlib/paths.c12
1 files changed, 10 insertions, 2 deletions
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) {