Prevent symlink loop when indexing
This commit is contained in:
+16
-7
@@ -156,23 +156,29 @@ int Database::checkVersion()
|
|||||||
|
|
||||||
static QStringList nameFilters = {"*.fit", "*.fits", "*.xisf"};
|
static QStringList nameFilters = {"*.fit", "*.fits", "*.xisf"};
|
||||||
|
|
||||||
static int countFiles(const QDir &dir, int count = 0)
|
static int countFiles(const QDir &dir, QStringList &scannedDirs)
|
||||||
{
|
{
|
||||||
count += dir.entryList(nameFilters, QDir::Files).size();
|
if(scannedDirs.contains(dir.canonicalPath()))return 0;
|
||||||
|
scannedDirs.append(dir.canonicalPath());
|
||||||
|
|
||||||
|
int count = dir.entryList(nameFilters, QDir::Files).size();
|
||||||
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
for(const QString &d : dirs)
|
for(const QString &d : dirs)
|
||||||
count += countFiles(dir.filePath(d));
|
count += countFiles(dir.filePath(d), scannedDirs);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::indexDir(const QDir &dir, QProgressDialog *progress)
|
void Database::indexDir(const QDir &dir, QProgressDialog *progress)
|
||||||
{
|
{
|
||||||
m_progress = 0;
|
m_progress = 0;
|
||||||
int count = countFiles(dir);
|
QStringList scannedDirs;
|
||||||
|
int count = countFiles(dir, scannedDirs);
|
||||||
progress->setMaximum(count);
|
progress->setMaximum(count);
|
||||||
QSqlDatabase database = QSqlDatabase::database();
|
QSqlDatabase database = QSqlDatabase::database();
|
||||||
database.transaction();
|
database.transaction();
|
||||||
if(indexDir2(dir, progress))
|
|
||||||
|
scannedDirs.clear();
|
||||||
|
if(indexDir2(dir, progress, scannedDirs))
|
||||||
{
|
{
|
||||||
database.commit();
|
database.commit();
|
||||||
emit databaseChanged();
|
emit databaseChanged();
|
||||||
@@ -225,14 +231,17 @@ QStringList Database::getFitsKeywords()
|
|||||||
return keywords;
|
return keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Database::indexDir2(const QDir &dir, QProgressDialog *progress)
|
bool Database::indexDir2(const QDir &dir, QProgressDialog *progress, QStringList &scannedDirs)
|
||||||
{
|
{
|
||||||
|
if(scannedDirs.contains(dir.canonicalPath()))return true;
|
||||||
|
scannedDirs.append(dir.canonicalPath());
|
||||||
|
|
||||||
QFileInfoList files = dir.entryInfoList(nameFilters, QDir::Files);
|
QFileInfoList files = dir.entryInfoList(nameFilters, QDir::Files);
|
||||||
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
|
|
||||||
for(const QString &d : dirs)
|
for(const QString &d : dirs)
|
||||||
{
|
{
|
||||||
if(!indexDir2(dir.filePath(d), progress))
|
if(!indexDir2(dir.filePath(d), progress, scannedDirs))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(const QFileInfo &file : files)
|
for(const QFileInfo &file : files)
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ public:
|
|||||||
void reindex(QProgressDialog *progress);
|
void reindex(QProgressDialog *progress);
|
||||||
QStringList getFitsKeywords();
|
QStringList getFitsKeywords();
|
||||||
protected:
|
protected:
|
||||||
bool indexDir2(const QDir &dir, QProgressDialog *progress);
|
bool indexDir2(const QDir &dir, QProgressDialog *progress, QStringList &scannedDirs);
|
||||||
bool indexFile(const QFileInfo &file);
|
bool indexFile(const QFileInfo &file);
|
||||||
bool checkError(QSqlQuery &query);
|
bool checkError(QSqlQuery &query);
|
||||||
int checkVersion();
|
int checkVersion();
|
||||||
|
|||||||
Reference in New Issue
Block a user