mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 11:08:06 +02:00
add simple cleanup of unmapped assets on start
This commit is contained in:
parent
a7f93aa75c
commit
882a0272c0
2 changed files with 33 additions and 0 deletions
|
@ -136,6 +136,8 @@ void AssetServer::completeSetup() {
|
|||
|
||||
performMappingMigration();
|
||||
|
||||
cleanupUnmappedFiles();
|
||||
|
||||
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
|
||||
}
|
||||
|
||||
|
@ -189,6 +191,34 @@ void AssetServer::performMappingMigration() {
|
|||
}
|
||||
}
|
||||
|
||||
void AssetServer::cleanupUnmappedFiles() {
|
||||
QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}" };
|
||||
|
||||
auto files = _filesDirectory.entryInfoList(QDir::Files);
|
||||
|
||||
// grab the currently mapped hashes
|
||||
auto mappedHashes = _fileMappings.values();
|
||||
|
||||
qDebug() << "Performing unmapped asset cleanup.";
|
||||
|
||||
for (const auto& fileInfo : files) {
|
||||
if (hashFileRegex.exactMatch(fileInfo.fileName())) {
|
||||
if (mappedHashes.contains(fileInfo.fileName())) {
|
||||
qDebug() << "\tLeaving" << fileInfo.fileName() << "in asset files directory since it is mapped";
|
||||
} else {
|
||||
// remove the unmapped file
|
||||
QFile removeableFile { fileInfo.absoluteFilePath() };
|
||||
|
||||
if (removeableFile.remove()) {
|
||||
qDebug() << "\tDeleted" << fileInfo.fileName() << "from asset files directory since it is unmapped.";
|
||||
} else {
|
||||
qDebug() << "\tAttempt to delete unmapped file" << fileInfo.fileName() << "failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AssetServer::handleAssetMappingOperation(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
|
||||
MessageID messageID;
|
||||
message->readPrimitive(&messageID);
|
||||
|
|
|
@ -62,6 +62,9 @@ private:
|
|||
|
||||
void performMappingMigration();
|
||||
|
||||
// deletes any unmapped files from the local asset directory
|
||||
void cleanupUnmappedFiles();
|
||||
|
||||
Mappings _fileMappings;
|
||||
|
||||
QDir _resourcesDirectory;
|
||||
|
|
Loading…
Reference in a new issue