mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-22 20:59:45 -04:00
fixed folder iterator to properly handle broken symbolic links
This commit is contained in:
parent
be6370ef13
commit
1125dfe6d1
2 changed files with 62 additions and 42 deletions
|
@ -144,7 +144,7 @@ public:
|
||||||
|
|
||||||
bool searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results);
|
bool searchHash(const RsFileHash& hash,std::list<DirectoryStorage::EntryIndex>& results);
|
||||||
int searchBoolExp(RsRegularExpression::Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
int searchBoolExp(RsRegularExpression::Expression * exp, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
||||||
int searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const ;
|
int searchTerms(const std::list<std::string>& terms, std::list<DirectoryStorage::EntryIndex> &results) const ; // does a logical OR between items of the list of terms
|
||||||
|
|
||||||
bool check(std::string& error_string) const ;// checks consistency of storage.
|
bool check(std::string& error_string) const ;// checks consistency of storage.
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "folderiterator.h"
|
#include "folderiterator.h"
|
||||||
#include "rsstring.h"
|
#include "rsstring.h"
|
||||||
|
|
||||||
|
#define DEBUG_FOLDER_ITERATOR 1
|
||||||
|
|
||||||
namespace librs { namespace util {
|
namespace librs { namespace util {
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,57 +61,75 @@ FolderIterator::~FolderIterator()
|
||||||
|
|
||||||
void FolderIterator::next()
|
void FolderIterator::next()
|
||||||
{
|
{
|
||||||
do {
|
while(readdir())
|
||||||
if(!readdir())
|
{
|
||||||
{
|
|
||||||
validity = false ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
|
|
||||||
d_name(mFileName);
|
d_name(mFileName);
|
||||||
} while(mFileName == "." || mFileName == "..") ;
|
|
||||||
|
|
||||||
mFullPath = mFolderName + "/" + mFileName ;
|
if(mFileName == "." || mFileName == "..")
|
||||||
|
continue ;
|
||||||
|
|
||||||
struct stat64 buf ;
|
mFullPath = mFolderName + "/" + mFileName ;
|
||||||
|
|
||||||
|
struct stat64 buf ;
|
||||||
|
|
||||||
|
#ifdef DEBUG_FOLDER_ITERATOR
|
||||||
|
std::cerr << "FolderIterator: next. Looking into file " << mFileName ;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WINDOWS_SYS
|
#ifdef WINDOWS_SYS
|
||||||
std::wstring wfullname;
|
std::wstring wfullname;
|
||||||
librs::util::ConvertUtf8ToUtf16(mFullPath, wfullname);
|
librs::util::ConvertUtf8ToUtf16(mFullPath, wfullname);
|
||||||
if ( 0 == _wstati64(wfullname.c_str(), &buf))
|
if ( 0 == _wstati64(wfullname.c_str(), &buf))
|
||||||
#else
|
#else
|
||||||
if ( 0 == stat64(mFullPath.c_str(), &buf))
|
if ( 0 == stat64(mFullPath.c_str(), &buf))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
mFileModTime = buf.st_mtime ;
|
mFileModTime = buf.st_mtime ;
|
||||||
mStatInfoOk = true;
|
mStatInfoOk = true;
|
||||||
|
|
||||||
if (S_ISDIR(buf.st_mode))
|
if (S_ISDIR(buf.st_mode))
|
||||||
{
|
{
|
||||||
mType = TYPE_DIR ;
|
#ifdef DEBUG_FOLDER_ITERATOR
|
||||||
mFileSize = 0 ;
|
std::cerr << ": is a directory" << std::endl;
|
||||||
mFileModTime = buf.st_mtime;
|
#endif
|
||||||
}
|
|
||||||
else if (S_ISREG(buf.st_mode))
|
mType = TYPE_DIR ;
|
||||||
{
|
mFileSize = 0 ;
|
||||||
mType = TYPE_FILE ;
|
mFileModTime = buf.st_mtime;
|
||||||
mFileSize = buf.st_size;
|
|
||||||
mFileModTime = buf.st_mtime;
|
return ;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (S_ISREG(buf.st_mode))
|
||||||
mType = TYPE_UNKNOWN ;
|
{
|
||||||
mFileSize = 0 ;
|
#ifdef DEBUG_FOLDER_ITERATOR
|
||||||
mFileModTime = 0;
|
std::cerr << ": is a file" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mType = TYPE_FILE ;
|
||||||
|
mFileSize = buf.st_size;
|
||||||
|
mFileModTime = buf.st_mtime;
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_FOLDER_ITERATOR
|
||||||
|
std::cerr << ": is unknown skipping" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mType = TYPE_UNKNOWN ;
|
||||||
|
mFileSize = 0 ;
|
||||||
|
mFileModTime = 0;
|
||||||
}
|
}
|
||||||
else
|
#ifdef DEBUG_FOLDER_ITERATOR
|
||||||
{
|
std::cerr << "End of directory." << std::endl;
|
||||||
mType = TYPE_UNKNOWN ;
|
#endif
|
||||||
mFileSize = 0 ;
|
|
||||||
mFileModTime = 0;
|
mType = TYPE_UNKNOWN ;
|
||||||
validity = false ;
|
mFileSize = 0 ;
|
||||||
}
|
mFileModTime = 0;
|
||||||
|
validity = false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FolderIterator::readdir()
|
bool FolderIterator::readdir()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue