]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
mkdir-p: ENOENT/ENOTDIR safety and consistency
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 22 Jul 2025 19:12:22 +0000 (12:12 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 22 Jul 2025 19:14:04 +0000 (12:14 -0700)
* lib/mkdir-p.c (make_dir_parents): If mkdir fails with ENOENT or
ENOTDIR, do not attempt anything else since the file does not exist.
Treat ENOENT and ENOTDIR consistently later, too.

ChangeLog
lib/mkdir-p.c

index 4841447b885fd4913a62258c208c30a6e68f6eec..ac20d475da80f22dfec4491cd208d575d525c814 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2025-07-22  Paul Eggert  <eggert@cs.ucla.edu>
 
+       mkdir-p: ENOENT/ENOTDIR safety and consistency
+       * lib/mkdir-p.c (make_dir_parents): If mkdir fails with ENOENT or
+       ENOTDIR, do not attempt anything else since the file does not exist.
+       Treat ENOENT and ENOTDIR consistently later, too.
+
        mkdir-p: better diagnostics
        Problem reported by Lauri Tirkkonen <https://bugs.gnu.org/79072>.
        * lib/mkdir-p.c (make_dir_parents):
index fffa58b4eb025d83d9e0427326d29bc949e074de..7b764f122dbd15362dd01dfcfbdf9aedf1f15371 100644 (file)
@@ -144,11 +144,13 @@ make_dir_parents (char *dir,
               mkdir_mode = -1;
             }
 
-          if (preserve_existing)
+          if (mkdir_errno == ENOENT || mkdir_errno == ENOTDIR)
+            ;
+          else if (preserve_existing)
             {
               if (mkdir_errno == 0)
                 return true;
-              if (mkdir_errno != ENOENT && make_ancestor)
+              if (make_ancestor)
                 {
                   struct stat st;
                   if (stat (dir + prefix_len, &st) == 0)
@@ -182,8 +184,7 @@ make_dir_parents (char *dir,
                     return true;
 
                   if (mkdir_errno == 0
-                      || (mkdir_errno != ENOENT && make_ancestor
-                          && errno != ENOTDIR))
+                      || (make_ancestor && errno != ENOENT && errno != ENOTDIR))
                     {
                       error (0, errno,
                              _(keep_owner