Skip to content

Commit

Permalink
move TDNFIsDir() to common/
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed Nov 15, 2022
1 parent ced5f99 commit 2df446c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
6 changes: 0 additions & 6 deletions client/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1056,12 +1056,6 @@ TDNFGetFileSize(
int *pnSize
);

uint32_t
TDNFIsDir(
const char* pszPath,
int* pnPathIsDir
);

int
TDNFIsGlob(
const char* pszString
Expand Down
36 changes: 0 additions & 36 deletions client/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,6 @@ TDNFGetFileSize(
goto cleanup;
}

uint32_t
TDNFIsDir(
const char* pszPath,
int* pnPathIsDir
)
{
uint32_t dwError = 0;
int nPathIsDir = 0;
struct stat stStat = {0};

if(!pnPathIsDir || IsNullOrEmptyString(pszPath))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

if(stat(pszPath, &stStat))
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

nPathIsDir = S_ISDIR(stStat.st_mode);

*pnPathIsDir = nPathIsDir;
cleanup:
return dwError;

error:
if(pnPathIsDir)
{
*pnPathIsDir = 0;
}
goto cleanup;
}

/* update time if file exists, create if not */
uint32_t
TDNFTouchFile(
Expand Down
6 changes: 6 additions & 0 deletions common/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ TDNFReadFileToStringArray(
char ***pppszArray
);

uint32_t
TDNFIsDir(
const char* pszPath,
int* pnPathIsDir
);

//setopt.c
uint32_t
AddSetOpt(
Expand Down
35 changes: 35 additions & 0 deletions common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,3 +869,38 @@ TDNFReadFileToStringArray(
goto cleanup;
}

uint32_t
TDNFIsDir(
const char* pszPath,
int* pnPathIsDir
)
{
uint32_t dwError = 0;
int nPathIsDir = 0;
struct stat stStat = {0};

if(!pnPathIsDir || IsNullOrEmptyString(pszPath))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

if(stat(pszPath, &stStat))
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

nPathIsDir = S_ISDIR(stStat.st_mode);

*pnPathIsDir = nPathIsDir;
cleanup:
return dwError;

error:
if(pnPathIsDir)
{
*pnPathIsDir = 0;
}
goto cleanup;
}

0 comments on commit 2df446c

Please sign in to comment.