From e94e2ece2e0dd954b51fb2b426de747c9e5267cd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 16:00:29 -0800 Subject: [PATCH] add trimming to paths on asset server --- assignment-client/src/assets/AssetServer.cpp | 12 +++++++++--- assignment-client/src/assets/AssetServer.h | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 38f4c66f4b..8598a33715 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -509,7 +509,8 @@ bool AssetServer::writeMappingsToFile() { return false; } -bool AssetServer::setMapping(const AssetPath& path, const AssetHash& hash) { +bool AssetServer::setMapping(AssetPath path, AssetHash hash) { + path = path.trimmed(); if (!isValidPath(path)) { qWarning() << "Cannot set a mapping for invalid path:" << path << "=>" << hash; @@ -555,7 +556,9 @@ bool AssetServer::deleteMappings(const AssetPathList& paths) { auto oldMappings = _fileMappings; // enumerate the paths to delete and remove them all - for (auto& path : paths) { + for (auto path : paths) { + + path = path.trimmed(); // figure out if this path will delete a file or folder if (pathIsFolder(path)) { @@ -602,7 +605,10 @@ bool AssetServer::deleteMappings(const AssetPathList& paths) { } } -bool AssetServer::renameMapping(const AssetPath& oldPath, const AssetPath& newPath) { +bool AssetServer::renameMapping(AssetPath oldPath, AssetPath newPath) { + oldPath = oldPath.trimmed(); + newPath = newPath.trimmed(); + if (!isValidPath(oldPath) || !isValidPath(newPath)) { qWarning() << "Cannot perform rename with invalid paths - both should have leading forward slashes:" << oldPath << "=>" << newPath; diff --git a/assignment-client/src/assets/AssetServer.h b/assignment-client/src/assets/AssetServer.h index 094ea58d41..2e4321e4cd 100644 --- a/assignment-client/src/assets/AssetServer.h +++ b/assignment-client/src/assets/AssetServer.h @@ -52,13 +52,13 @@ private: bool writeMappingsToFile(); /// Set the mapping for path to hash - bool setMapping(const AssetPath& path, const AssetHash& hash); + bool setMapping(AssetPath path, AssetHash hash); /// Delete mapping `path`. Returns `true` if deletion of mappings succeeds, else `false`. bool deleteMappings(const AssetPathList& paths); /// Rename mapping from `oldPath` to `newPath`. Returns true if successful - bool renameMapping(const AssetPath& oldPath, const AssetPath& newPath); + bool renameMapping(AssetPath oldPath, AssetPath newPath); void performMappingMigration();