protect mapping clobbering when migrating

This commit is contained in:
Stephen Birarda 2016-03-07 14:46:54 -08:00
parent 18b22cbd16
commit 82cd8aed8c

View file

@ -150,6 +150,8 @@ void AssetServer::performMappingMigration() {
auto files = _resourcesDirectory.entryInfoList(QDir::Files);
bool addedAtLeastOneMapping = false;
for (const auto& fileInfo : files) {
if (hashFileRegex.exactMatch(fileInfo.fileName())) {
// we have a pre-mapping file that we should migrate to the new mapping system
@ -177,10 +179,23 @@ void AssetServer::performMappingMigration() {
auto hash = oldFilename.left(SHA256_HASH_HEX_LENGTH);
qDebug() << "Adding a migration mapping from" << fakeFileName << "to" << hash;
_fileMapping[fakeFileName] = hash;
auto it = _fileMapping.find(fakeFileName);
if (it == _fileMapping.end()) {
_fileMapping[fakeFileName] = hash;
addedAtLeastOneMapping = true;
} else {
qDebug() << "Could not add migration mapping for" << hash << "since a mapping for" << fakeFileName
<< "already exists.";
}
}
}
}
if (addedAtLeastOneMapping) {
// we added at least one new mapping - let's persist changes to file
}
}
void AssetServer::handleAssetMappingOperation(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {