summaryrefslogtreecommitdiff
path: root/Src/Modules/files.c
diff options
context:
space:
mode:
authorAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:18:04 +0200
committerAxel Beckert <abe@deuxchevaux.org>2022-04-11 00:18:04 +0200
commit31bcc5c263aea983e967426e2b94269e7605dcd4 (patch)
tree7b48ad9d7799afe09b7d7d8adc980bd5db935bdf /Src/Modules/files.c
parent5086b5356abcef8849dc8a09902b7c55f01db3c0 (diff)
parentb09f4483416c54c1782824633dfabaf2ec0265b6 (diff)
downloadzsh-31bcc5c263aea983e967426e2b94269e7605dcd4.tar.gz
zsh-31bcc5c263aea983e967426e2b94269e7605dcd4.zip
Update upstream source from tag 'upstream/5.8.1.2-test'
Update to upstream version '5.8.1.2-test' with Debian dir b380d582bf51cd93149e4dea28fffa1ad85db4f5
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;