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:
parent
f3d05ffd0a
commit
5c63ffad33
30
xinstall.c
30
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user