summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-10-13 19:05:13 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-10-13 19:05:13 +0000
commit2ec133706a86d25a9a15c274522fe5a79e9590d4 (patch)
treedc586b84a7f709e64dbaf3e815d9ff38df6edfdb /lib
parent71a4b4865c455131b94850c768d46ad93a4f11e3 (diff)
downloadcoreutils-2ec133706a86d25a9a15c274522fe5a79e9590d4.tar.xz
(make_dir_parents): Don't report an error if an
intermediate directory is in a read-only file system.
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog8
-rw-r--r--lib/mkdir-p.c47
2 files changed, 32 insertions, 23 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 2686a4c19..7c1b906a7 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-13 Paul Eggert <eggert@cs.ucla.edu>
+
+ * mkdir-p.c (make_dir_parents): Don't report an error if an
+ intermediate directory is in a read-only file system. Problem
+ reported by Eric Blake.
+
2005-10-08 Jim Meyering <jim@meyering.net>
* openat.c (rpl_openat): Use the promoted type (int), not mode_t,
@@ -5480,7 +5486,7 @@
* exclude.c (bool): Declare, perhaps by including stdbool.h.
(<sys/types.h>): Include only if HAVE_SYS_TYPES_H.
(<stdlib.h>, <string.h>, <strings.h>, <inttypes.h>, <stdint.h>):
- Include if available.
+ Include if available.
(<xalloc.h>): Include
(SIZE_MAX): Define if <stdint.h> or <inttypes.h> doesn't.
(verify): New macro. Use it to verify that EXCLUDE macros do not
diff --git a/lib/mkdir-p.c b/lib/mkdir-p.c
index b074c0aa7..7c3965f3e 100644
--- a/lib/mkdir-p.c
+++ b/lib/mkdir-p.c
@@ -45,10 +45,6 @@
#include "quote.h"
#include "stat-macros.h"
-#ifndef ENOSYS
-# define ENOSYS EEXIST
-#endif
-
#define WX_USR (S_IWUSR | S_IXUSR)
/* Ensure that the directory ARG exists.
@@ -175,6 +171,9 @@ make_dir_parents (char const *arg,
while (true)
{
+ bool dir_known_to_exist;
+ int mkdir_errno;
+
/* slash points to the leftmost unprocessed component of dir. */
basename_dir = slash;
@@ -188,7 +187,10 @@ make_dir_parents (char const *arg,
basename_dir = dir;
*slash = '\0';
- if (mkdir (basename_dir, tmp_mode) == 0)
+ dir_known_to_exist = (mkdir (basename_dir, tmp_mode) == 0);
+ mkdir_errno = errno;
+
+ if (dir_known_to_exist)
{
if (verbose_fmt_string)
error (0, 0, verbose_fmt_string, quote (dir));
@@ -215,29 +217,30 @@ make_dir_parents (char const *arg,
leading_dirs = new;
}
}
- else if (errno == EEXIST || errno == ENOSYS)
- {
- /* A file is already there. Perhaps it is a directory.
- If not, it will be diagnosed later.
-
- The ENOSYS is for Solaris 8 NFS clients, which can
- fail with errno == ENOSYS if mkdir is invoked on an
- NFS mount point. */
- }
- else
- {
- error (0, errno, _("cannot create directory %s"), quote (dir));
- retval = false;
- break;
- }
/* If we were able to save the initial working directory,
then we can use chdir to change into each directory before
creating an entry in that directory. This avoids making
mkdir process O(n^2) file name components. */
- if (do_chdir && chdir (basename_dir) < 0)
+ if (do_chdir)
+ {
+ if (chdir (basename_dir) == 0)
+ dir_known_to_exist = true;
+ else if (dir_known_to_exist)
+ {
+ error (0, errno, _("cannot chdir to directory %s"),
+ quote (dir));
+ retval = false;
+ break;
+ }
+ }
+ else if (!dir_known_to_exist)
+ dir_known_to_exist = (stat (basename_dir, &stats) == 0
+ && S_ISDIR (stats.st_mode));
+
+ if (!dir_known_to_exist)
{
- error (0, errno, _("cannot chdir to directory %s"),
+ error (0, mkdir_errno, _("cannot create directory %s"),
quote (dir));
retval = false;
break;