[hackers] [sbase] install: Fix -d with more than two directories || Michael Forney

From: <git_AT_suckless.org>
Date: Sat, 11 Jan 2020 11:22:03 +0100 (CET)

commit 5c63ffad332bd23fe527a19a468aa679d10da55c
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sat Jan 11 02:10:04 2020 -0800
Commit: Michael Forney <mforney_AT_mforney.org>
CommitDate: Sat Jan 11 02:19:26 2020 -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.

diff --git a/xinstall.c b/xinstall.c
index 93ce842..fe55396 100644
--- a/xinstall.c
+++ b/xinstall.c
_AT_@ -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;
_AT_@ -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;
 }
Received on Sat Jan 11 2020 - 11:22:03 CET

This archive was generated by hypermail 2.3.0 : Sat Jan 11 2020 - 11:24:24 CET