]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
installer: Add recurisve mkdir function
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 26 Feb 2024 05:37:08 +0000 (06:37 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 26 Feb 2024 05:37:08 +0000 (06:37 +0100)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
src/installer/hw.c

index 205d40d21c5dcf56587aaa5492335d94eaa4da97..cb6a8ab8191251d6f4250e52b77bc1d35789ffae 100644 (file)
@@ -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);