Skip to content

Commit

Permalink
Merge branch 'vmware:dev' into iss34-CheckAvailCacheSizeForDownload
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonsn authored Jul 11, 2022
2 parents 002ec08 + de8980b commit c1b65b8
Show file tree
Hide file tree
Showing 15 changed files with 319 additions and 162 deletions.
29 changes: 24 additions & 5 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,33 +438,52 @@ 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);
}

/* 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");
}
cleanup:
Expand Down
13 changes: 7 additions & 6 deletions client/gpgcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
Expand All @@ -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,
Expand Down
12 changes: 5 additions & 7 deletions client/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,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(
Expand Down Expand Up @@ -316,14 +314,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
Expand Down
27 changes: 21 additions & 6 deletions client/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,32 @@ TDNFRepoGetUserPass(
uint32_t
TDNFRepoGetRpmCacheDir(
PTDNF pTdnf,
const char* pszRepo,
PTDNF_REPO_DATA pRepo,
char** ppszRpmCacheDir
);

uint32_t
TDNFRepoRemoveCacheDir(
PTDNF pTdnf,
PTDNF_REPO_DATA pRepo
);

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
Expand All @@ -192,13 +198,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
Expand Down Expand Up @@ -704,6 +710,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,
Expand Down
84 changes: 33 additions & 51 deletions client/repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +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 = TDNFJoinPath(
&pszRepoCacheDir,
pConf->pszCacheDir,
pRepoData->pszId,
NULL);
dwError = TDNFGetCachePath(pTdnf, pRepoData,
NULL, NULL,
&pszRepoCacheDir);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFJoinPath(
Expand Down Expand Up @@ -81,6 +77,7 @@ TDNFInitRepo(
BAIL_ON_TDNF_ERROR(dwError);
}
pSolvRepoInfo->pRepo = pRepo;
pSolvRepoInfo->pszRepoCacheDir = pszRepoCacheDir;
pRepo->appdata = pSolvRepoInfo;

dwError = SolvCalculateCookieForFile(pRepoMD->pszRepoMD, pSolvRepoInfo->cookie);
Expand Down Expand Up @@ -121,9 +118,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;
Expand Down Expand Up @@ -504,7 +501,7 @@ TDNFStoreBaseURLFromMetalink(
{
uint32_t dwError = 0;
char *pszBaseUrlFile = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA pRepo = NULL;

if (!pTdnf ||
!pTdnf->pConf ||
Expand All @@ -514,34 +511,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);
Expand Down Expand Up @@ -704,11 +697,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);
Expand Down Expand Up @@ -781,12 +772,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);
Expand Down Expand Up @@ -925,12 +913,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);
Expand All @@ -940,12 +928,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);
Expand Down Expand Up @@ -1416,12 +1401,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);
Expand Down
Loading

0 comments on commit c1b65b8

Please sign in to comment.