aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSulfurNitride <SulfurNitride@users.noreply.github.com>2026-03-11 13:52:45 -0500
committerSulfurNitride <SulfurNitride@users.noreply.github.com>2026-03-11 13:52:45 -0500
commit11d95d117b205ba5398567dfd25b025a776a3949 (patch)
tree086fecd49c4bbee67e73d2335ff54363d7ab959c /src
parent853a1f6259ea08f051e678276e95c4488d60efa4 (diff)
Fix empty directory cleanup after overwrite move
Sort directories by path length descending (deepest first) before rmdir, so leaf directories like NVSE/Plugins/Tweaks/INIs are removed before their parents. The previous prepend approach didn't guarantee depth-first order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src')
-rw-r--r--src/src/modlistviewactions.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/src/modlistviewactions.cpp b/src/src/modlistviewactions.cpp
index 040da79..df8417e 100644
--- a/src/src/modlistviewactions.cpp
+++ b/src/src/modlistviewactions.cpp
@@ -1377,14 +1377,18 @@ void ModListViewActions::moveOverwriteContentsTo(const QString& absolutePath) co
}
// Clean up empty directories left behind in overwrite.
+ // Sort by path length descending so leaf dirs are removed before parents.
if (movedCount > 0) {
QDirIterator dirIter(overwritePath, QDir::Dirs | QDir::NoDotAndDotDot,
QDirIterator::Subdirectories);
- QStringList emptyDirs;
+ QStringList dirs;
while (dirIter.hasNext()) {
- emptyDirs.prepend(dirIter.next()); // Reverse order for leaf-first deletion.
+ dirs.append(dirIter.next());
}
- for (const auto& dir : emptyDirs) {
+ std::sort(dirs.begin(), dirs.end(), [](const QString& a, const QString& b) {
+ return a.length() > b.length();
+ });
+ for (const auto& dir : dirs) {
QDir(dir).rmdir("."); // Only removes if empty.
}
}