From 564fca8c9b3077335a1ea00b1dc803c97429f5b3 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 7 May 2026 20:36:46 +0500 Subject: [PATCH] fix: don't delete base directories when evicting metacache Signed-off-by: Octol1ttle --- launcher/FileSystem.cpp | 26 ++++++++++++++++++++++++++ launcher/FileSystem.h | 7 +++++++ launcher/net/HttpMetaCache.cpp | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 938ef23e4..ef56e3e65 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -684,6 +684,32 @@ bool deletePath(QString path) return err.value() == 0; } +bool deleteContents(const QString& path) +{ + const QFileInfo info(path); + if (!info.exists()) { + return true; + } + if (!info.isDir()) { + qWarning() << "Attempted to delete contents of non-directory path:" << path; + return false; + } + + bool ret = true; + + for (const auto& entry : fs::directory_iterator(StringUtils::toStdString(path))) { + std::error_code err; + + fs::remove_all(entry.path(), err); + if (err.value() != 0) { + qWarning().nospace() << "Could not delete directory entry " << entry.path() << ": " << QString::fromStdString(err.message()); + ret = false; + } + } + + return ret; +} + bool trash(QString path, QString* pathInTrash) { // FIXME: Figure out trash in Flatpak. Qt seemingly doesn't use the Trash portal diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index f2676b147..6d9b01178 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -291,6 +291,13 @@ bool move(const QString& source, const QString& dest); */ bool deletePath(QString path); +/** + * Delete a folder's contents recursively but not the folder itself. + * @param path The path to the folder. + * @return Whether the deletion was completely successful. + */ +bool deleteContents(const QString& path); + bool removeFiles(QStringList listFile); /** diff --git a/launcher/net/HttpMetaCache.cpp b/launcher/net/HttpMetaCache.cpp index 6b81bfe0d..5c1e47dfd 100644 --- a/launcher/net/HttpMetaCache.cpp +++ b/launcher/net/HttpMetaCache.cpp @@ -182,7 +182,7 @@ auto HttpMetaCache::evictAll() -> bool } map.entry_list.clear(); // AND all return codes together so the result is true iff all runs of deletePath() are true - ret &= FS::deletePath(map.base_path); + ret &= FS::deleteContents(map.base_path); } return ret; }