From 11d95d117b205ba5398567dfd25b025a776a3949 Mon Sep 17 00:00:00 2001 From: SulfurNitride Date: Wed, 11 Mar 2026 13:52:45 -0500 Subject: 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 --- src/src/modlistviewactions.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') 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. } } -- cgit v1.3.1