commit 5c63ffad332bd23fe527a19a468aa679d10da55c
parent f3d05ffd0ac4226f9064be5c71606ab9b7d12d92
Author: Michael Forney <mforney@mforney.org>
Date: Sat, 11 Jan 2020 02:10:04 -0800
install: Fix -d with more than two directories
The `tflag || argc > 2` if-statement should only apply when not
creating directories (-d). Otherwise, if we are creating more than
two directories, we get an error if the last argument does not
already exist.
To fix this, move the -d case above and return early.
Diffstat:
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/xinstall.c b/xinstall.c
@@ -198,6 +198,12 @@ main(int argc, char *argv[])
if (mflag)
mode = parsemode(mflag, mode, 0);
+ if (dflag) {
+ for (; *argv; argc--, argv++)
+ make_dirs(*argv, 0);
+ return 0;
+ }
+
if (tflag) {
argv = memmove(argv - 1, argv, argc * sizeof(*argv));
argv[argc++] = tflag;
@@ -213,24 +219,18 @@ main(int argc, char *argv[])
eprintf("%s: not a directory\n", argv[argc - 1]);
}
}
-
- if (dflag) {
- for (; *argv; argc--, argv++)
- make_dirs(*argv, 0);
- } else {
- if (stat(argv[argc - 1], &st) < 0) {
- if (errno != ENOENT)
- eprintf("stat %s:", argv[argc - 1]);
- if (tflag || Dflag || argc > 2) {
- if ((p = strrchr(argv[argc - 1], '/')) != NULL) {
- *p = '\0';
- make_dirs(argv[argc - 1], 1);
- *p = '/';
- }
+ if (stat(argv[argc - 1], &st) < 0) {
+ if (errno != ENOENT)
+ eprintf("stat %s:", argv[argc - 1]);
+ if (tflag || Dflag || argc > 2) {
+ if ((p = strrchr(argv[argc - 1], '/')) != NULL) {
+ *p = '\0';
+ make_dirs(argv[argc - 1], 1);
+ *p = '/';
}
}
- enmasse(argc, argv, install);
}
+ enmasse(argc, argv, install);
return 0;
}