Mercurial > gnulib
annotate lib/mkdir-p.c @ 40169:ecb43221748b
strtod, strtold: Work around HP-UX 11.31/ia64 bug.
* lib/strtod.c (STRTOD): When there is an extra character after the
exponent marker 'p', reparse the number.
* doc/posix-functions/strtod.texi: Document the HP-UX 11.31 bug.
* doc/posix-functions/strtold.texi: Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 01 Feb 2019 00:18:57 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
5907 | 1 /* mkdir-p.c -- Ensure that a directory and its parents exist. |
2 | |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
40025
diff
changeset
|
3 Copyright (C) 1990, 1997-2000, 2002-2007, 2009-2019 Free Software |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12518
diff
changeset
|
4 Foundation, Inc. |
5907 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8059
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
5907 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8059
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8059
diff
changeset
|
9 (at your option) any later version. |
5907 | 10 |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
19190 | 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
5907 | 18 |
6969 | 19 /* Written by Paul Eggert, David MacKenzie, and Jim Meyering. */ |
5907 | 20 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6969
diff
changeset
|
21 #include <config.h> |
5907 | 22 |
23 #include "mkdir-p.h" | |
24 | |
6969 | 25 #include <errno.h> |
5907 | 26 #include <sys/stat.h> |
7380
d12ab9dc1e7e
* mkdir-p.c: Include "dirchownmod.h", not "dirchownmod.c".
Jim Meyering <jim@meyering.net>
parents:
7312
diff
changeset
|
27 #include <unistd.h> |
5907 | 28 |
29 #include "gettext.h" | |
30 #define _(msgid) gettext (msgid) | |
31 | |
7380
d12ab9dc1e7e
* mkdir-p.c: Include "dirchownmod.h", not "dirchownmod.c".
Jim Meyering <jim@meyering.net>
parents:
7312
diff
changeset
|
32 #include "dirchownmod.h" |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
33 #include "dirname.h" |
5907 | 34 #include "error.h" |
35 #include "quote.h" | |
6969 | 36 #include "mkancesdirs.h" |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
37 #include "savewd.h" |
5907 | 38 |
7479
a21f992ed2b2
* lib/mkdir-p.c (HAVE_FCHMOD): Define to false if not already
Paul Eggert <eggert@cs.ucla.edu>
parents:
7418
diff
changeset
|
39 #ifndef HAVE_FCHMOD |
a21f992ed2b2
* lib/mkdir-p.c (HAVE_FCHMOD): Define to false if not already
Paul Eggert <eggert@cs.ucla.edu>
parents:
7418
diff
changeset
|
40 # define HAVE_FCHMOD false |
a21f992ed2b2
* lib/mkdir-p.c (HAVE_FCHMOD): Define to false if not already
Paul Eggert <eggert@cs.ucla.edu>
parents:
7418
diff
changeset
|
41 #endif |
a21f992ed2b2
* lib/mkdir-p.c (HAVE_FCHMOD): Define to false if not already
Paul Eggert <eggert@cs.ucla.edu>
parents:
7418
diff
changeset
|
42 |
6969 | 43 /* Ensure that the directory DIR exists. |
44 | |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
45 WD is the working directory, as in savewd.c. |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
46 |
6969 | 47 If MAKE_ANCESTOR is not null, create any ancestor directories that |
7418
77a75e20049c
* mkancesdirs.c (mkancesdirs): Pass to MAKE_DIR both the full file
Paul Eggert <eggert@cs.ucla.edu>
parents:
7380
diff
changeset
|
48 don't already exist, by invoking MAKE_ANCESTOR (DIR, ANCESTOR, OPTIONS). |
6969 | 49 This function should return zero if successful, -1 (setting errno) |
50 otherwise. In this case, DIR may be modified by storing '\0' bytes | |
51 into it, to access the ancestor directories, and this modification | |
52 is retained on return if the ancestor directories could not be | |
53 created. | |
54 | |
17387
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
55 Create DIR as a new directory, using mkdir with permissions MODE; |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
56 here, MODE is affected by the umask in the usual way. It is also |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
57 OK if MAKE_ANCESTOR is not null and a directory DIR already exists. |
6969 | 58 |
59 Call ANNOUNCE (DIR, OPTIONS) just after successfully making DIR, | |
60 even if some of the following actions fail. | |
5907 | 61 |
6969 | 62 Set DIR's owner to OWNER and group to GROUP, but leave the owner |
63 alone if OWNER is (uid_t) -1, and similarly for GROUP. | |
5907 | 64 |
6969 | 65 Set DIR's mode bits to MODE, except preserve any of the bits that |
66 correspond to zero bits in MODE_BITS. In other words, MODE_BITS is | |
67 a mask that specifies which of DIR's mode bits should be set or | |
17387
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
68 cleared. Changing the mode in this way is necessary if DIR already |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
69 existed, if MODE and MODE_BITS specify non-permissions bits like |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
70 S_ISUID, or if MODE and MODE_BITS specify permissions bits that are |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
71 masked out by the umask. MODE_BITS should be a subset of |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
72 CHMOD_MODE_BITS. |
6271
fdd622fe6d47
* mkdir-p.c (ENOSYS): Define to EEXIST if not defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
73 |
6969 | 74 However, if PRESERVE_EXISTING is true and DIR already exists, |
75 do not attempt to set DIR's ownership and file mode bits. | |
76 | |
77 Return true if DIR exists as a directory with the proper ownership | |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
78 and file mode bits when done, or if a child process has been |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
79 dispatched to do the real work (though the child process may not |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
80 have finished yet -- it is the caller's responsibility to handle |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
81 this). Report a diagnostic and return false on failure, storing |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
82 '\0' into *DIR if an ancestor directory had problems. */ |
5907 | 83 |
84 bool | |
6969 | 85 make_dir_parents (char *dir, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
86 struct savewd *wd, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
87 int (*make_ancestor) (char const *, char const *, void *), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
88 void *options, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
89 mode_t mode, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
90 void (*announce) (char const *, void *), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
91 mode_t mode_bits, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
92 uid_t owner, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
93 gid_t group, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
94 bool preserve_existing) |
5907 | 95 { |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
96 int mkdir_errno = (IS_ABSOLUTE_FILE_NAME (dir) ? 0 : savewd_errno (wd)); |
5907 | 97 |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
98 if (mkdir_errno == 0) |
6271
fdd622fe6d47
* mkdir-p.c (ENOSYS): Define to EEXIST if not defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
99 { |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
100 ptrdiff_t prefix_len = 0; |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
101 int savewd_chdir_options = (HAVE_FCHMOD ? SAVEWD_CHDIR_SKIP_READABLE : 0); |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
102 |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
103 if (make_ancestor) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
104 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
105 prefix_len = mkancesdirs (dir, wd, make_ancestor, options); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
106 if (prefix_len < 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
107 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
108 if (prefix_len < -1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
109 return true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
110 mkdir_errno = errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
111 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
112 } |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
113 |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
114 if (0 <= prefix_len) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
115 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
116 /* If the ownership might change, or if the directory will be |
16358 | 117 writable to other users and its special mode bits may |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
118 change after the directory is created, create it with |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
119 more restrictive permissions at first, so unauthorized |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
120 users cannot nip in before the directory is ready. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
121 bool keep_owner = owner == (uid_t) -1 && group == (gid_t) -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
122 bool keep_special_mode_bits = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
123 ((mode_bits & (S_ISUID | S_ISGID)) | (mode & S_ISVTX)) == 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
124 mode_t mkdir_mode = mode; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
125 if (! keep_owner) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
126 mkdir_mode &= ~ (S_IRWXG | S_IRWXO); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
127 else if (! keep_special_mode_bits) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
128 mkdir_mode &= ~ (S_IWGRP | S_IWOTH); |
7711
17e5da0fb096
* lib/mkdir-p.c (make_dir_parents): Fix race condition when making
Paul Eggert <eggert@cs.ucla.edu>
parents:
7581
diff
changeset
|
129 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
130 if (mkdir (dir + prefix_len, mkdir_mode) == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
131 { |
17387
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
132 /* True if the caller does not care about the umask's |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
133 effect on the permissions. */ |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
134 bool umask_must_be_ok = (mode & mode_bits & S_IRWXUGO) == 0; |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
135 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
136 announce (dir, options); |
17387
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
137 preserve_existing = (keep_owner & keep_special_mode_bits |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
138 & umask_must_be_ok); |
18104
76e10610d806
savewd: remove SAVEWD_CHDIR_READABLE
Paul Eggert <eggert@cs.ucla.edu>
parents:
17848
diff
changeset
|
139 savewd_chdir_options |= SAVEWD_CHDIR_NOFOLLOW; |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
140 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
141 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
142 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
143 mkdir_errno = errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
144 mkdir_mode = -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
145 } |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
146 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
147 if (preserve_existing) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
148 { |
40025
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
149 if (mkdir_errno == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
150 return true; |
40025
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
151 if (mkdir_errno != ENOENT && make_ancestor) |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
152 { |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
153 struct stat st; |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
154 if (stat (dir + prefix_len, &st) == 0) |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
155 { |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
156 if (S_ISDIR (st.st_mode)) |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
157 return true; |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
158 } |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
159 else if (mkdir_errno == EEXIST |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
160 && errno != ENOENT && errno != ENOTDIR) |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
161 { |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
162 error (0, errno, _("cannot stat %s"), quote (dir)); |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
163 return false; |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
164 } |
d80a47eca286
mkdir-p: improve diagnostic for FUSE mounts
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
165 } |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
166 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
167 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
168 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
169 int open_result[2]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
170 int chdir_result = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
171 savewd_chdir (wd, dir + prefix_len, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
172 savewd_chdir_options, open_result); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
173 if (chdir_result < -1) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
174 return true; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
175 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
176 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
177 bool chdir_ok = (chdir_result == 0); |
17387
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
178 char const *subdir = (chdir_ok ? "." : dir + prefix_len); |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
179 if (dirchownmod (open_result[0], subdir, mkdir_mode, |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
180 owner, group, mode, mode_bits) |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
181 == 0) |
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
182 return true; |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
183 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
184 if (mkdir_errno == 0 |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
185 || (mkdir_errno != ENOENT && make_ancestor |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
186 && errno != ENOTDIR)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
187 { |
17387
21bdea0c916e
mkdir-p: remove assumptions about umask and mode
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
188 error (0, errno, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
189 _(keep_owner |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
190 ? "cannot change permissions of %s" |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
191 : "cannot change owner and permissions of %s"), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
192 quote (dir)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
193 return false; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
194 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
195 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
196 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
197 } |
6969 | 198 } |
6271
fdd622fe6d47
* mkdir-p.c (ENOSYS): Define to EEXIST if not defined.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
199 |
7312
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
200 error (0, mkdir_errno, _("cannot create directory %s"), quote (dir)); |
796e1837ac66
* lib/dirchownmod.c: Don't include fcntl.h; no longer needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7302
diff
changeset
|
201 return false; |
5907 | 202 } |