added param to folderIterator to skip/follow symbolic links

This commit is contained in:
csoler 2016-11-16 21:41:32 +01:00
parent 608d0d0a65
commit 6272856b5e
7 changed files with 27 additions and 7 deletions

View file

@ -16,8 +16,8 @@
namespace librs { namespace util {
FolderIterator::FolderIterator(const std::string& folderName)
: mFolderName(folderName)
FolderIterator::FolderIterator(const std::string& folderName,bool allow_symlinks)
: mFolderName(folderName),mAllowSymLinks(allow_symlinks)
{
is_open = false ;
validity = false ;
@ -112,6 +112,19 @@ bool FolderIterator::updateFileInfo(bool& should_skip)
mFullPath = mFolderName + "/" + mFileName ;
if( ent->d_type == DT_LNK && !mAllowSymLinks)
{
std::cerr << "(II) Skipping symbolic link " << mFullPath << std::endl;
should_skip = true ;
return true ;
}
else if( ent->d_type != DT_DIR && ent->d_type != DT_REG)
{
std::cerr << "(II) Skipping file of unknown type " << ent->d_type << ": " << mFullPath << std::endl;
should_skip = true ;
return true ;
}
struct stat64 buf ;
#ifdef DEBUG_FOLDER_ITERATOR

View file

@ -22,7 +22,7 @@ namespace librs { namespace util {
class FolderIterator
{
public:
FolderIterator(const std::string& folderName);
FolderIterator(const std::string& folderName,bool allow_symlinks);
~FolderIterator();
enum { TYPE_UNKNOWN = 0x00,
@ -68,6 +68,7 @@ private:
std::string mFileName ;
std::string mFullPath ;
std::string mFolderName ;
bool mAllowSymLinks;
};

View file

@ -438,7 +438,7 @@ bool RsDirUtil::checkCreateDirectory(const std::string& dir)
bool RsDirUtil::cleanupDirectory(const std::string& cleandir, const std::set<std::string> &keepFiles)
{
for(librs::util::FolderIterator it(cleandir);it.isValid();it.next())
for(librs::util::FolderIterator it(cleandir,false);it.isValid();it.next())
if(it.file_type() == librs::util::FolderIterator::TYPE_FILE && (keepFiles.end() == std::find(keepFiles.begin(), keepFiles.end(), it.file_name())))
remove( (cleandir + "/" + it.file_name()).c_str() ) ;