From: Paul Eggert Date: Tue, 22 Jul 2025 19:09:28 +0000 (-0700) Subject: mkdir-p: better diagnostics X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27db579667399d9f2cae2552a6f9185ffd10ab23;p=thirdparty%2Fgnulib.git mkdir-p: better diagnostics Problem reported by Lauri Tirkkonen . * 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. --- diff --git a/ChangeLog b/ChangeLog index 99ca126183..4841447b88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2025-07-22 Paul Eggert + + mkdir-p: better diagnostics + Problem reported by Lauri Tirkkonen . + * 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 sys_un-h: Make sure that the 'sys' subdirectory is created. diff --git a/lib/mkdir-p.c b/lib/mkdir-p.c index f5df9843e4..fffa58b4eb 100644 --- a/lib/mkdir-p.c +++ b/lib/mkdir-p.c @@ -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]); + } } } }