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

(fix) Library: allow adding new dirs while we have missing watched dir(s) #12937

Merged
merged 1 commit into from
Apr 15, 2024
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
24 changes: 10 additions & 14 deletions src/library/dao/directorydao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,25 @@ DirectoryDAO::AddResult DirectoryDAO::addDirectory(
const auto newCanonicalLocation = newDir.canonicalLocation();
DEBUG_ASSERT(!newCanonicalLocation.isEmpty());
QList<mixxx::FileInfo> obsoleteChildDirs;
for (auto&& oldDir : loadAllDirectories()) {
if (!oldDir.exists() || !oldDir.isDir()) {
// Abort to prevent inconsistencies in the database
kLogger.warning()
<< "Aborting to add"
<< newDir
<< ": Loaded directory"
<< oldDir
<< "does not exist or is inaccessible";
return AddResult::InvalidOrMissingDirectory;
}
// Ignore invalid or missing directories in order to allow adding new dirs
// while the list contains e.g. currently unmounted removable drives.
// Worst that can happen is that we have orphan tracks in the database that
// would be moved to missing after the rescan (which is required anyway after
// having added a new dir).
for (auto&& oldDir : loadAllDirectories(true)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, use the current implemantation but don't return if the old dir is missing. Instead, do the QString equivalent of mixxx::FileInfo::isRootSubCanonicalLocation(new, old) in that case.
This requires refactirng here, i.e. use DirectoryDAO::getRootDirStrings() added in #12878 and construct the mixxx::FileInfo here.

const auto oldCanonicalLocation = oldDir.canonicalLocation();
DEBUG_ASSERT(!oldCanonicalLocation.isEmpty());
if (mixxx::FileInfo::isRootSubCanonicalLocation(
oldCanonicalLocation,
newCanonicalLocation)) {
// New dir is a child of an existing dir, return
return AddResult::AlreadyWatching;
}
if (mixxx::FileInfo::isRootSubCanonicalLocation(
newCanonicalLocation,
oldCanonicalLocation)) {
// New dir is the parent of an existing dir. Remove the child from
// the dir list.
obsoleteChildDirs.append(std::move(oldDir));
}
}
Expand All @@ -92,9 +90,7 @@ DirectoryDAO::AddResult DirectoryDAO::addDirectory(
.arg(
kTable,
kLocationColumn);
FwdSqlQuery query(
m_database,
statement);
FwdSqlQuery query(m_database, statement);
query.bindValue(
QStringLiteral(":location"),
newDir.location());
Expand Down
Loading