summaryrefslogtreecommitdiff
path: root/Src/Modules/files.c
diff options
context:
space:
mode:
authorAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:17:48 +0200
committerAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:17:48 +0200
commitb09f4483416c54c1782824633dfabaf2ec0265b6 (patch)
tree304bc82642862525ae680c7fbaa249663b10ad57 /Src/Modules/files.c
parent12eb3e5356f2fc3351eed58ef1cef1b8fb83b504 (diff)
parent6e55c920503071e917619b8cb1a188cd35d772db (diff)
downloadzsh-b09f4483416c54c1782824633dfabaf2ec0265b6.tar.gz
zsh-b09f4483416c54c1782824633dfabaf2ec0265b6.zip
New upstream version 5.8.1.2-test
Diffstat (limited to 'Src/Modules/files.c')
-rw-r--r--Src/Modules/files.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/Src/Modules/files.c b/Src/Modules/files.c
index 6d20e38a8..bf0e8f8a8 100644
--- a/Src/Modules/files.c
+++ b/Src/Modules/files.c
@@ -32,12 +32,6 @@
typedef int (*MoveFunc) _((char const *, char const *));
typedef int (*RecurseFunc) _((char *, char *, struct stat const *, void *));
-#ifndef STDC_HEADERS
-extern int link _((const char *, const char *));
-extern int symlink _((const char *, const char *));
-extern int rename _((const char *, const char *));
-#endif
-
struct recursivecmd;
#include "files.pro"
@@ -122,19 +116,29 @@ domkdir(char *nam, char *path, mode_t mode, int p)
{
int err;
mode_t oumask;
+ struct stat st;
+ int n = 8;
char const *rpath = unmeta(path);
- if(p) {
- struct stat st;
-
- if(!stat(rpath, &st) && S_ISDIR(st.st_mode))
+ while(n-- > 0) {
+ oumask = umask(0);
+ err = mkdir(rpath, mode) ? errno : 0;
+ umask(oumask);
+ if (!err)
return 0;
+ if(!p || err != EEXIST)
+ break;
+ if(stat(rpath, &st)) {
+ if(errno == ENOENT)
+ continue;
+ err = errno;
+ break;
+ }
+ if(S_ISDIR(st.st_mode))
+ return 0;
+ break;
}
- oumask = umask(0);
- err = mkdir(rpath, mode) ? errno : 0;
- umask(oumask);
- if(!err)
- return 0;
+
zwarnnam(nam, "cannot make directory `%s': %e", path, err);
return 1;
}
@@ -342,7 +346,13 @@ domove(char *nam, MoveFunc movefn, char *p, char *q, int flags)
unlink(qbuf);
}
if(movefn(pbuf, qbuf)) {
- zwarnnam(nam, "%s: %e", p, errno);
+ int ferrno = errno;
+ char *errfile = p;
+ if (ferrno == ENOENT && !lstat(pbuf, &st)) {
+ /* p *does* exist, so error is in q */
+ errfile = q;
+ }
+ zwarnnam(nam, "`%s': %e", errfile, ferrno);
zsfree(pbuf);
return 1;
}
@@ -642,7 +652,7 @@ chmod_dochmod(char *arg, char *rp, UNUSED(struct stat const *sp), void *magic)
/**/
static int
-bin_chmod(char *nam, char **args, Options ops, int func)
+bin_chmod(char *nam, char **args, Options ops, UNUSED(int func))
{
struct chmodmagic chm;
char *str = args[0], *ptr;