From df92175300a9e320136fc2fc4e3f7a9b1274635c Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 18 Apr 2012 12:18:35 +0300 Subject: [PATCH] Split out hardlink checking from fsmTeardown() - 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 | 57 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/fsm.c b/lib/fsm.c index 2edd82e..006067d 100644 --- 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); -- 2.7.4