From: Stefan Schantl Date: Mon, 26 Feb 2024 05:37:08 +0000 (+0100) Subject: installer: Add recurisve mkdir function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=97418ff315dc6ff0ba58309f50e245c0f422c3be;p=people%2Fstevee%2Fipfire-2.x.git installer: Add recurisve mkdir function Signed-off-by: Stefan Schantl --- diff --git a/src/installer/hw.c b/src/installer/hw.c index 205d40d21..cb6a8ab81 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -1274,6 +1274,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]; snprintf(command, sizeof(command), "/usr/bin/btrfs subvolume create %s/%s", DESTINATION_MOUNT_PATH, subvolume);