mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 07:15:49 +00:00
Check for and remove cached hashes not in folder
This commit is contained in:
parent
7a439bb5b9
commit
0bb18de9f6
@ -94,10 +94,12 @@ void TResourceManager::RefreshFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (modsDB.contains(entry.path().filename().string())) {
|
if (modsDB.contains(entry.path().filename().string())) {
|
||||||
auto dbEntry = modsDB[entry.path().filename().string()];
|
auto& dbEntry = modsDB[entry.path().filename().string()];
|
||||||
if (entry.last_write_time().time_since_epoch().count() > dbEntry["lastwrite"] || std::filesystem::file_size(File) != dbEntry["filesize"].get<size_t>()) {
|
if (entry.last_write_time().time_since_epoch().count() > dbEntry["lastwrite"] || std::filesystem::file_size(File) != dbEntry["filesize"].get<size_t>()) {
|
||||||
beammp_infof("File '{}' has been modified, rehashing", File);
|
beammp_infof("File '{}' has been modified, rehashing", File);
|
||||||
} else {
|
} else {
|
||||||
|
dbEntry["exists"] = true;
|
||||||
|
|
||||||
mMods.push_back(nlohmann::json {
|
mMods.push_back(nlohmann::json {
|
||||||
{ "file_name", std::filesystem::path(File).filename() },
|
{ "file_name", std::filesystem::path(File).filename() },
|
||||||
{ "file_size", std::filesystem::file_size(File) },
|
{ "file_size", std::filesystem::file_size(File) },
|
||||||
@ -178,7 +180,8 @@ void TResourceManager::RefreshFiles() {
|
|||||||
{ "lastwrite", entry.last_write_time().time_since_epoch().count() },
|
{ "lastwrite", entry.last_write_time().time_since_epoch().count() },
|
||||||
{ "hash", result },
|
{ "hash", result },
|
||||||
{ "filesize", std::filesystem::file_size(File) },
|
{ "filesize", std::filesystem::file_size(File) },
|
||||||
{ "protected", false }
|
{ "protected", false },
|
||||||
|
{ "exists", true }
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
@ -186,6 +189,15 @@ void TResourceManager::RefreshFiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto it = modsDB.begin(); it != modsDB.end(); ) {
|
||||||
|
if (!it.value().contains("exists")) {
|
||||||
|
it = modsDB.erase(it);
|
||||||
|
} else {
|
||||||
|
it.value().erase("exists");
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::ofstream stream(Path + "/mods.json");
|
std::ofstream stream(Path + "/mods.json");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user