/** \fn ImageScanThread::SyncFilesFromDir(QString &, int) * \brief Loads all available files from the path on the * backend and syncs depending if they are a directory or file * \param path The current directory with the files that shall be scanned syncronized * \param parentId The id of the parent directory which is required for possible subdirectories * \param baseDirectory The current root storage group path, this will be stripped before insertion into the database * \return void */ void ImageScanThread::SyncFilesFromDir(QString &path, int parentId, const QString &baseDirectory) { if (!m_continue) { LOG(VB_FILE, LOG_DEBUG, QString("Syncing from SG dir %1 interrupted").arg(path)); return; } LOG(VB_FILE, LOG_DEBUG, QString("Syncing from SG dir %1").arg(path)); QDir dir(path); if (!dir.exists()) return; // Only get files and dirs, no special and hidden stuff dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks); QFileInfoList list = dir.entryInfoList(); if (list.isEmpty()) return; for (QFileInfoList::iterator it = list.begin(); it != list.end(); ++it) { if (!m_continue) { LOG(VB_FILE, LOG_DEBUG, QString("Syncing from SG dir %1 interrupted").arg(path)); return; } QFileInfo fileInfo = *it; if (fileInfo.isDir()) { // Get the id. This will be new parent id // when we traverse down the current directory. int id = SyncDirectory(fileInfo, parentId, baseDirectory); // Get new files within this directory QString fileName = fileInfo.absoluteFilePath(); SyncFilesFromDir(fileName, id, baseDirectory); } else { SyncFile(fileInfo, parentId, baseDirectory); } // Increase the current progress count in case a // progressbar is used to show the sync progress if (m_progressTotalCount > m_progressCount) ++m_progressCount; } }
void ImageScanThread<DBFS>::SyncSubTree(const QFileInfo &dirInfo, int parentId, int devId, const QString &base) { // Ignore excluded dirs if (MATCHES(m_exclusions, dirInfo.fileName())) { LOG(VB_FILE, LOG_INFO, QString("Excluding dir %1").arg(dirInfo.absoluteFilePath())); return; } // Use global image filters QDir dir = m_dir; if (!dir.cd(dirInfo.absoluteFilePath())) { LOG(VB_FILE, LOG_INFO, QString("Failed to open dir %1").arg(dirInfo.absoluteFilePath())); return; } // Create directory node int id = SyncDirectory(dirInfo, devId, base, parentId); // Sync its contents QFileInfoList list = dir.entryInfoList(); foreach(const QFileInfo &fileInfo, list) { if (!IsScanning()) { LOG(VB_GENERAL, LOG_INFO, QString("Scan interrupted in %2").arg(dirInfo.absoluteFilePath())); return; } if (fileInfo.isDir()) { // Scan this directory SyncSubTree(fileInfo, id, devId, base); } else { SyncFile(fileInfo, devId, base, id); QMutexLocker locker(&m_mutexProgress); ++m_progressCount; // Throttle updates if (m_bcastTimer.elapsed() > 250) Broadcast(m_progressCount); } } }