mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 01:53:10 +02:00
add deletion of unmapped files during delete op
This commit is contained in:
parent
fae9b061a3
commit
775898893b
1 changed files with 29 additions and 0 deletions
|
@ -544,6 +544,8 @@ bool AssetServer::deleteMappings(AssetPathList& paths) {
|
||||||
// take a copy of the current mappings in case persistence of these deletes fails
|
// take a copy of the current mappings in case persistence of these deletes fails
|
||||||
auto oldMappings = _fileMappings;
|
auto oldMappings = _fileMappings;
|
||||||
|
|
||||||
|
QSet<QString> hashesToCheck;
|
||||||
|
|
||||||
// enumerate the paths to delete and remove them all
|
// enumerate the paths to delete and remove them all
|
||||||
for (auto& path : paths) {
|
for (auto& path : paths) {
|
||||||
|
|
||||||
|
@ -557,6 +559,9 @@ bool AssetServer::deleteMappings(AssetPathList& paths) {
|
||||||
|
|
||||||
while (it != _fileMappings.end()) {
|
while (it != _fileMappings.end()) {
|
||||||
if (it.key().startsWith(path)) {
|
if (it.key().startsWith(path)) {
|
||||||
|
// add this hash to the list we need to check for asset removal from the server
|
||||||
|
hashesToCheck << it.value().toString();
|
||||||
|
|
||||||
it = _fileMappings.erase(it);
|
it = _fileMappings.erase(it);
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
|
@ -583,6 +588,30 @@ bool AssetServer::deleteMappings(AssetPathList& paths) {
|
||||||
// deleted the old mappings, attempt to persist to file
|
// deleted the old mappings, attempt to persist to file
|
||||||
if (writeMappingsToFile()) {
|
if (writeMappingsToFile()) {
|
||||||
// persistence succeeded we are good to go
|
// persistence succeeded we are good to go
|
||||||
|
|
||||||
|
// grab the current mapped hashes
|
||||||
|
auto mappedHashes = _fileMappings.values();
|
||||||
|
|
||||||
|
// enumerate the mapped hashes and clear the list of hashes to check for anything that's present
|
||||||
|
for (auto& hashVariant : mappedHashes) {
|
||||||
|
auto it = hashesToCheck.find(hashVariant.toString());
|
||||||
|
if (it != hashesToCheck.end()) {
|
||||||
|
hashesToCheck.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// we now have a set of hashes that are unmapped - we will delete those asset files
|
||||||
|
for (auto& hash : hashesToCheck) {
|
||||||
|
// remove the unmapped file
|
||||||
|
QFile removeableFile { _filesDirectory.absoluteFilePath(hash) };
|
||||||
|
|
||||||
|
if (removeableFile.remove()) {
|
||||||
|
qDebug() << "\tDeleted" << hash << "from asset files directory since it is now unmapped.";
|
||||||
|
} else {
|
||||||
|
qDebug() << "\tAttempt to delete unmapped file" << hash << "failed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to persist deleted mappings, rolling back";
|
qWarning() << "Failed to persist deleted mappings, rolling back";
|
||||||
|
|
Loading…
Reference in a new issue