From ad99f4e84a5fea05edca59257b6e00d91d6c8a08 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 18 Sep 2012 09:39:38 +0300 Subject: [PATCH] Ensure directories have trailing slashes in doLookupId() - In the old days, stripping trailing slashes made sense as its useless as it is and stripping it saved a bit of memory, but now with the directories in the pool things are different: while not all paths we'll see here necessarily exist in the pool already, NONE of them exists without the trailing slash, so stripping it out wastes gobs of memory. Simplifies the code a bit and saves several megs of memory on larger transactions, what's not to like? --- lib/fprint.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/fprint.c b/lib/fprint.c index 6ae3048..687561c 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -140,14 +140,14 @@ static int doLookupId(fingerPrintCache cache, const char * dirName = rpmstrPoolStr(cache->pool, dirNameId); size_t cdnl = rpmstrPoolStrlen(cache->pool, dirNameId);; const char * cdn = NULL; /* cleaned directory path */ + const char *rootDir = "/"; if (*dirName == '/') { - char trailingslash = (dirName[cdnl-1] == '/'); cdnbuf = xstrdup(dirName); cdnbuf = rpmCleanPath(cdnbuf); - if (trailingslash) { + /* leave my trailing slashes along you b**** */ + if (cdnl > 1) cdnbuf = rstrcat(&cdnbuf, "/"); - } cdn = cdnbuf; cdnl = strlen(cdn); } else { @@ -183,15 +183,9 @@ static int doLookupId(fingerPrintCache cache, buf = xstrdup(cdn); end = buf + cdnl; - /* no need to pay attention to that extra little / at the end of dirName */ - if (buf[1] && end[-1] == '/') { - end--; - *end = '\0'; - } - while (1) { /* buf contents change through end ptr, requiring rehash on each loop */ - const char *fpDir = (*buf != '\0') ? buf : "/"; + const char *fpDir = (*buf != '\0') ? buf : rootDir; rpmsid fpId = rpmstrPoolId(cache->pool, fpDir, 1); /* as we're stating paths here, we want to follow symlinks */ @@ -224,14 +218,11 @@ static int doLookupId(fingerPrintCache cache, } /* stat of '/' just failed! */ - if (end == buf + 1) + if (fpDir == rootDir) abort(); end--; - while ((end > buf) && *end != '/') end--; - if (end == buf) /* back to stat'ing just '/' */ - end++; - + while ((end > buf) && *(end-1) != '/') end--; *end = '\0'; } -- 2.7.4