Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library Scanner: sort files before adding #10919

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/library/scanner/recursivescandirectorytask.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "library/scanner/recursivescandirectorytask.h"

#include <QCryptographicHash>
#include <QDirIterator>
#include <QDir>
#include <QFileInfo>

#include "library/scanner/importfilestask.h"
#include "library/scanner/libraryscanner.h"
Expand Down Expand Up @@ -34,8 +35,10 @@ void RecursiveScanDirectoryTask::run() {
// Filter from the QDir so we have to set it first. If the QDir has not done
// any FS operations yet then this should be lightweight.
auto dir = m_dirAccess.info().toQDir();
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
QDirIterator it(dir);
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot | QDir::System);
// sort directory by file name to increase chance that files are sorted sensible
dir.setSorting(QDir::SortFlag::DirsFirst | QDir::SortFlag::Name);
const QFileInfoList children = dir.entryInfoList();

std::list<QFileInfo> filesToImport;
std::list<QFileInfo> possibleCovers;
Expand All @@ -50,9 +53,8 @@ void RecursiveScanDirectoryTask::run() {
QRegularExpression supportedCoverExtensionsRegex =
m_scannerGlobal->supportedCoverExtensionsRegex();

while (it.hasNext()) {
QString currentFile = it.next();
QFileInfo currentFileInfo = it.fileInfo();
for (const auto& currentFileInfo : children) {
QString currentFile = currentFileInfo.filePath();

if (currentFileInfo.isFile()) {
const QString& fileName = currentFileInfo.fileName();
Expand Down