From: Stefan Schantl Date: Sat, 23 Mar 2024 10:56:24 +0000 (+0100) Subject: installer: Add recurisve mkdir function X-Git-Tag: v2.29-core186~139 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e0a7cdd86f5ae425b76d73d9b39f51308d48d611;p=ipfire-2.x.git installer: Add recurisve mkdir function Signed-off-by: Stefan Schantl Signed-off-by: Arne Fitzenreiter --- diff --git a/src/installer/hw.c b/src/installer/hw.c index 8396d83cf6..3fa8b889e0 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -1281,6 +1281,49 @@ int hw_restore_backup(const char* output, const char* backup_path, const char* d return 0; } +int hw_mkdir(const char *dir) { + char tmp[STRING_SIZE]; + char *p = NULL; + size_t len; + int r; + + snprintf(tmp, sizeof(tmp),"%s",dir); + len = strlen(tmp); + + if (tmp[len - 1] == '/') { + tmp[len - 1] = 0; + } + + for (p = tmp + 1; *p; p++) { + if (*p == '/') { + *p = 0; + + // Create target if it does not exist + if (access(tmp, X_OK) != 0) { + r = mkdir(tmp, S_IRWXU|S_IRWXG|S_IRWXO); + + if (r) { + return r; + } + } + + *p = '/'; + } + } + + // Create target if it does not exist + if (access(tmp, X_OK) != 0) { + r = mkdir(tmp, S_IRWXU|S_IRWXG|S_IRWXO); + + if (r) { + return r; + } + } + + return 0; +} + + int hw_create_btrfs_subvolume(const char* output, const char* subvolume) { char command [STRING_SIZE]; int r;