mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-06-09 00:25:04 -06:00
ISO: Clean up orphaned cache entries after game list scan
This commit is contained in:
parent
5903612adc
commit
1c5bd20d80
@ -6,6 +6,8 @@
|
|||||||
#include "util/fnv_hash.hpp"
|
#include "util/fnv_hash.hpp"
|
||||||
#include "Utilities/File.h"
|
#include "Utilities/File.h"
|
||||||
|
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
LOG_CHANNEL(iso_cache_log, "ISOCache");
|
LOG_CHANNEL(iso_cache_log, "ISOCache");
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -128,4 +130,30 @@ namespace iso_cache
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanup(const std::unordered_set<std::string>& valid_iso_paths)
|
||||||
|
{
|
||||||
|
const std::string dir = get_cache_dir();
|
||||||
|
|
||||||
|
// Build a set of stems that should exist.
|
||||||
|
std::unordered_set<std::string> valid_stems;
|
||||||
|
for (const std::string& path : valid_iso_paths)
|
||||||
|
{
|
||||||
|
valid_stems.insert(get_cache_stem(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete any cache files whose stem is not in the valid set.
|
||||||
|
fs::dir cache_dir(dir);
|
||||||
|
fs::dir_entry entry{};
|
||||||
|
while (cache_dir.read(entry))
|
||||||
|
{
|
||||||
|
if (entry.name == "." || entry.name == "..") continue;
|
||||||
|
|
||||||
|
const std::string stem = entry.name.substr(0, entry.name.find_last_of('.'));
|
||||||
|
if (valid_stems.find(stem) == valid_stems.end())
|
||||||
|
{
|
||||||
|
fs::remove_file(dir + entry.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -5,6 +5,7 @@
|
|||||||
#include "util/types.hpp"
|
#include "util/types.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Cached metadata extracted from an ISO during game list scanning.
|
// Cached metadata extracted from an ISO during game list scanning.
|
||||||
@ -25,4 +26,7 @@ namespace iso_cache
|
|||||||
|
|
||||||
// Persists a populated cache entry to disk.
|
// Persists a populated cache entry to disk.
|
||||||
void save(const std::string& iso_path, const iso_metadata_cache_entry& entry);
|
void save(const std::string& iso_path, const iso_metadata_cache_entry& entry);
|
||||||
|
|
||||||
|
// Remove cache entries for ISOs that are no longer in the scanned set.
|
||||||
|
void cleanup(const std::unordered_set<std::string>& valid_iso_paths);
|
||||||
}
|
}
|
||||||
@ -542,6 +542,9 @@ void game_list_frame::OnParsingFinished()
|
|||||||
{
|
{
|
||||||
archive = std::make_unique<iso_archive>(dir_or_elf);
|
archive = std::make_unique<iso_archive>(dir_or_elf);
|
||||||
}
|
}
|
||||||
|
// Track this ISO path for cache cleanup after scan completes.
|
||||||
|
std::lock_guard lock(m_path_mutex);
|
||||||
|
m_scanned_iso_paths.insert(dir_or_elf);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto file_exists = [&archive, &cache_entry](const std::string& path)
|
const auto file_exists = [&archive, &cache_entry](const std::string& path)
|
||||||
@ -892,6 +895,9 @@ void game_list_frame::OnRefreshFinished()
|
|||||||
WaitAndAbortSizeCalcThreads();
|
WaitAndAbortSizeCalcThreads();
|
||||||
WaitAndAbortRepaintThreads();
|
WaitAndAbortRepaintThreads();
|
||||||
|
|
||||||
|
// Remove cache entries for ISOs that are no longer present in the scanned paths.
|
||||||
|
iso_cache::cleanup(m_scanned_iso_paths);
|
||||||
|
|
||||||
for (auto&& g : m_games.pop_all())
|
for (auto&& g : m_games.pop_all())
|
||||||
{
|
{
|
||||||
m_game_data.push_back(g);
|
m_game_data.push_back(g);
|
||||||
@ -978,6 +984,7 @@ void game_list_frame::OnRefreshFinished()
|
|||||||
m_serials.clear();
|
m_serials.clear();
|
||||||
m_path_list.clear();
|
m_path_list.clear();
|
||||||
m_path_entries.clear();
|
m_path_entries.clear();
|
||||||
|
m_scanned_iso_paths.clear();
|
||||||
|
|
||||||
Refresh();
|
Refresh();
|
||||||
|
|
||||||
|
|||||||
@ -181,6 +181,7 @@ private:
|
|||||||
std::vector<path_entry> m_path_entries;
|
std::vector<path_entry> m_path_entries;
|
||||||
shared_mutex m_path_mutex;
|
shared_mutex m_path_mutex;
|
||||||
std::set<std::string> m_path_list;
|
std::set<std::string> m_path_list;
|
||||||
|
std::unordered_set<std::string> m_scanned_iso_paths;
|
||||||
QSet<QString> m_serials;
|
QSet<QString> m_serials;
|
||||||
QMutex m_games_mutex;
|
QMutex m_games_mutex;
|
||||||
lf_queue<game_info> m_games;
|
lf_queue<game_info> m_games;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user