]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
mkdir-p: better diagnostics
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 22 Jul 2025 19:09:28 +0000 (12:09 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 22 Jul 2025 19:14:04 +0000 (12:14 -0700)
Problem reported by Lauri Tirkkonen <https://bugs.gnu.org/79072>.
* lib/mkdir-p.c (make_dir_parents):
If savewd_chdir fails due to anything other than EACCES, do
not attempt to preserve permissions; instead, fail with mkdir’s
errno if nonzero, and with savewd_chdir’s errno otherwise.

ChangeLog
lib/mkdir-p.c

index 99ca12618371343dd8d1f297c7e1115b7f5d8f38..4841447b885fd4913a62258c208c30a6e68f6eec 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2025-07-22  Paul Eggert  <eggert@cs.ucla.edu>
+
+       mkdir-p: better diagnostics
+       Problem reported by Lauri Tirkkonen <https://bugs.gnu.org/79072>.
+       * lib/mkdir-p.c (make_dir_parents):
+       If savewd_chdir fails due to anything other than EACCES, do
+       not attempt to preserve permissions; instead, fail with mkdir’s
+       errno if nonzero, and with savewd_chdir’s errno otherwise.
+
 2025-07-21  Collin Funk  <collin.funk1@gmail.com>
 
        sys_un-h: Make sure that the 'sys' subdirectory is created.
index f5df9843e406c56fa4294dcb7d103e3472ac1301..fffa58b4eb025d83d9e0427326d29bc949e074de 100644 (file)
@@ -172,7 +172,7 @@ make_dir_parents (char *dir,
                               savewd_chdir_options, open_result);
               if (chdir_result < -1)
                 return true;
-              else
+              else if (chdir_result == 0 || errno == EACCES)
                 {
                   bool chdir_ok = (chdir_result == 0);
                   char const *subdir = (chdir_ok ? "." : dir + prefix_len);
@@ -193,6 +193,13 @@ make_dir_parents (char *dir,
                       return false;
                     }
                 }
+              else
+                {
+                  if (mkdir_errno == 0)
+                    mkdir_errno = errno;
+                  if (0 <= open_result[0])
+                    close (open_result[0]);
+                }
             }
         }
     }