diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 4c6cba2e74..509f8095c9 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -394,6 +394,7 @@ void AssetServer::completeSetup() { if (_fileMappings.size() > 0) { cleanupUnmappedFiles(); + cleanupBakedFilesForDeletedAssets(); } nodeList->addSetOfNodeTypesToNodeInterestSet({ NodeType::Agent, NodeType::EntityScriptServer }); @@ -473,7 +474,7 @@ void AssetServer::replayRequests() { } void AssetServer::cleanupUnmappedFiles() { - QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(AssetUtils::SHA256_HASH_HEX_LENGTH) + "}" }; + QRegExp hashFileRegex { AssetUtils::ASSET_HASH_REGEX_STRING }; auto files = _filesDirectory.entryInfoList(QDir::Files); @@ -505,6 +506,38 @@ void AssetServer::cleanupUnmappedFiles() { } } +void AssetServer::cleanupBakedFilesForDeletedAssets() { + qCInfo(asset_server) << "Performing baked asset cleanup for deleted assets"; + + std::set bakedHashes; + + for (auto it : _fileMappings) { + // check if this is a mapping to baked content + if (it.first.startsWith(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER)) { + // extract the hash from the baked mapping + AssetUtils::AssetHash hash = it.first.mid(AssetUtils::HIDDEN_BAKED_CONTENT_FOLDER.length(), + AssetUtils::SHA256_HASH_HEX_LENGTH); + + // add the hash to our set of hashes for which we have baked content + bakedHashes.insert(hash); + } + } + + // enumerate the hashes for which we have baked content + for (auto hash : bakedHashes) { + // check if we have a mapping that points to this hash + auto matchingMapping = std::find_if(std::begin(_fileMappings), std::end(_fileMappings), + [&hash](const std::pair mappingPair) { + return mappingPair.second == hash; + }); + + if (matchingMapping == std::end(_fileMappings)) { + // we didn't find a mapping for this hash, remove any baked content we still have for it + removeBakedPathsForDeletedAsset(hash); + } + } +} + void AssetServer::handleAssetMappingOperation(QSharedPointer message, SharedNodePointer senderNode) { using AssetMappingOperationType = AssetUtils::AssetMappingOperationType; diff --git a/assignment-client/src/assets/AssetServer.h b/assignment-client/src/assets/AssetServer.h index c85fb89175..f5a7d5f2da 100644 --- a/assignment-client/src/assets/AssetServer.h +++ b/assignment-client/src/assets/AssetServer.h @@ -88,6 +88,9 @@ private: /// Delete any unmapped files from the local asset directory void cleanupUnmappedFiles(); + /// Delete any baked files for assets removed from the local asset directory + void cleanupBakedFilesForDeletedAssets(); + QString getPathToAssetHash(const AssetUtils::AssetHash& assetHash); std::pair getAssetStatus(const AssetUtils::AssetPath& path, const AssetUtils::AssetHash& hash);