# HG changeset patch # User Jim Meyering # Date 925956634 0 # Node ID ce6300b5001400e0ac1c57ee98c60d8f19c2c223 # Parent 8139ee8d995b2b09f0cfc5b2256df7d97e28a851 (make_dir): When reporting a mkdir failure and the target cannot be `stat'ed, use the errno from the failed mkdir call, not the one from the stat call. Before this change, running `mkdir -p /no-dir/no-dir' as an unprivileged user would wrongly elicit `No such file or directory' instead of `Permission denied'. diff --git a/lib/makepath.c b/lib/makepath.c --- a/lib/makepath.c +++ b/lib/makepath.c @@ -162,6 +162,7 @@ if (!created_dir) { struct stat stats; + int saved_errno = errno; /* The mkdir and stat calls below may appear to be reversed. They are not. It is important to call mkdir first and then to @@ -173,7 +174,7 @@ if (stat (dir, &stats)) { - error (0, errno, _("cannot create directory `%s'"), dirpath); + error (0, saved_errno, _("cannot create directory `%s'"), dirpath); fail = 1; } else if (!S_ISDIR (stats.st_mode))