Skip to content

Commit

Permalink
avoid failure when checking free space if cache directory doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed Dec 1, 2023
1 parent 13751a8 commit 6f2ca3f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client/packageutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,21 +1000,28 @@ TDNFGetAvailableCacheBytes(
)
{
uint32_t dwError = 0;
struct statfs tmpStatfsBuffer = {0};
struct statfs stfs = {0};
struct stat st = {0};

if(!pConf || !pConf->pszCacheDir || !pqwAvailCacheDirBytes)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

if (statfs(pConf->pszCacheDir, &tmpStatfsBuffer) != 0)
if (stat(pConf->pszCacheDir, &st) != 0) {
/* avoid failure when checking space, and dir doesn't exist */
dwError = TDNFUtilsMakeDirs(pConf->pszCacheDir);
BAIL_ON_TDNF_ERROR(dwError);
}

if (statfs(pConf->pszCacheDir, &stfs) != 0)
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

*pqwAvailCacheDirBytes = tmpStatfsBuffer.f_bsize * tmpStatfsBuffer.f_bavail;
*pqwAvailCacheDirBytes = stfs.f_bsize * stfs.f_bavail;

cleanup:
return dwError;
Expand Down

0 comments on commit 6f2ca3f

Please sign in to comment.