cmFileSys.h/c: Symbolic link fixes.
Added kRecurseLInksFsFl and kLinkFsFl. Changed stat() to lstat() in _cmFileSysIsLink(). Added _cmFileSysIsSocket()
This commit is contained in:
parent
79eb363343
commit
825a359af2
53
cmFileSys.c
53
cmFileSys.c
@ -273,7 +273,7 @@ bool _cmFileSysIsLink( cmFs_t* p, const cmChar_t* fnStr )
|
|||||||
struct stat s;
|
struct stat s;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
if( stat(fnStr,&s) != 0 )
|
if( lstat(fnStr,&s) != 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
// if the file does not exist
|
// if the file does not exist
|
||||||
@ -294,6 +294,26 @@ bool cmFileSysIsLink( cmFileSysH_t h, const cmChar_t* fnStr )
|
|||||||
return _cmFileSysIsLink(p,fnStr);
|
return _cmFileSysIsLink(p,fnStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _cmFileSysIsSocket( cmFs_t* p, const cmChar_t* fnStr )
|
||||||
|
{
|
||||||
|
struct stat s;
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
|
if( stat(fnStr,&s) != 0 )
|
||||||
|
{
|
||||||
|
|
||||||
|
// if the file does not exist
|
||||||
|
if( errno == ENOENT )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_cmFileSysError( p, kStatFailFsRC, errno, "'stat' failed on '%s'.",fnStr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_ISSOCK(s.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool _cmFileSysConcat( cmChar_t* rp, unsigned rn, char sepChar, const cmChar_t* suffixStr )
|
bool _cmFileSysConcat( cmChar_t* rp, unsigned rn, char sepChar, const cmChar_t* suffixStr )
|
||||||
{
|
{
|
||||||
unsigned m = strlen(rp);
|
unsigned m = strlen(rp);
|
||||||
@ -798,6 +818,9 @@ cmFsRC_t _cmFileSysDirGetEntries( cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
|
|||||||
if( dirStr == NULL || strlen(dirStr) == 0 )
|
if( dirStr == NULL || strlen(dirStr) == 0 )
|
||||||
dirStr = curDirPtr;
|
dirStr = curDirPtr;
|
||||||
|
|
||||||
|
if( _cmFileSysIsDir(drp->p,dirStr) == false )
|
||||||
|
return rc;
|
||||||
|
|
||||||
unsigned fnCharCnt= strlen(dirStr) + PATH_MAX;
|
unsigned fnCharCnt= strlen(dirStr) + PATH_MAX;
|
||||||
char fn[ fnCharCnt + 1 ];
|
char fn[ fnCharCnt + 1 ];
|
||||||
|
|
||||||
@ -821,10 +844,10 @@ cmFsRC_t _cmFileSysDirGetEntries( cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
|
|||||||
if((dirp = opendir(dirStr)) == NULL)
|
if((dirp = opendir(dirStr)) == NULL)
|
||||||
{
|
{
|
||||||
rc = _cmFileSysError(drp->p,kOpenDirFailFsRC,errno,"Unable to open the directory:'%s'.",dirStr);
|
rc = _cmFileSysError(drp->p,kOpenDirFailFsRC,errno,"Unable to open the directory:'%s'.",dirStr);
|
||||||
|
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// get the next directory entry
|
// get the next directory entry
|
||||||
while((dp = readdir(dirp)) != NULL )
|
while((dp = readdir(dirp)) != NULL )
|
||||||
{
|
{
|
||||||
@ -873,6 +896,7 @@ cmFsRC_t _cmFileSysDirGetEntries( cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
|
|||||||
goto errLabel;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// is the entry a file
|
// is the entry a file
|
||||||
if( _cmFileSysIsFile(drp->p,fn) )
|
if( _cmFileSysIsFile(drp->p,fn) )
|
||||||
{
|
{
|
||||||
@ -895,9 +919,27 @@ cmFsRC_t _cmFileSysDirGetEntries( cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
|
|||||||
if((rc = _cmFileSysDirGetEntries(drp,fn)) != kOkFsRC )
|
if((rc = _cmFileSysDirGetEntries(drp,fn)) != kOkFsRC )
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( _cmFileSysIsLink(drp->p,fn) )
|
||||||
|
{
|
||||||
|
if( cmIsFlag(drp->filterFlags,kLinkFsFl) == false )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
flags |= kLinkFsFl;
|
||||||
|
|
||||||
|
if( cmIsFlag(drp->filterFlags,kRecurseLinksFsFl) )
|
||||||
|
if((rc = _cmFileSysDirGetEntries(drp,fn)) != kOkFsRC )
|
||||||
|
goto errLabel;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(flags != 0);
|
//assert(flags != 0);
|
||||||
|
|
||||||
if( drp->passIdx == 0 )
|
if( drp->passIdx == 0 )
|
||||||
{
|
{
|
||||||
@ -941,6 +983,9 @@ cmFsRC_t _cmFileSysDirGetEntries( cmFileSysDeRecd_t* drp, const cmChar_t* dirSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
errLabel:
|
errLabel:
|
||||||
|
if( dirp != NULL )
|
||||||
|
closedir(dirp);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -962,7 +1007,7 @@ cmFileSysDirEntry_t* cmFileSysDirEntries( cmFileSysH_t h, const cmChar_t* dirSt
|
|||||||
if((rc = _cmFileSysDirGetEntries( &r, dirStr )) != kOkFsRC )
|
if((rc = _cmFileSysDirGetEntries( &r, dirStr )) != kOkFsRC )
|
||||||
goto errLabel;
|
goto errLabel;
|
||||||
|
|
||||||
if( r.passIdx == 0 )
|
if( r.passIdx == 0 && r.dataByteCnt>0 )
|
||||||
{
|
{
|
||||||
// allocate memory to hold the return values
|
// allocate memory to hold the return values
|
||||||
if(( r.rp = (cmFileSysDirEntry_t *)cmLHeapAllocZ( r.p->heapH, r.dataByteCnt )) == NULL )
|
if(( r.rp = (cmFileSysDirEntry_t *)cmLHeapAllocZ( r.p->heapH, r.dataByteCnt )) == NULL )
|
||||||
|
18
cmFileSys.h
18
cmFileSys.h
@ -146,16 +146,18 @@ extern "C" {
|
|||||||
// Flags used by cmFileSysDirEntries 'includeFlags' parameter.
|
// Flags used by cmFileSysDirEntries 'includeFlags' parameter.
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
kFileFsFl = 0x01, //< include all visible files
|
kFileFsFl = 0x001, //< include all visible files
|
||||||
kDirFsFl = 0x02, //< include all visible directory
|
kDirFsFl = 0x002, //< include all visible directory
|
||||||
kInvisibleFsFl = 0x04, //< include file/dir name beginning with a '.'
|
kLinkFsFl = 0x004, //< include all symbolic links
|
||||||
kCurDirFsFl = 0x08, //< include '.' directory
|
kInvisibleFsFl = 0x008, //< include file/dir name beginning with a '.'
|
||||||
kParentDirFsFl = 0x10, //< include '..' directory
|
kCurDirFsFl = 0x010, //< include '.' directory
|
||||||
|
kParentDirFsFl = 0x020, //< include '..' directory
|
||||||
|
|
||||||
kAllFsFl = 0x1f, //< all type flags
|
kAllFsFl = 0x02f, //< all type flags
|
||||||
|
|
||||||
kFullPathFsFl = 0x40, //< return the full path in the 'name' field of cmFileSysDirEntry_t;
|
kFullPathFsFl = 0x040, //< return the full path in the 'name' field of cmFileSysDirEntry_t;
|
||||||
kRecurseFsFl = 0x80 //< recurse into directories
|
kRecurseFsFl = 0x080, //< recurse into directories
|
||||||
|
kRecurseLinksFsFl = 0x100 //< recurse into symbol link directories
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user