Split out hardlink checking from fsmTeardown()
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 18 Apr 2012 09:18:35 +0000 (12:18 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 18 Apr 2012 09:27:28 +0000 (12:27 +0300)
- Checking missing links is only relevant for install, lift the
  code to separate function and call from the install-case only.
- Freeing data while checking seems like a dubious "optimization"
  but to keep changes minimal, leaving that as it is now.

lib/fsm.c

index 2edd82e..006067d 100644 (file)
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -577,6 +577,35 @@ static hardLink_t freeHardLink(hardLink_t li)
     return NULL;
 }
 
+/* Check for hard links missing from payload, also freeing the data (eh?) */
+static int checkHardLinks(FSM_t fsm)
+{
+    int rc = 0;
+
+    while ((fsm->li = fsm->links) != NULL) {
+       fsm->links = fsm->li->next;
+       fsm->li->next = NULL;
+       if (fsm->li->linksLeft) {
+           for (nlink_t i = 0 ; i < fsm->li->linksLeft; i++) {
+               if (fsm->li->filex[i] < 0)
+                   continue;
+               rc = CPIOERR_MISSING_HARDLINK;
+               if (fsm->failedFile && *fsm->failedFile == NULL) {
+                   fsm->ix = fsm->li->filex[i];
+                   if (!fsmMapPath(fsm)) {
+                       /* Out-of-sync hardlinks handled as sub-state */
+                       *fsm->failedFile = fsm->path;
+                       fsm->path = NULL;
+                   }
+               }
+               break;
+           }
+       }
+       fsm->li = freeHardLink(fsm->li);
+    }
+    return rc;
+}
+
 static int fsmSetup(FSM_t fsm, fileStage goal,
                rpmts ts, rpmte te, rpmfi fi,
                char ** failedFile)
@@ -618,31 +647,6 @@ static int fsmTeardown(FSM_t fsm)
 {
     int rc = 0;
 
-    if (!rc) {
-        /* Check for hard links missing from payload. */
-        while ((fsm->li = fsm->links) != NULL) {
-            fsm->links = fsm->li->next;
-            fsm->li->next = NULL;
-            if (fsm->goal == FSM_PKGINSTALL && fsm->li->linksLeft) {
-                for (nlink_t i = 0 ; i < fsm->li->linksLeft; i++) {
-                    if (fsm->li->filex[i] < 0)
-                        continue;
-                    rc = CPIOERR_MISSING_HARDLINK;
-                    if (fsm->failedFile && *fsm->failedFile == NULL) {
-                        fsm->ix = fsm->li->filex[i];
-                        if (!fsmMapPath(fsm)) {
-                            /* Out-of-sync hardlinks handled as sub-state */
-                            *fsm->failedFile = fsm->path;
-                            fsm->path = NULL;
-                        }
-                    }
-                    break;
-                }
-            }
-            fsm->li = freeHardLink(fsm->li);
-        }
-    }
-
     fsm->buf = _free(fsm->buf);
     fsm->bufsize = 0;
 
@@ -1847,6 +1851,9 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfi fi, FD_t cfd,
         }
     }
 
+    if (!rc)
+       rc = checkHardLinks(fsm);
+
     /* No need to bother with close errors on read */
     rpmcpioFree(archive);
     fsmTeardown(fsm);