Skip to content

Commit

Permalink
replace path building with TDNFAllocateStringPrintf() with TDNFJoin()
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed Nov 29, 2021
1 parent 0810428 commit 8e586f5
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 162 deletions.
41 changes: 23 additions & 18 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ TDNFCheckLocalPackages(
{
continue;
}
dwError = TDNFAllocateStringPrintf(
dwError = TDNFJoinPath(
&pszRPMPath,
"%s/%s",
pszLocalPath,
pEnt->d_name);
pEnt->d_name,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwPkgAdded = repo_add_rpm(
Expand Down Expand Up @@ -660,9 +660,10 @@ TDNFOpenHandle(
{
int nIsDir = 0;

dwError = TDNFAllocateStringPrintf(&pszCacheDir, "%s/%s",
pTdnf->pArgs->pszInstallRoot,
pTdnf->pConf->pszCacheDir);
dwError = TDNFJoinPath(&pszCacheDir,
pTdnf->pArgs->pszInstallRoot,
pTdnf->pConf->pszCacheDir,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

TDNF_SAFE_FREE_MEMORY(pTdnf->pConf->pszCacheDir);
Expand All @@ -671,9 +672,10 @@ TDNFOpenHandle(

if (!nHasOptReposdir)
{
dwError = TDNFAllocateStringPrintf(&pszRepoDir, "%s/%s",
pTdnf->pArgs->pszInstallRoot,
pTdnf->pConf->pszRepoDir);
dwError = TDNFJoinPath(&pszRepoDir,
pTdnf->pArgs->pszInstallRoot,
pTdnf->pConf->pszRepoDir,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFIsDir(pszRepoDir, &nIsDir);
Expand Down Expand Up @@ -1171,9 +1173,10 @@ TDNFRepoSync(
{
if (!pReposyncArgs->nNoRepoPath)
{
dwError = TDNFAllocateStringPrintf(&pszDir, "%s/%s",
strcmp(pszRootPath, "/") ? pszRootPath : "",
pPkgInfo->pszRepoName);
dwError = TDNFJoinPath(&pszDir,
strcmp(pszRootPath, "/") ? pszRootPath : "",
pPkgInfo->pszRepoName,
NULL);
BAIL_ON_TDNF_ERROR(dwError);
}
else
Expand Down Expand Up @@ -1257,9 +1260,10 @@ TDNFRepoSync(
}

/* no need to check nNoRepoPath since we wouldn't get here */
dwError = TDNFAllocateStringPrintf(&pszRepoDir, "%s/%s",
strcmp(pszRootPath, "/") ? pszRootPath : "",
pRepo->pszId);
dwError = TDNFJoinPath(&pszRepoDir,
strcmp(pszRootPath, "/") ? pszRootPath : "",
pRepo->pszId,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

ret = nftw(pszRepoDir, _rm_rpms, 10, FTW_DEPTH|FTW_PHYS);
Expand Down Expand Up @@ -1291,9 +1295,10 @@ TDNFRepoSync(
const char *pszBasePath = pReposyncArgs->pszMetaDataPath ?
pReposyncArgs->pszMetaDataPath : pszRootPath;

dwError = TDNFAllocateStringPrintf(&pszRepoDir, "%s/%s",
strcmp(pszBasePath, "/") ? pszBasePath : "",
pRepo->pszId);
dwError = TDNFJoinPath(&pszRepoDir,
strcmp(pszBasePath, "/") ? pszBasePath : "",
pRepo->pszId,
NULL);
BAIL_ON_TDNF_ERROR(dwError);
}
else
Expand Down
5 changes: 3 additions & 2 deletions client/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ TDNFReadConfig(
dwError = TDNFAllocateString(pszConfFile, &pszConfFileCopy);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFAllocateStringPrintf(&pszMinVersionsDir, "%s/minversions.d", dirname(pszConfFileCopy));
dwError = TDNFJoinPath(&pszMinVersionsDir, dirname(pszConfFileCopy), "minversions.d", NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFReadMinVersionsFiles(pszMinVersionsDir, &pConf->ppszMinVersions);
Expand Down Expand Up @@ -519,7 +519,8 @@ TDNFReadMinVersionsFiles(
{
continue;
}
dwError = TDNFAllocateStringPrintf(&pszFile, "%s/%s", pszDir, pEnt->d_name);
dwError = TDNFAllocateStringPrintf(&pszFile, pszDir, pEnt->d_name);
dwError = TDNFJoinPath(&pszFile, pszDir, pEnt->d_name, NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFReadFileToStringArray(pszFile, &pppszArrayList[i]);
Expand Down
15 changes: 8 additions & 7 deletions client/gpgcheck.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2021 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -580,22 +580,23 @@ TDNFFetchRemoteGPGKey(
}
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFAllocateStringPrintf(
dwError = TDNFJoinPath(
&pszTopKeyCacheDir,
"%s/%s/keys",
pTdnf->pConf->pszCacheDir,
pszRepoName);
pszRepoName,
"keys",
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFNormalizePath(pszTopKeyCacheDir,
&pszRealTopKeyCacheDir);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFAllocateStringPrintf(
dwError = TDNFJoinPath(
&pszFilePath,
"%s/%s",
pszRealTopKeyCacheDir,
pszKeyLocation);
pszKeyLocation,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFNormalizePath(
Expand Down
15 changes: 8 additions & 7 deletions client/init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 VMware, Inc. All Rights Reserved.
* Copyright (C) 2015-2021 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -75,9 +75,10 @@ TDNFCloneCmdArgs(
int nExists = 0;

/* prepend installroot to tdnf.conf location */
dwError = TDNFAllocateStringPrintf(&pszConfFileInstallRoot, "%s/%s",
pCmdArgsIn->pszInstallRoot,
TDNF_CONF_FILE);
dwError = TDNFJoinPath(&pszConfFileInstallRoot,
pCmdArgsIn->pszInstallRoot,
TDNF_CONF_FILE,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFIsFileOrSymlink(pszConfFileInstallRoot, &nExists);
Expand Down Expand Up @@ -290,11 +291,11 @@ TDNFRefreshSack(
//Check if expired since last sync per metadata_expire
if(pRepo->lMetadataExpire >= 0)
{
dwError = TDNFAllocateStringPrintf(
dwError = TDNFJoinPath(
&pszRepoCacheDir,
"%s/%s",
pTdnf->pConf->pszCacheDir,
pRepo->pszId);
pRepo->pszId,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFShouldSyncMetadata(
Expand Down
8 changes: 4 additions & 4 deletions client/plugins.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 VMware, Inc. All Rights Reserved.
* Copyright (C) 2020-2021 VMware, Inc. All Rights Reserved.
*
* Licensed under the GNU Lesser General Public License v2.1 (the "License");
* you may not use this file except in compliance with the License. The terms
Expand Down Expand Up @@ -314,11 +314,11 @@ _TDNFLoadPluginConfigs(
continue;
}

dwError = TDNFAllocateStringPrintf(
dwError = TDNFJoinPath(
&pszPluginConfig,
"%s/%s",
pConf->pszConfPath,
pEnt->d_name);
pEnt->d_name,
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = _TDNFLoadPluginConfig(pszPluginConfig, &pPlugin);
Expand Down
40 changes: 14 additions & 26 deletions client/remoterepo.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,7 @@ TDNFCreatePackageUrl(
BAIL_ON_TDNF_ERROR(dwError);

if (pszBaseUrl) {
dwError = TDNFAllocateStringPrintf(&pszPackageUrl,
"%s/%s",
pszBaseUrl,
pszPackageLocation);
dwError = TDNFJoinPath(&pszPackageUrl, pszBaseUrl, pszPackageLocation, NULL);
BAIL_ON_TDNF_ERROR(dwError);
}
else
Expand Down Expand Up @@ -944,10 +941,10 @@ TDNFDownloadPackage(
&pszCopyOfPackageLocation);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFAllocateStringPrintf(&pszPackageFile,
"%s/%s",
pszRpmCacheDir,
basename(pszCopyOfPackageLocation));
dwError = TDNFJoinPath(&pszPackageFile,
pszRpmCacheDir,
basename(pszCopyOfPackageLocation),
NULL);
BAIL_ON_TDNF_ERROR(dwError);

/* don't download if file is already there. Older versions may have left
Expand Down Expand Up @@ -1002,12 +999,11 @@ TDNFDownloadPackageToCache(
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = TDNFAllocateStringPrintf(
&pszRpmCacheDir,
"%s/%s/%s",
pTdnf->pConf->pszCacheDir,
pszRepoName,
"rpms");
dwError = TDNFJoinPath(&pszRpmCacheDir,
pTdnf->pConf->pszCacheDir,
pszRepoName,
"rpms",
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFNormalizePath(pszRpmCacheDir,
Expand All @@ -1033,7 +1029,7 @@ TDNFDownloadPackageToCache(
* TDNFDownloadPackageToTree()
*
* Download a package while preserving the directory path. For example,
* if pszPackageLocation is "RPMS/x86_64/foo-1.2-3.rpm, the destination will
* if pszPackageLocation is "RPMS/x86_64/foo-1.2-3.rpm", the destination will
* be downloaded under the destination directory in RPMS/x86_64/foo-1.2-3.rpm
* (so 'RPMS/x86_64/' will be preserved).
*/
Expand Down Expand Up @@ -1073,11 +1069,7 @@ TDNFDownloadPackageToTree(
}
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFAllocateStringPrintf(
&pszFilePath,
"%s/%s",
pszNormalRpmCacheDir,
pszRemotePath);
dwError = TDNFJoinPath(&pszFilePath, pszNormalRpmCacheDir, pszRemotePath, NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFNormalizePath(
Expand Down Expand Up @@ -1144,7 +1136,7 @@ TDNFDownloadPackageToTree(
* TDNFDownloadPackageToDirectory()
*
* Download a package withou preserving the directory path. For example,
* if pszPackageLocation is "RPMS/x86_64/foo-1.2-3.rpm, the destination will
* if pszPackageLocation is "RPMS/x86_64/foo-1.2-3.rpm", the destination will
* be downloaded under the destination directory (pszDirectory) as foo-1.2-3.rpm
* (so RPMS/x86_64/ will be stripped).
*/
Expand Down Expand Up @@ -1184,11 +1176,7 @@ TDNFDownloadPackageToDirectory(

pszFileName = basename(pszRemotePath);

dwError = TDNFAllocateStringPrintf(
&pszFilePath,
"%s/%s",
pszDirectory,
pszFileName);
TDNFJoinPath(&pszFilePath, pszDirectory, pszFileName, NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFDownloadPackage(pTdnf, pszPackageLocation, pszPkgName,
Expand Down
Loading

0 comments on commit 8e586f5

Please sign in to comment.