don't perform asset cleanup if mapping file load fails

This commit is contained in:
Stephen Birarda 2016-04-11 17:14:31 -07:00
parent 334dc3cb6c
commit 026f58c866
2 changed files with 22 additions and 14 deletions

View file

@ -122,21 +122,27 @@ void AssetServer::completeSetup() {
} }
// load whatever mappings we currently have from the local file // load whatever mappings we currently have from the local file
loadMappingsFromFile(); if (loadMappingsFromFile()) {
qInfo() << "Serving files from: " << _filesDirectory.path();
qInfo() << "Serving files from: " << _filesDirectory.path(); // Check the asset directory to output some information about what we have
auto files = _filesDirectory.entryList(QDir::Files);
// Check the asset directory to output some information about what we have QRegExp hashFileRegex { ASSET_HASH_REGEX_STRING };
auto files = _filesDirectory.entryList(QDir::Files); auto hashedFiles = files.filter(hashFileRegex);
QRegExp hashFileRegex { ASSET_HASH_REGEX_STRING }; qInfo() << "There are" << hashedFiles.size() << "asset files in the asset directory.";
auto hashedFiles = files.filter(hashFileRegex);
qInfo() << "There are" << hashedFiles.size() << "asset files in the asset directory."; if (_fileMappings.count() > 0) {
cleanupUnmappedFiles();
}
cleanupUnmappedFiles(); nodeList->addNodeTypeToInterestSet(NodeType::Agent);
} else {
qCritical() << "Asset Server assignment will not continue because mapping file could not be loaded.";
setFinished(true);
}
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
} }
void AssetServer::cleanupUnmappedFiles() { void AssetServer::cleanupUnmappedFiles() {
@ -427,7 +433,7 @@ void AssetServer::sendStatsPacket() {
static const QString MAP_FILE_NAME = "map.json"; static const QString MAP_FILE_NAME = "map.json";
void AssetServer::loadMappingsFromFile() { bool AssetServer::loadMappingsFromFile() {
auto mapFilePath = _resourcesDirectory.absoluteFilePath(MAP_FILE_NAME); auto mapFilePath = _resourcesDirectory.absoluteFilePath(MAP_FILE_NAME);
@ -464,15 +470,17 @@ void AssetServer::loadMappingsFromFile() {
} }
qInfo() << "Loaded" << _fileMappings.count() << "mappings from map file at" << mapFilePath; qInfo() << "Loaded" << _fileMappings.count() << "mappings from map file at" << mapFilePath;
return; return true;
} }
} }
qCritical() << "Failed to read mapping file at" << mapFilePath << "- assignment will not continue."; qCritical() << "Failed to read mapping file at" << mapFilePath;
setFinished(true); return false;
} else { } else {
qInfo() << "No existing mappings loaded from file since no file was found at" << mapFilePath; qInfo() << "No existing mappings loaded from file since no file was found at" << mapFilePath;
} }
return true;
} }
bool AssetServer::writeMappingsToFile() { bool AssetServer::writeMappingsToFile() {

View file

@ -48,7 +48,7 @@ private:
void handleRenameMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket); void handleRenameMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket);
// Mapping file operations must be called from main assignment thread only // Mapping file operations must be called from main assignment thread only
void loadMappingsFromFile(); bool loadMappingsFromFile();
bool writeMappingsToFile(); bool writeMappingsToFile();
/// Set the mapping for path to hash /// Set the mapping for path to hash