From 0edf8cc8f76e09212550895cb876bee88bba89c0 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Thu, 30 Jun 2022 23:25:58 +0000 Subject: [PATCH 01/10] add SolvCreateRepoCacheName() and set pszCacheName for repos --- client/repolist.c | 15 ++++++++++++++ include/tdnftypes.h | 1 + solv/prototypes.h | 7 +++++++ solv/tdnfrepo.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/client/repolist.c b/client/repolist.c index fe4a651df..ef768cb9a 100644 --- a/client/repolist.c +++ b/client/repolist.c @@ -665,6 +665,21 @@ TDNFRepoListFinalize( dwError = TDNFConfigReplaceVars(pTdnf, &pRepo->pszMetaLink); BAIL_ON_TDNF_ERROR(dwError); } + + if (pRepo->pszMetaLink) + { + dwError = SolvCreateRepoCacheName(pRepo->pszId, + pRepo->pszMetaLink, + &pRepo->pszCacheName); + } + else if (pRepo->pszBaseUrl) + { + dwError = SolvCreateRepoCacheName(pRepo->pszId, + pRepo->pszBaseUrl, + &pRepo->pszCacheName); + } + BAIL_ON_TDNF_ERROR(dwError); + printf("pszCacheName = %s\n", pRepo->pszCacheName); } } cleanup: diff --git a/include/tdnftypes.h b/include/tdnftypes.h index f794f6266..4af981c90 100644 --- a/include/tdnftypes.h +++ b/include/tdnftypes.h @@ -275,6 +275,7 @@ typedef struct _TDNF_REPO_DATA int nSkipMDFileLists; int nSkipMDUpdateInfo; int nSkipMDOther; + char *pszCacheName; struct _TDNF_REPO_DATA* pNext; }TDNF_REPO_DATA, *PTDNF_REPO_DATA; diff --git a/solv/prototypes.h b/solv/prototypes.h index 67c7c7af0..24c1551db 100644 --- a/solv/prototypes.h +++ b/solv/prototypes.h @@ -570,6 +570,13 @@ SolvCalculateCookieForFile( unsigned char* pszCookie ); +uint32_t +SolvCreateRepoCacheName( + const char *pszName, + const char *pszUrl, + char **ppszCacheName + ); + uint32_t SolvGetMetaDataCachePath( PSOLV_REPO_INFO_INTERNAL pSolvRepoInfo, diff --git a/solv/tdnfrepo.c b/solv/tdnfrepo.c index dee0d051c..3d49ec016 100644 --- a/solv/tdnfrepo.c +++ b/solv/tdnfrepo.c @@ -377,6 +377,55 @@ SolvCalculateCookieForFile( goto cleanup; } +/* Create a name for the repo cache path based on repo name and + a a hash of the url. +*/ +uint32_t +SolvCreateRepoCacheName( + const char *pszName, + const char *pszUrl, + char **ppszCacheName + ) +{ + uint32_t dwError = 0; + Chksum *pChkSum = NULL; + unsigned char pCookie[SOLV_COOKIE_LEN] = {0}; + char pszCookie[SOLV_COOKIE_LEN*2+1]; + char *pszCacheName; + int i; + + if (!pszName || !pszUrl || !ppszCacheName) + { + dwError = ERROR_TDNF_INVALID_PARAMETER; + BAIL_ON_TDNF_LIBSOLV_ERROR(dwError); + } + + pChkSum = solv_chksum_create(REPOKEY_TYPE_SHA256); + if (!pChkSum) + { + dwError = ERROR_TDNF_SOLV_CHKSUM; + BAIL_ON_TDNF_LIBSOLV_ERROR(dwError); + } + solv_chksum_add(pChkSum, pszUrl, strlen(pszUrl)); + solv_chksum_free(pChkSum, pCookie); + + for (i = 0; i < SOLV_COOKIE_LEN; i++) + { + snprintf(&pszCookie[2*i], 3, "%.2x", pCookie[i]); + } + + dwError = TDNFAllocateStringPrintf(&pszCacheName, "%s-%s", pszName, pszCookie); + BAIL_ON_TDNF_LIBSOLV_ERROR(dwError); + + *ppszCacheName = pszCacheName; +cleanup: + return dwError; + +error: + TDNF_SAFE_FREE_MEMORY(pszCacheName); + goto cleanup; +} + uint32_t SolvGetMetaDataCachePath( PSOLV_REPO_INFO_INTERNAL pSolvRepoInfo, From 4db4d476a48119c1d7962b754c9e0b0488f91f92 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 1 Jul 2022 00:44:22 +0000 Subject: [PATCH 02/10] use TDNFGetCachePath() to create paths to cache dirs (not unique yet) --- client/api.c | 10 ++-- client/gpgcheck.c | 13 +++--- client/init.c | 4 +- client/prototypes.h | 21 ++++++--- client/repo.c | 71 +++++++++++----------------- client/repolist.c | 2 +- client/repoutils.c | 111 +++++++++++++++++++++++++------------------- 7 files changed, 122 insertions(+), 110 deletions(-) diff --git a/client/api.c b/client/api.c index 0e4ef75fb..e6144c6f6 100644 --- a/client/api.c +++ b/client/api.c @@ -438,31 +438,31 @@ TDNFClean( if (nCleanType & CLEANTYPE_METADATA) { pr_info(" metadata"); - dwError = TDNFRepoRemoveCache(pTdnf, pRepo->pszId); + dwError = TDNFRepoRemoveCache(pTdnf, pRepo); BAIL_ON_TDNF_ERROR(dwError); } if (nCleanType & CLEANTYPE_DBCACHE) { pr_info(" dbcache"); - dwError = TDNFRemoveSolvCache(pTdnf, pRepo->pszId); + dwError = TDNFRemoveSolvCache(pTdnf, pRepo); BAIL_ON_TDNF_ERROR(dwError); } if (nCleanType & CLEANTYPE_PACKAGES) { pr_info(" packages"); - dwError = TDNFRemoveRpmCache(pTdnf, pRepo->pszId); + dwError = TDNFRemoveRpmCache(pTdnf, pRepo); BAIL_ON_TDNF_ERROR(dwError); } if (nCleanType & CLEANTYPE_KEYS) { pr_info(" keys"); - dwError = TDNFRemoveKeysCache(pTdnf, pRepo->pszId); + dwError = TDNFRemoveKeysCache(pTdnf, pRepo); BAIL_ON_TDNF_ERROR(dwError); } if (nCleanType & CLEANTYPE_EXPIRE_CACHE) { pr_info(" expire-cache"); - dwError = TDNFRemoveLastRefreshMarker(pTdnf, pRepo->pszId); + dwError = TDNFRemoveLastRefreshMarker(pTdnf, pRepo); BAIL_ON_TDNF_ERROR(dwError); } pr_info("\n"); diff --git a/client/gpgcheck.c b/client/gpgcheck.c index a60143642..e74b084f0 100644 --- a/client/gpgcheck.c +++ b/client/gpgcheck.c @@ -564,6 +564,7 @@ TDNFFetchRemoteGPGKey( char* pszRealTopKeyCacheDir = NULL; char* pszDownloadCacheDir = NULL; char* pszKeyLocation = NULL; + PTDNF_REPO_DATA pRepo = NULL; if(!pTdnf || IsNullOrEmptyString(pszRepoName || IsNullOrEmptyString(pszUrlGPGKey))) { @@ -578,12 +579,12 @@ TDNFFetchRemoteGPGKey( } BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFJoinPath( - &pszTopKeyCacheDir, - pTdnf->pConf->pszCacheDir, - pszRepoName, - "keys", - NULL); + dwError = TDNFFindRepoById(pTdnf, pszRepoName, &pRepo); + BAIL_ON_TDNF_ERROR(dwError); + + dwError = TDNFGetCachePath(pTdnf, pRepo, + "keys", NULL, + &pszTopKeyCacheDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFNormalizePath(pszTopKeyCacheDir, diff --git a/client/init.c b/client/init.c index 2601fb7d4..7e9da56cc 100644 --- a/client/init.c +++ b/client/init.c @@ -313,14 +313,14 @@ TDNFRefreshSack( goto cleanup; } - dwError = TDNFRepoRemoveCache(pTdnf, pRepo->pszId); + dwError = TDNFRepoRemoveCache(pTdnf, pRepo); if (dwError == ERROR_TDNF_FILE_NOT_FOUND) { dwError = 0;//Ignore non existent folders } BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFRemoveSolvCache(pTdnf, pRepo->pszId); + dwError = TDNFRemoveSolvCache(pTdnf, pRepo); if (dwError == ERROR_TDNF_FILE_NOT_FOUND) { dwError = 0;//Ignore non existent folders diff --git a/client/prototypes.h b/client/prototypes.h index 9be88e5f8..4f25cc130 100644 --- a/client/prototypes.h +++ b/client/prototypes.h @@ -162,26 +162,26 @@ TDNFRepoGetUserPass( uint32_t TDNFRepoGetRpmCacheDir( PTDNF pTdnf, - const char* pszRepo, + PTDNF_REPO_DATA pRepo, char** ppszRpmCacheDir ); uint32_t TDNFRepoRemoveCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ); uint32_t TDNFRemoveRpmCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ); uint32_t TDNFRemoveLastRefreshMarker( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ); uint32_t @@ -192,13 +192,13 @@ TDNFRemoveTmpRepodata( uint32_t TDNFRemoveSolvCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ); uint32_t TDNFRemoveKeysCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ); uint32_t @@ -677,6 +677,15 @@ TDNFGetSkipDigestOption( uint32_t *pdwSkipDigest ); +uint32_t +TDNFGetCachePath( + PTDNF pTdnf, + PTDNF_REPO_DATA pRepo, + const char *pszSubDir, + const char *pszFileName, + char **ppszPath +); + uint32_t TDNFGetRepoById( PTDNF pTdnf, diff --git a/client/repo.c b/client/repo.c index e20af30b1..c4bfec21a 100644 --- a/client/repo.c +++ b/client/repo.c @@ -121,9 +121,9 @@ TDNFInitRepo( if(pTdnf) { - TDNFRepoRemoveCache(pTdnf, pRepoData->pszId); - TDNFRemoveSolvCache(pTdnf, pRepoData->pszId); - TDNFRemoveLastRefreshMarker(pTdnf, pRepoData->pszId); + TDNFRepoRemoveCache(pTdnf, pRepoData); + TDNFRemoveSolvCache(pTdnf, pRepoData); + TDNFRemoveLastRefreshMarker(pTdnf, pRepoData); } } goto cleanup; @@ -504,7 +504,7 @@ TDNFStoreBaseURLFromMetalink( { uint32_t dwError = 0; char *pszBaseUrlFile = NULL; - PTDNF_REPO_DATA pRepos = NULL; + PTDNF_REPO_DATA pRepo = NULL; if (!pTdnf || !pTdnf->pConf || @@ -514,34 +514,30 @@ TDNFStoreBaseURLFromMetalink( dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - pRepos = pTdnf->pRepos; - if (!pRepos) + + if (!pTdnf->pRepos) { dwError = ERROR_TDNF_NO_REPOS; BAIL_ON_TDNF_ERROR(dwError); } - while(pRepos) + for (pRepo = pTdnf->pRepos; pRepo; pRepo = pRepo->pNext) { - if(!strcmp(pszRepo, pRepos->pszId)) + if(!strcmp(pszRepo, pRepo->pszId)) { break; } - pRepos = pRepos->pNext; } - if (!pRepos) + if (!pRepo) { dwError = ERROR_TDNF_NO_REPOS; BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFJoinPath(&pszBaseUrlFile, - pTdnf->pConf->pszCacheDir, - pRepos->pszId, - "tmp", - TDNF_REPO_BASEURL_FILE_NAME, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + "tmp", TDNF_REPO_BASEURL_FILE_NAME, + &pszBaseUrlFile); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFCreateAndWriteToFile(pszBaseUrlFile, pszRepoMDURL); @@ -704,11 +700,9 @@ TDNFGetRepoMD( (void **)&pRepoMDRel); BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFJoinPath( - &pRepoMDRel->pszRepoCacheDir, - pTdnf->pConf->pszCacheDir, - pRepoData->pszId, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepoData, + NULL, NULL, + &pRepoMDRel->pszRepoCacheDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFAllocateString(pszRepoMDFile, &pRepoMDRel->pszRepoMD); @@ -781,12 +775,9 @@ TDNFGetRepoMD( { pr_info("Refreshing metadata for: '%s'\n", pRepoData->pszName); /* always download to tmp */ - dwError = TDNFJoinPath( - &pszTmpRepoDataDir, - pTdnf->pConf->pszCacheDir, - pRepoData->pszId, - "tmp", - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepoData, + "tmp", NULL, + &pszTmpRepoDataDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFUtilsMakeDirs(pszTmpRepoDataDir); @@ -925,12 +916,12 @@ TDNFGetRepoMD( { /* Remove the old repodata, solvcache and lastRefreshMarker before replacing the new repomd file and metalink files. */ - TDNFRepoRemoveCache(pTdnf, pRepoData->pszId); - TDNFRemoveSolvCache(pTdnf, pRepoData->pszId); - TDNFRemoveLastRefreshMarker(pTdnf, pRepoData->pszId); + TDNFRepoRemoveCache(pTdnf, pRepoData); + TDNFRemoveSolvCache(pTdnf, pRepoData); + TDNFRemoveLastRefreshMarker(pTdnf, pRepoData); if (!nKeepCache) { - TDNFRemoveRpmCache(pTdnf, pRepoData->pszId); + TDNFRemoveRpmCache(pTdnf, pRepoData); } dwError = TDNFUtilsMakeDirs(pszRepoDataDir); BAIL_ON_TDNF_ERROR(dwError); @@ -940,12 +931,9 @@ TDNFGetRepoMD( if (nNewRepoMDFile) { - dwError = TDNFJoinPath( - &pszLastRefreshMarker, - pTdnf->pConf->pszCacheDir, - pRepoData->pszId, - TDNF_REPO_METADATA_MARKER, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepoData, + TDNF_REPO_METADATA_MARKER, NULL, + &pszLastRefreshMarker); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFTouchFile(pszLastRefreshMarker); BAIL_ON_TDNF_ERROR(dwError); @@ -1416,12 +1404,9 @@ TDNFDownloadMetadata( else { /* if printing only we use the already downloaded repomd.xml */ - dwError = TDNFJoinPath( - &pszRepoMDPath, - pTdnf->pConf->pszCacheDir, - pRepo->pszId, - TDNF_REPO_METADATA_FILE_PATH, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + TDNF_REPO_METADATA_FILE_PATH, NULL, + &pszRepoMDPath); BAIL_ON_TDNF_ERROR(dwError); pr_info("%s\n", pszRepoMDUrl); diff --git a/client/repolist.c b/client/repolist.c index ef768cb9a..e4bcf1093 100644 --- a/client/repolist.c +++ b/client/repolist.c @@ -679,7 +679,6 @@ TDNFRepoListFinalize( &pRepo->pszCacheName); } BAIL_ON_TDNF_ERROR(dwError); - printf("pszCacheName = %s\n", pRepo->pszCacheName); } } cleanup: @@ -803,6 +802,7 @@ TDNFFreeReposInternal( TDNF_SAFE_FREE_STRINGARRAY(pRepo->ppszUrlGPGKeys); TDNF_SAFE_FREE_MEMORY(pRepo->pszUser); TDNF_SAFE_FREE_MEMORY(pRepo->pszPass); + TDNF_SAFE_FREE_MEMORY(pRepo->pszCacheName); pRepos = pRepo->pNext; TDNF_SAFE_FREE_MEMORY(pRepo); } diff --git a/client/repoutils.c b/client/repoutils.c index 99c6062e7..c3bcd9016 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -42,24 +42,24 @@ TDNFRepoMakeCacheDirs( uint32_t TDNFRepoSetBaseUrl( PTDNF pTdnf, - PTDNF_REPO_DATA pszRepo, + PTDNF_REPO_DATA pRepo, const char *pszBaseUrlFile ) { uint32_t dwError = 0; char *pszBaseUrl = NULL; - if (!pTdnf || !pszRepo || IsNullOrEmptyString(pszBaseUrlFile)) + if (!pTdnf || !pRepo || IsNullOrEmptyString(pszBaseUrlFile)) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - TDNF_SAFE_FREE_MEMORY(pszRepo->pszBaseUrl); + TDNF_SAFE_FREE_MEMORY(pRepo->pszBaseUrl); dwError = TDNFFileReadAllText(pszBaseUrlFile, &pszBaseUrl, NULL); BAIL_ON_TDNF_ERROR(dwError); - pszRepo->pszBaseUrl = pszBaseUrl; + pRepo->pszBaseUrl = pszBaseUrl; cleanup: return dwError; @@ -180,14 +180,14 @@ TDNFRepoGetUserPass( uint32_t TDNFRepoGetRpmCacheDir( PTDNF pTdnf, - const char* pszRepoId, + PTDNF_REPO_DATA pRepo, char** ppszRpmCacheDir ) { uint32_t dwError = 0; char* pszRpmCacheDir = NULL; - if(!pTdnf || IsNullOrEmptyString(pszRepoId) || !ppszRpmCacheDir) + if(!pTdnf || !pRepo || !ppszRpmCacheDir) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); @@ -199,12 +199,9 @@ TDNFRepoGetRpmCacheDir( BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFJoinPath( - &pszRpmCacheDir, - pTdnf->pConf->pszCacheDir, - pszRepoId, - TDNF_RPM_CACHE_DIR_NAME, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + TDNF_RPM_CACHE_DIR_NAME, NULL, + &pszRpmCacheDir); BAIL_ON_TDNF_ERROR(dwError); if(access(pszRpmCacheDir, F_OK)) @@ -232,24 +229,21 @@ TDNFRepoGetRpmCacheDir( uint32_t TDNFRepoRemoveCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ) { uint32_t dwError = 0; char* pszRepoCacheDir = NULL; - if(!pTdnf || !pTdnf->pConf || IsNullOrEmptyString(pszRepoId)) + if(!pTdnf || !pRepo || !pTdnf->pConf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFJoinPath( - &pszRepoCacheDir, - pTdnf->pConf->pszCacheDir, - pszRepoId, - TDNF_REPODATA_DIR_NAME, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + TDNF_REPODATA_DIR_NAME, NULL, + &pszRepoCacheDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFRecursivelyRemoveDir(pszRepoCacheDir); @@ -270,19 +264,19 @@ TDNFRepoRemoveCache( uint32_t TDNFRemoveRpmCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ) { uint32_t dwError = 0; char* pszRpmCacheDir = NULL; - if (!pTdnf || !pTdnf->pConf || IsNullOrEmptyString(pszRepoId)) + if (!pTdnf || !pRepo || !pTdnf->pConf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFRepoGetRpmCacheDir(pTdnf, pszRepoId, &pszRpmCacheDir); + dwError = TDNFRepoGetRpmCacheDir(pTdnf, pRepo, &pszRpmCacheDir); BAIL_ON_TDNF_ERROR(dwError); if (!IsNullOrEmptyString(pszRpmCacheDir)) @@ -330,24 +324,21 @@ TDNFRemoveTmpRepodata( uint32_t TDNFRemoveLastRefreshMarker( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ) { uint32_t dwError = 0; char* pszLastRefreshMarker = NULL; - if(!pTdnf || !pTdnf->pConf || IsNullOrEmptyString(pszRepoId)) + if(!pTdnf || !pRepo || !pTdnf->pConf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFJoinPath( - &pszLastRefreshMarker, - pTdnf->pConf->pszCacheDir, - pszRepoId, - TDNF_REPO_METADATA_MARKER, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + TDNF_REPO_METADATA_MARKER, NULL, + &pszLastRefreshMarker); BAIL_ON_TDNF_ERROR(dwError); if (pszLastRefreshMarker) { @@ -367,24 +358,21 @@ TDNFRemoveLastRefreshMarker( uint32_t TDNFRemoveSolvCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ) { uint32_t dwError = 0; char* pszSolvCacheDir = NULL; - if(!pTdnf || !pTdnf->pConf || IsNullOrEmptyString(pszRepoId)) + if(!pTdnf || !pRepo || !pTdnf->pConf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFJoinPath( - &pszSolvCacheDir, - pTdnf->pConf->pszCacheDir, - pszRepoId, - TDNF_SOLVCACHE_DIR_NAME, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + TDNF_SOLVCACHE_DIR_NAME, NULL, + &pszSolvCacheDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFRecursivelyRemoveDir(pszSolvCacheDir); @@ -404,24 +392,21 @@ TDNFRemoveSolvCache( uint32_t TDNFRemoveKeysCache( PTDNF pTdnf, - const char* pszRepoId + PTDNF_REPO_DATA pRepo ) { uint32_t dwError = 0; char* pszKeysDir = NULL; - if(!pTdnf || !pTdnf->pConf || IsNullOrEmptyString(pszRepoId)) + if(!pTdnf || !pRepo || !pTdnf->pConf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFJoinPath( - &pszKeysDir, - pTdnf->pConf->pszCacheDir, - pszRepoId, - "keys", - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + "keys", NULL, + &pszKeysDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFRecursivelyRemoveDir(pszKeysDir); @@ -613,6 +598,38 @@ TDNFRepoApplySSLSettings( goto cleanup; } +uint32_t +TDNFGetCachePath( + PTDNF pTdnf, + PTDNF_REPO_DATA pRepo, + const char *pszSubDir, + const char *pszFileName, + char **ppszPath +) +{ + uint32_t dwError = 0; + + if(!pTdnf || !pRepo || !ppszPath) + { + dwError = ERROR_TDNF_INVALID_PARAMETER; + BAIL_ON_TDNF_ERROR(dwError); + } + + dwError = TDNFJoinPath( + ppszPath, + pTdnf->pConf->pszCacheDir, + pRepo->pszId, + pszSubDir, + pszFileName, + NULL); + BAIL_ON_TDNF_LIBSOLV_ERROR(dwError); + +cleanup: + return dwError; +error: + goto cleanup; +} + uint32_t TDNFFindRepoById( PTDNF pTdnf, From 7c95300508a43e08ea513f9d0ad211f289788d89 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 1 Jul 2022 18:04:29 +0000 Subject: [PATCH 03/10] use pszCacheName, solv/* not yet working --- client/init.c | 8 +++----- client/repo.c | 6 +----- client/repolist.c | 3 ++- client/repoutils.c | 9 ++++++++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/client/init.c b/client/init.c index 7e9da56cc..9b2baa902 100644 --- a/client/init.c +++ b/client/init.c @@ -281,11 +281,9 @@ TDNFRefreshSack( unless requested to ignore. lMetadataExpire < 0 means never expire. */ if(pRepo->lMetadataExpire >= 0 && !pTdnf->pArgs->nCacheOnly) { - dwError = TDNFJoinPath( - &pszRepoCacheDir, - pTdnf->pConf->pszCacheDir, - pRepo->pszId, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepo, + NULL, NULL, + &pszRepoCacheDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFShouldSyncMetadata( diff --git a/client/repo.c b/client/repo.c index c4bfec21a..ee6a7d0c7 100644 --- a/client/repo.c +++ b/client/repo.c @@ -47,11 +47,7 @@ TDNFInitRepo( pConf = pTdnf->pConf; pPool = pSack->pPool; - dwError = TDNFJoinPath( - &pszRepoCacheDir, - pConf->pszCacheDir, - pRepoData->pszId, - NULL); + dwError = TDNFGetCachePath(pTdnf, pRepoData, NULL, NULL, &pszRepoCacheDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFJoinPath( diff --git a/client/repolist.c b/client/repolist.c index e4bcf1093..5935e9bee 100644 --- a/client/repolist.c +++ b/client/repolist.c @@ -648,7 +648,8 @@ TDNFRepoListFinalize( for the repos that are enabled. */ for(pRepo = pTdnf->pRepos; pRepo; pRepo = pRepo->pNext) { - if(pRepo->nEnabled) +// if(pRepo->nEnabled) + if (1) { if(pRepo->pszName) { diff --git a/client/repoutils.c b/client/repoutils.c index c3bcd9016..ca7699dce 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -615,10 +615,17 @@ TDNFGetCachePath( BAIL_ON_TDNF_ERROR(dwError); } + if (!pRepo->pszCacheName) + { + dwError = ERROR_TDNF_INVALID_PARAMETER; + BAIL_ON_TDNF_ERROR(dwError); + pr_err("pRepo->pszCacheName not set\n"); + } + dwError = TDNFJoinPath( ppszPath, pTdnf->pConf->pszCacheDir, - pRepo->pszId, + pRepo->pszCacheName ? pRepo->pszCacheName : pRepo->pszId, pszSubDir, pszFileName, NULL); From 2da2c1d3b66e1be48b58f824e73afa34a60477bf Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 1 Jul 2022 19:57:18 +0000 Subject: [PATCH 04/10] unique path for solvdata --- client/repo.c | 9 +++++---- solv/prototypes.h | 1 + solv/tdnfrepo.c | 13 ++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/client/repo.c b/client/repo.c index ee6a7d0c7..eb262b62e 100644 --- a/client/repo.c +++ b/client/repo.c @@ -32,22 +32,22 @@ TDNFInitRepo( char* pszRepoDataDir = NULL; char* pszRepoCacheDir = NULL; PTDNF_REPO_METADATA pRepoMD = NULL; - PTDNF_CONF pConf = NULL; Repo* pRepo = NULL; Pool* pPool = NULL; int nUseMetaDataCache = 0; PSOLV_REPO_INFO_INTERNAL pSolvRepoInfo = NULL; - if (!pTdnf || !pTdnf->pConf || !pRepoData || !pSack || !pSack->pPool) + if (!pTdnf || !pRepoData || !pSack || !pSack->pPool) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - pConf = pTdnf->pConf; pPool = pSack->pPool; - dwError = TDNFGetCachePath(pTdnf, pRepoData, NULL, NULL, &pszRepoCacheDir); + dwError = TDNFGetCachePath(pTdnf, pRepoData, + NULL, NULL, + &pszRepoCacheDir); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFJoinPath( @@ -77,6 +77,7 @@ TDNFInitRepo( BAIL_ON_TDNF_ERROR(dwError); } pSolvRepoInfo->pRepo = pRepo; + pSolvRepoInfo->pszRepoCacheDir = pszRepoCacheDir; pRepo->appdata = pSolvRepoInfo; dwError = SolvCalculateCookieForFile(pRepoMD->pszRepoMD, pSolvRepoInfo->cookie); diff --git a/solv/prototypes.h b/solv/prototypes.h index 24c1551db..2d28a53e0 100644 --- a/solv/prototypes.h +++ b/solv/prototypes.h @@ -46,6 +46,7 @@ typedef struct _SOLV_REPO_INFO_INTERNAL_ Repo* pRepo; unsigned char cookie[SOLV_COOKIE_LEN]; int nCookieSet; + char *pszRepoCacheDir; }SOLV_REPO_INFO_INTERNAL, *PSOLV_REPO_INFO_INTERNAL; extern Id allDepKeyIds[]; diff --git a/solv/tdnfrepo.c b/solv/tdnfrepo.c index 3d49ec016..5d3a935c7 100644 --- a/solv/tdnfrepo.c +++ b/solv/tdnfrepo.c @@ -278,6 +278,7 @@ SolvReadInstalledRpms( Repo *pRepo = NULL; FILE *pCacheFile = NULL; int dwFlags = 0; + if(!pPool || !ppRepo) { dwError = ERROR_TDNF_INVALID_PARAMETER; @@ -295,6 +296,7 @@ SolvReadInstalledRpms( { /* coverity[toctou] */ pCacheFile = fopen(pszCacheFileName, "r"); + if(!pCacheFile) { dwError = errno; @@ -378,7 +380,7 @@ SolvCalculateCookieForFile( } /* Create a name for the repo cache path based on repo name and - a a hash of the url. + a hash of the url. */ uint32_t SolvCreateRepoCacheName( @@ -447,9 +449,8 @@ SolvGetMetaDataCachePath( { dwError = TDNFAllocateStringPrintf( &pszCachePath, - "%s/%s/%s/%s.solv", - pSack->pszCacheDir, - pRepo->name, + "%s/%s/%s.solv", + pSolvRepoInfo->pszRepoCacheDir, TDNF_SOLVCACHE_DIR_NAME, pRepo->name); BAIL_ON_TDNF_ERROR(dwError); @@ -615,12 +616,10 @@ SolvCreateMetaDataCache( pRepo = pSolvRepoInfo->pRepo; dwError = TDNFJoinPath( &pszSolvCacheDir, - pSack->pszCacheDir, - pRepo->name, + pSolvRepoInfo->pszRepoCacheDir, TDNF_SOLVCACHE_DIR_NAME, NULL); BAIL_ON_TDNF_LIBSOLV_ERROR(dwError); - if (access(pszSolvCacheDir, W_OK | X_OK)) { if(errno != ENOENT) From 6bc1a8cc5233ae4edb99d8714e57761825b40ef3 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 1 Jul 2022 22:00:11 +0000 Subject: [PATCH 05/10] accept empty pszCacheName to create repo path --- client/repoutils.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/client/repoutils.c b/client/repoutils.c index ca7699dce..e33a46257 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -615,13 +615,6 @@ TDNFGetCachePath( BAIL_ON_TDNF_ERROR(dwError); } - if (!pRepo->pszCacheName) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - pr_err("pRepo->pszCacheName not set\n"); - } - dwError = TDNFJoinPath( ppszPath, pTdnf->pConf->pszCacheDir, From 39a10e476ea9b96fc978d5e007c828077d3f0c98 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 1 Jul 2022 22:00:29 +0000 Subject: [PATCH 06/10] fix tests --- pytests/tests/test_cache.py | 24 ++++++++++++++++++------ pytests/tests/test_installroot.py | 11 ++++++++++- pytests/tests/test_skip_md.py | 12 ++++++++++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/pytests/tests/test_cache.py b/pytests/tests/test_cache.py index 57c0088d7..10a5b4b67 100644 --- a/pytests/tests/test_cache.py +++ b/pytests/tests/test_cache.py @@ -7,6 +7,7 @@ # import os +import fnmatch import pytest @@ -44,6 +45,14 @@ def check_package_in_cache(utils, pkgname): return False +def find_cache_dir(utils, reponame): + cache_dir = utils.tdnf_config.get('main', 'cachedir') + for f in os.listdir(cache_dir): + if fnmatch.fnmatch(f, '{}-*'.format(reponame)): + return os.path.join(cache_dir, f) + return None + + def test_install_without_cache(utils): clean_cache(utils) disable_cache(utils) @@ -86,8 +95,9 @@ def test_install_with_keepcache_false(utils): def test_disable_repo_make_cache(utils): - cache_dir = utils.tdnf_config.get('main', 'cachedir') - lastrefresh = os.path.join(cache_dir, 'photon-test/lastrefresh') + cache_dir = find_cache_dir(utils, 'photon-test') + assert(cache_dir is not None) + lastrefresh = os.path.join(cache_dir, 'lastrefresh') before = os.path.getmtime(lastrefresh) utils.run(['tdnf', '--disablerepo=*', 'makecache']) after = os.path.getmtime(lastrefresh) @@ -95,8 +105,9 @@ def test_disable_repo_make_cache(utils): def test_enable_repo_make_cache(utils): - cache_dir = utils.tdnf_config.get('main', 'cachedir') - lastrefresh = os.path.join(cache_dir, 'photon-test/lastrefresh') + cache_dir = find_cache_dir(utils, 'photon-test') + assert(cache_dir is not None) + lastrefresh = os.path.join(cache_dir, 'lastrefresh') before = os.path.getmtime(lastrefresh) utils.run(['tdnf', '--disablerepo=*', '--enablerepo=photon-test', 'makecache']) after = os.path.getmtime(lastrefresh) @@ -105,8 +116,9 @@ def test_enable_repo_make_cache(utils): # -v (verbose) prints progress data def test_enable_repo_make_cache_verbose(utils): - cache_dir = utils.tdnf_config.get('main', 'cachedir') - lastrefresh = os.path.join(cache_dir, 'photon-test/lastrefresh') + cache_dir = find_cache_dir(utils, 'photon-test') + assert(cache_dir is not None) + lastrefresh = os.path.join(cache_dir, 'lastrefresh') before = os.path.getmtime(lastrefresh) utils.run(['tdnf', '-v', '--disablerepo=*', '--enablerepo=photon-test', 'makecache']) after = os.path.getmtime(lastrefresh) diff --git a/pytests/tests/test_installroot.py b/pytests/tests/test_installroot.py index 786df86b0..488f1b618 100644 --- a/pytests/tests/test_installroot.py +++ b/pytests/tests/test_installroot.py @@ -9,6 +9,7 @@ import os import shutil import pytest +import fnmatch INSTALLROOT = '/root/installroot' REPOFILENAME = 'photon-test.repo' @@ -76,6 +77,14 @@ def erase_package(utils, pkgname, installroot=INSTALLROOT, pkgversion=None): assert(not check_package(utils, pkgname)) +def find_cache_dir(reponame): + cache_dir = os.path.join(INSTALLROOT, 'var/cache/tdnf') + for f in os.listdir(cache_dir): + if fnmatch.fnmatch(f, '{}-*'.format(reponame)): + return os.path.join(cache_dir, f) + return None + + def test_install(utils): install_root(utils) pkgname = utils.config["mulversion_pkgname"] @@ -98,7 +107,7 @@ def test_makecache(utils): '--installroot', INSTALLROOT, '--releasever=4.0'], noconfig=True) assert(ret['retval'] == 0) - assert(os.path.isdir(os.path.join(INSTALLROOT, 'var/cache/tdnf', 'photon-test'))) + assert(find_cache_dir('photon-test') is not None) shutil.rmtree(INSTALLROOT) diff --git a/pytests/tests/test_skip_md.py b/pytests/tests/test_skip_md.py index b8442c351..8f194f8d3 100644 --- a/pytests/tests/test_skip_md.py +++ b/pytests/tests/test_skip_md.py @@ -10,7 +10,7 @@ import os import pytest import glob - +import fnmatch REPOFILENAME = "photon-skip.repo" REPOID = "photon-skip" @@ -61,6 +61,14 @@ def get_cache_dir(utils): return '/var/cache/tdnf/' +def find_cache_dir(utils, reponame): + cache_dir = utils.tdnf_config.get('main', 'cachedir') + for f in os.listdir(cache_dir): + if fnmatch.fnmatch(f, '{}-*'.format(reponame)): + return os.path.join(cache_dir, f) + return None + + # enable/disable md part, expect/do not expect download of the associated file def check_skip_md_part(utils, mdpart, skipped): repoconf = os.path.join(utils.config['repo_path'], "yum.repos.d", REPOFILENAME) @@ -68,7 +76,7 @@ def check_skip_md_part(utils, mdpart, skipped): utils.run(['tdnf', '--repoid={}'.format(REPOID), 'clean', 'all']) utils.run(['tdnf', '--repoid={}'.format(REPOID), 'makecache']) - md_dir = os.path.join(get_cache_dir(utils), REPOID, 'repodata') + md_dir = os.path.join(find_cache_dir(utils, REPOID), 'repodata') assert((len(glob.glob('{}/*{}*'.format(md_dir, mdpart))) == 0) == skipped) From 81f2cb80ffab5b5c03e724425a52fcb37dc3c254 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 1 Jul 2022 23:57:58 +0000 Subject: [PATCH 07/10] remove top level repo cache dir if not empty --- client/api.c | 5 +++++ client/prototypes.h | 6 ++++++ client/repoutils.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/client/api.c b/client/api.c index e6144c6f6..ad6020204 100644 --- a/client/api.c +++ b/client/api.c @@ -465,6 +465,11 @@ TDNFClean( dwError = TDNFRemoveLastRefreshMarker(pTdnf, pRepo); BAIL_ON_TDNF_ERROR(dwError); } + + /* remove the top level repo cache dir if it's not empty */ + dwError = TDNFRepoRemoveCacheDir(pTdnf, pRepo); + BAIL_ON_TDNF_ERROR(dwError); + pr_info("\n"); } cleanup: diff --git a/client/prototypes.h b/client/prototypes.h index 4f25cc130..a7a8c98b9 100644 --- a/client/prototypes.h +++ b/client/prototypes.h @@ -166,6 +166,12 @@ TDNFRepoGetRpmCacheDir( char** ppszRpmCacheDir ); +uint32_t +TDNFRepoRemoveCacheDir( + PTDNF pTdnf, + PTDNF_REPO_DATA pRepo + ); + uint32_t TDNFRepoRemoveCache( PTDNF pTdnf, diff --git a/client/repoutils.c b/client/repoutils.c index e33a46257..c00a4607a 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -226,6 +226,44 @@ TDNFRepoGetRpmCacheDir( goto cleanup; } +/* remove the repo top level cache dir */ +uint32_t +TDNFRepoRemoveCacheDir( + PTDNF pTdnf, + PTDNF_REPO_DATA pRepo + ) +{ + uint32_t dwError = 0; + char* pszRepoCacheDir = NULL; + + if(!pTdnf || !pRepo) + { + dwError = ERROR_TDNF_INVALID_PARAMETER; + BAIL_ON_TDNF_ERROR(dwError); + } + + dwError = TDNFGetCachePath(pTdnf, pRepo, + NULL, NULL, + &pszRepoCacheDir); + BAIL_ON_TDNF_ERROR(dwError); + + if (rmdir(pszRepoCacheDir) != 0) + { + /* ignore ENOTEMPTY, let's keep the dir if it's not empty */ + if (errno != ENOENT && errno != ENOTEMPTY) + { + BAIL_ON_TDNF_ERROR(errno); + } + } + +cleanup: + TDNF_SAFE_FREE_MEMORY(pszRepoCacheDir); + return dwError; + +error: + goto cleanup; +} + uint32_t TDNFRepoRemoveCache( PTDNF pTdnf, From 259687388fca287cd96315311c2c9fef52ef74d3 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Tue, 5 Jul 2022 18:11:32 +0000 Subject: [PATCH 08/10] shorten repo cache name to 8 chars --- solv/tdnfrepo.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/solv/tdnfrepo.c b/solv/tdnfrepo.c index 5d3a935c7..f7952fd19 100644 --- a/solv/tdnfrepo.c +++ b/solv/tdnfrepo.c @@ -392,9 +392,8 @@ SolvCreateRepoCacheName( uint32_t dwError = 0; Chksum *pChkSum = NULL; unsigned char pCookie[SOLV_COOKIE_LEN] = {0}; - char pszCookie[SOLV_COOKIE_LEN*2+1]; + char pszCookie[9] = {0}; char *pszCacheName; - int i; if (!pszName || !pszUrl || !ppszCacheName) { @@ -411,10 +410,8 @@ SolvCreateRepoCacheName( solv_chksum_add(pChkSum, pszUrl, strlen(pszUrl)); solv_chksum_free(pChkSum, pCookie); - for (i = 0; i < SOLV_COOKIE_LEN; i++) - { - snprintf(&pszCookie[2*i], 3, "%.2x", pCookie[i]); - } + snprintf(pszCookie, sizeof(pszCookie), "%.2x%.2x%.2x%.2x", + pCookie[0], pCookie[1], pCookie[2], pCookie[3]); dwError = TDNFAllocateStringPrintf(&pszCacheName, "%s-%s", pszName, pszCookie); BAIL_ON_TDNF_LIBSOLV_ERROR(dwError); From 6c3fe2a349dca2808426a587deb080cbfaa59c60 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Tue, 5 Jul 2022 18:13:40 +0000 Subject: [PATCH 09/10] clean up and warn if cacxhe dir is not empty but should be --- client/api.c | 14 +++++++++++ client/repolist.c | 58 +++++++++++++++++++++------------------------- client/repoutils.c | 9 +++---- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/client/api.c b/client/api.c index ad6020204..5c879264c 100644 --- a/client/api.c +++ b/client/api.c @@ -468,6 +468,20 @@ TDNFClean( /* remove the top level repo cache dir if it's not empty */ dwError = TDNFRepoRemoveCacheDir(pTdnf, pRepo); + if (dwError == ERROR_TDNF_SYSTEM_BASE + ENOTEMPTY) + { + /* if we did a 'clean all' the directory should be empty now. If + not we either missed something or someone other than us + put a file there, so warn about it, but don't bail out. + If we did clean just one part it's not expected to be empty + unless the other parts were already cleaned. + */ + if (nCleanType == CLEANTYPE_ALL) + { + pr_err("Cache directory for %s not removed because it's not empty.\n", pRepo->pszId); + } + dwError = 0; + } BAIL_ON_TDNF_ERROR(dwError); pr_info("\n"); diff --git a/client/repolist.c b/client/repolist.c index 5935e9bee..6ffc254f7 100644 --- a/client/repolist.c +++ b/client/repolist.c @@ -645,42 +645,38 @@ TDNFRepoListFinalize( } /* Now that the overrides are applied, replace config vars - for the repos that are enabled. */ + for all repos. */ for(pRepo = pTdnf->pRepos; pRepo; pRepo = pRepo->pNext) { -// if(pRepo->nEnabled) - if (1) + if(pRepo->pszName) { - if(pRepo->pszName) - { - dwError = TDNFConfigReplaceVars(pTdnf, &pRepo->pszName); - BAIL_ON_TDNF_ERROR(dwError); - } - if(pRepo->pszBaseUrl) - { - dwError = TDNFConfigReplaceVars(pTdnf, &pRepo->pszBaseUrl); - BAIL_ON_TDNF_ERROR(dwError); - } - if(pRepo->pszMetaLink) - { - dwError = TDNFConfigReplaceVars(pTdnf, &pRepo->pszMetaLink); - BAIL_ON_TDNF_ERROR(dwError); - } - - if (pRepo->pszMetaLink) - { - dwError = SolvCreateRepoCacheName(pRepo->pszId, - pRepo->pszMetaLink, - &pRepo->pszCacheName); - } - else if (pRepo->pszBaseUrl) - { - dwError = SolvCreateRepoCacheName(pRepo->pszId, - pRepo->pszBaseUrl, - &pRepo->pszCacheName); - } + dwError = TDNFConfigReplaceVars(pTdnf, &pRepo->pszName); + BAIL_ON_TDNF_ERROR(dwError); + } + if(pRepo->pszBaseUrl) + { + dwError = TDNFConfigReplaceVars(pTdnf, &pRepo->pszBaseUrl); + BAIL_ON_TDNF_ERROR(dwError); + } + if(pRepo->pszMetaLink) + { + dwError = TDNFConfigReplaceVars(pTdnf, &pRepo->pszMetaLink); BAIL_ON_TDNF_ERROR(dwError); } + + if (pRepo->pszMetaLink) + { + dwError = SolvCreateRepoCacheName(pRepo->pszId, + pRepo->pszMetaLink, + &pRepo->pszCacheName); + } + else if (pRepo->pszBaseUrl) + { + dwError = SolvCreateRepoCacheName(pRepo->pszId, + pRepo->pszBaseUrl, + &pRepo->pszCacheName); + } + BAIL_ON_TDNF_ERROR(dwError); } cleanup: return dwError; diff --git a/client/repoutils.c b/client/repoutils.c index c00a4607a..f501ccab4 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -247,13 +247,10 @@ TDNFRepoRemoveCacheDir( &pszRepoCacheDir); BAIL_ON_TDNF_ERROR(dwError); - if (rmdir(pszRepoCacheDir) != 0) + if (rmdir(pszRepoCacheDir) != 0 && errno != ENOENT) { - /* ignore ENOTEMPTY, let's keep the dir if it's not empty */ - if (errno != ENOENT && errno != ENOTEMPTY) - { - BAIL_ON_TDNF_ERROR(errno); - } + dwError = errno; + BAIL_ON_TDNF_SYSTEM_ERROR(dwError); } cleanup: From 90c46528a1e9bb9f1bf5125a51337f3e8a341f60 Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Thu, 7 Jul 2022 12:30:47 -0400 Subject: [PATCH 10/10] python: Fix linking to built libraries We incorrectly use RPATH here when we actually want to link to the libraries we produced earlier in the build. Usage of RPATH also causes package builds in Fedora to fail, since RPATHs are forbidden. Fix the tests to load the library from the right place. Signed-off-by: Neal Gompa --- pytests/CMakeLists.txt | 2 +- python/setup.py.in | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/pytests/CMakeLists.txt b/pytests/CMakeLists.txt index ee2e458e3..7f564e1b9 100644 --- a/pytests/CMakeLists.txt +++ b/pytests/CMakeLists.txt @@ -14,7 +14,7 @@ configure_file( ) add_custom_target(check - COMMAND pytest + COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH="${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" pytest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running tests.." ) diff --git a/python/setup.py.in b/python/setup.py.in index 69bbbe04b..089a018de 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -10,11 +10,7 @@ from setuptools import setup from distutils.core import Extension cflags = [ - '-I@PYTDNF_INC_DIR@' -] - -link_args = [ - '-Wl,-rpath=@PYTDNF_LIB_DIR@' + '-I@PYTDNF_INC_DIR@', ] pytdnf_sources = [ @@ -29,8 +25,7 @@ tdnfmodule = Extension('tdnf._tdnf', libraries=['tdnf'], library_dirs=['${PYTDNF_LIB_DIR}'], sources=pytdnf_sources, - extra_compile_args=cflags, - extra_link_args=link_args) + extra_compile_args=cflags) setup(name='@PYTDNF_PACKAGE_NAME@', version='@PYTDNF_VERSION@',