]> git.ipfire.org Git - pakfire.git/commitdiff
util: Repair pakfire_mkparentdir
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 14:37:45 +0000 (14:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 13 Mar 2021 14:37:45 +0000 (14:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c

index a445b57c4d4ee0d9f7953eec702f9aa28f2a4e3e..6549241a827dbe8f67f7b57dd9ebdd6e13070c8f 100644 (file)
@@ -507,21 +507,21 @@ static int pakfire_mkparentdir(const char* path) {
                return 1;
 
        // We have arrived at the top of the tree
-       if (*dirname == '.' || *dirname == '/')
+       if (*dirname == '.' || strcmp(dirname, "/") == 0)
                return 0;
 
        // Ensure the parent directory exists
        r = pakfire_mkparentdir(dirname);
-       if (r) {
-               if (errno == EEXIST)
-                       r = 0;
-
+       if (r)
                goto END;
-       }
 
        // Create this directory
        r = mkdir(dirname, 0);
 
+       // Ignore when the directory already exists
+       if (r && errno == EEXIST)
+               r = 0;
+
 END:
        free(dirname);
 
@@ -529,7 +529,9 @@ END:
 }
 
 FILE* pakfire_mktemp(char* path) {
-       pakfire_mkparentdir(path);
+       int r = pakfire_mkparentdir(path);
+       if (r)
+               return NULL;
 
        // Create a temporary result file
        int fd = mkostemp(path, O_CLOEXEC);