]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/commitdiff
installer: Add recurisve mkdir function
authorStefan Schantl <stefan.schantl@ipfire.org>
Sat, 23 Mar 2024 10:56:24 +0000 (11:56 +0100)
committerArne Fitzenreiter <arne_f@ipfire.org>
Tue, 26 Mar 2024 07:34:16 +0000 (07:34 +0000)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
src/installer/hw.c

index 8396d83cf62befc37d04a454dc64f6117d66641e..3fa8b889e03453fcbe2929320371ad6004be2d61 100644 (file)
@@ -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;