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.
This commit is contained in:
Michael Forney 2020-01-11 02:10:04 -08:00
parent f3d05ffd0a
commit 5c63ffad33

View File

@ -198,6 +198,12 @@ main(int argc, char *argv[])
if (mflag) if (mflag)
mode = parsemode(mflag, mode, 0); mode = parsemode(mflag, mode, 0);
if (dflag) {
for (; *argv; argc--, argv++)
make_dirs(*argv, 0);
return 0;
}
if (tflag) { if (tflag) {
argv = memmove(argv - 1, argv, argc * sizeof(*argv)); argv = memmove(argv - 1, argv, argc * sizeof(*argv));
argv[argc++] = tflag; argv[argc++] = tflag;
@ -213,24 +219,18 @@ main(int argc, char *argv[])
eprintf("%s: not a directory\n", argv[argc - 1]); eprintf("%s: not a directory\n", argv[argc - 1]);
} }
} }
if (stat(argv[argc - 1], &st) < 0) {
if (dflag) { if (errno != ENOENT)
for (; *argv; argc--, argv++) eprintf("stat %s:", argv[argc - 1]);
make_dirs(*argv, 0); if (tflag || Dflag || argc > 2) {
} else { if ((p = strrchr(argv[argc - 1], '/')) != NULL) {
if (stat(argv[argc - 1], &st) < 0) { *p = '\0';
if (errno != ENOENT) make_dirs(argv[argc - 1], 1);
eprintf("stat %s:", argv[argc - 1]); *p = '/';
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; return 0;
} }