Skip to content

Commit

Permalink
ENH: Follow symlinks in dicom indexing (#1066)
Browse files Browse the repository at this point in the history
Enabled by default, but settable as a property.

Fixes #1065
  • Loading branch information
pieper authored Feb 22, 2023
1 parent 2daac1c commit 3286ac3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Libs/DICOM/Core/ctkDICOMIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ void ctkDICOMIndexerPrivateWorker::processIndexingRequest(DICOMIndexingQueue::In
{
filters |= QDir::Hidden;
}
QDirIterator it(indexingRequest.inputFolderPath, filters, QDirIterator::Subdirectories);
QDirIterator::IteratorFlags flags = QDirIterator::Subdirectories;
if (indexingRequest.followSymlinks)
{
flags |= QDirIterator::FollowSymlinks;
}
QDirIterator it(indexingRequest.inputFolderPath, filters, flags);
while (it.hasNext())
{
indexingRequest.inputFilesPath << it.next();
Expand Down Expand Up @@ -284,10 +289,11 @@ ctkDICOMIndexerPrivate::ctkDICOMIndexerPrivate(ctkDICOMIndexer& o)
: q_ptr(&o)
, Database(nullptr)
, BackgroundImportEnabled(false)
, FollowSymlinks(true)
{
ctkDICOMIndexerPrivateWorker* worker = new ctkDICOMIndexerPrivateWorker(&this->RequestQueue);
worker->moveToThread(&this->WorkerThread);

connect(&this->WorkerThread, &QThread::finished, worker, &QObject::deleteLater);
connect(this, &ctkDICOMIndexerPrivate::startWorker, worker, &ctkDICOMIndexerPrivateWorker::start);

Expand Down Expand Up @@ -331,6 +337,10 @@ void ctkDICOMIndexerPrivate::pushIndexingRequest(const DICOMIndexingQueue::Index
CTK_GET_CPP(ctkDICOMIndexer, bool, isBackgroundImportEnabled, BackgroundImportEnabled);
CTK_SET_CPP(ctkDICOMIndexer, bool, setBackgroundImportEnabled, BackgroundImportEnabled);

//------------------------------------------------------------------------------
CTK_GET_CPP(ctkDICOMIndexer, bool, followSymlinks, FollowSymlinks);
CTK_SET_CPP(ctkDICOMIndexer, bool, setFollowSymlinks, FollowSymlinks);

//------------------------------------------------------------------------------
// ctkDICOMIndexer methods

Expand Down Expand Up @@ -398,7 +408,7 @@ ctkDICOMDatabase* ctkDICOMIndexer::database()
d->RequestQueue.setDatabaseFilename(QString());
}
}

//------------------------------------------------------------------------------
void ctkDICOMIndexer::tagsToPrecacheChanged()
{
Expand Down Expand Up @@ -433,7 +443,7 @@ ctkDICOMDatabase* ctkDICOMIndexer::database()
this->setDatabase(db);
this->addFile(filePath, copyFile);
}

//------------------------------------------------------------------------------
void ctkDICOMIndexer::addFile(const QString filePath, bool copyFile/*=false*/)
{
Expand Down Expand Up @@ -473,6 +483,7 @@ void ctkDICOMIndexer::addDirectory(const QString& directoryName, bool copyFile/*
request.inputFolderPath = directoryName;
request.includeHidden = includeHidden;
request.copyFile = copyFile;
request.followSymlinks = d->FollowSymlinks;
d->pushIndexingRequest(request);
}
if (!d->BackgroundImportEnabled)
Expand Down
7 changes: 7 additions & 0 deletions Libs/DICOM/Core/ctkDICOMIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMIndexer : public QObject
{
Q_OBJECT
Q_PROPERTY(bool backgroundImportEnabled READ isBackgroundImportEnabled WRITE setBackgroundImportEnabled)
Q_PROPERTY(bool followSymlinks READ followSymlinks WRITE setFollowSymlinks)
Q_PROPERTY(bool importing READ isImporting)

public:
Expand All @@ -54,6 +55,12 @@ class CTK_DICOM_CORE_EXPORT ctkDICOMIndexer : public QObject
void setBackgroundImportEnabled(bool);
bool isBackgroundImportEnabled() const;

/// If enabled, addDirectory will follow symbolic links
/// on systems that support them.
/// Enabled by default.
void setFollowSymlinks(bool);
bool followSymlinks() const;

/// Returns with true if background importing is currently in progress.
bool isImporting();

Expand Down
3 changes: 3 additions & 0 deletions Libs/DICOM/Core/ctkDICOMIndexer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class DICOMIndexingQueue
/// Make a copy of the indexed file into the database.
/// If false then only a link to the existing file is added.
bool copyFile;
/// Follow symlinks on platforms that support it.
bool followSymlinks;
};

DICOMIndexingQueue()
Expand Down Expand Up @@ -264,6 +266,7 @@ class ctkDICOMIndexerPrivate : public QObject
QThread WorkerThread;
ctkDICOMDatabase* Database;
bool BackgroundImportEnabled;
bool FollowSymlinks;
};


Expand Down

0 comments on commit 3286ac3

Please sign in to comment.