mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 17:10:41 +02:00
add folder rename handling
This commit is contained in:
parent
6abd1c50b2
commit
03c38eada3
1 changed files with 49 additions and 9 deletions
|
@ -511,6 +511,10 @@ bool AssetServer::setMapping(const AssetPath& path, const AssetHash& hash) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pathIsFolder(const AssetPath& path) {
|
||||||
|
return path.endsWith('/');
|
||||||
|
}
|
||||||
|
|
||||||
bool AssetServer::deleteMappings(const AssetPathList& paths) {
|
bool AssetServer::deleteMappings(const 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;
|
||||||
|
@ -538,23 +542,59 @@ bool AssetServer::deleteMappings(const AssetPathList& paths) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AssetServer::renameMapping(const AssetPath& oldPath, const AssetPath& newPath) {
|
bool AssetServer::renameMapping(const AssetPath& oldPath, const AssetPath& newPath) {
|
||||||
// take the old hash to remove the old mapping
|
if (pathIsFolder(oldPath)) {
|
||||||
auto oldMapping = _fileMappings[oldPath].toString();
|
if (!pathIsFolder(newPath)) {
|
||||||
|
// we were asked to rename a path to a folder to a path that isn't a folder, this is a fail
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!oldMapping.isEmpty()) {
|
// take a copy of the old mappings
|
||||||
_fileMappings[newPath] = oldMapping;
|
auto oldMappings = _fileMappings;
|
||||||
|
|
||||||
|
// iterate the current mappings and adjust any that matches the renamed folder
|
||||||
|
auto it = oldMappings.begin();
|
||||||
|
while (it != oldMappings.end()) {
|
||||||
|
|
||||||
|
if (it->toString().startsWith(oldPath)) {
|
||||||
|
auto oldKey = it.key();
|
||||||
|
auto newKey = oldKey.replace(0, oldPath.size(), newPath);
|
||||||
|
|
||||||
|
// remove the old version from the in memory file mappings
|
||||||
|
_fileMappings.remove(oldKey);
|
||||||
|
_fileMappings.insert(newKey, it.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
if (writeMappingsToFile()) {
|
if (writeMappingsToFile()) {
|
||||||
// persisted the renamed mapping, return success
|
// persisted the changed mappings return success
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// we couldn't persist the renamed mapping, rollback and return failure
|
// couldn't persist the renamed paths, rollback and return failure
|
||||||
_fileMappings[oldPath] = oldMapping;
|
_fileMappings = oldMappings;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// failed to find a mapping that was to be renamed, return failure
|
// take the old hash to remove the old mapping
|
||||||
return false;
|
auto oldMapping = _fileMappings[oldPath].toString();
|
||||||
|
|
||||||
|
if (!oldMapping.isEmpty()) {
|
||||||
|
_fileMappings[newPath] = oldMapping;
|
||||||
|
|
||||||
|
if (writeMappingsToFile()) {
|
||||||
|
// persisted the renamed mapping, return success
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
// we couldn't persist the renamed mapping, rollback and return failure
|
||||||
|
_fileMappings[oldPath] = oldMapping;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// failed to find a mapping that was to be renamed, return failure
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue