]> pd.if.org Git - zpackage/commitdiff
fix chmod and chown ordering
authorNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 10:56:29 +0000 (10:56 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Mon, 3 Dec 2018 10:57:41 +0000 (10:57 +0000)
fix bug where metadata was not set for regular files

zpm-syncfs.c

index 9a50be1856c1aca9aa4c66f90ca02e174e878b5d..3c0eebb0ff84bc43175d528f13e08c79e0514ce6 100644 (file)
@@ -721,6 +721,17 @@ static int set_md(struct config *conf, struct nitem *item) {
                return success;
        }
 
+       if (conf->setuser && conf->setgroup) {
+               rv = lchown(item->dest, item->uid, item->gid);
+               if (rv == -1) {
+                       setsyserr(conf, "can't lchown %s", item->dest);
+                       return conf->errabort;
+               }
+       }
+
+       /* have to chmod after the chown, setuid bits may (and will)
+        * be cleared after a chown
+        */
        /* can't chmod a symlink */
        if (item->ftype != 'l') {
                rv = chmod(item->dest, item->mode);
@@ -731,13 +742,6 @@ static int set_md(struct config *conf, struct nitem *item) {
                }
        }
 
-       if (conf->setuser && conf->setgroup) {
-               rv = lchown(item->dest, item->uid, item->gid);
-               if (rv == -1) {
-                       setsyserr(conf, "can't lchown %s", item->dest);
-                       return conf->errabort;
-               }
-       }
 
        rv = utimensat(AT_FDCWD, item->dest, item->times, AT_SYMLINK_NOFOLLOW);
        if (rv == -1) {
@@ -814,16 +818,11 @@ static int install(struct config *conf, struct nitem *item, unsigned int flags)
                }
        }
 
-       if (item->ftype == 'r') {
-               rv = zpm_extract(source, item->hash, item->dest, item->mode);
-               if (rv == 0) {
-                       seterror(conf, "can't extract %s", item->dest);
-                       return failure;
-               }
-               return success;
-       }
-
+       errno = 0;
        switch (item->ftype) {
+               case 'r': rv = zpm_extract(source, item->hash, item->dest, item->mode);
+                         if (rv == 0) rv = -1;
+                         break;
                case 'd': rv = mkdir(item->dest, item->mode);
                          break;
                case 'l': rv = symlink(item->target, item->dest);
@@ -833,6 +832,17 @@ static int install(struct config *conf, struct nitem *item, unsigned int flags)
        }
 
        if (rv == -1) {
+               switch (item->ftype) {
+                       case 'r':
+                               seterror(conf, "can't extract %s", item->dest);
+                               break;
+                       case 'd':
+                               setsyserr(conf, "install mkdir(\"%s\") failed", item->dest);
+                               break;
+                       case 'l':
+                               setsyserr(conf, "install symlink(\"%s\") failed", item->dest);
+                               break;
+               }
                setsyserr(conf, "installing %s failed", item->dest);
                return failure;
        }