add trimming to paths on asset server

This commit is contained in:
Stephen Birarda 2016-03-10 16:00:29 -08:00
parent 52ee2499fc
commit e94e2ece2e
2 changed files with 11 additions and 5 deletions

View file

@ -509,7 +509,8 @@ bool AssetServer::writeMappingsToFile() {
return false; return false;
} }
bool AssetServer::setMapping(const AssetPath& path, const AssetHash& hash) { bool AssetServer::setMapping(AssetPath path, AssetHash hash) {
path = path.trimmed();
if (!isValidPath(path)) { if (!isValidPath(path)) {
qWarning() << "Cannot set a mapping for invalid path:" << path << "=>" << hash; qWarning() << "Cannot set a mapping for invalid path:" << path << "=>" << hash;
@ -555,7 +556,9 @@ bool AssetServer::deleteMappings(const AssetPathList& paths) {
auto oldMappings = _fileMappings; auto oldMappings = _fileMappings;
// enumerate the paths to delete and remove them all // 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 // figure out if this path will delete a file or folder
if (pathIsFolder(path)) { 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)) { if (!isValidPath(oldPath) || !isValidPath(newPath)) {
qWarning() << "Cannot perform rename with invalid paths - both should have leading forward slashes:" qWarning() << "Cannot perform rename with invalid paths - both should have leading forward slashes:"
<< oldPath << "=>" << newPath; << oldPath << "=>" << newPath;

View file

@ -52,13 +52,13 @@ private:
bool writeMappingsToFile(); bool writeMappingsToFile();
/// Set the mapping for path to hash /// 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`. /// Delete mapping `path`. Returns `true` if deletion of mappings succeeds, else `false`.
bool deleteMappings(const AssetPathList& paths); bool deleteMappings(const AssetPathList& paths);
/// Rename mapping from `oldPath` to `newPath`. Returns true if successful /// 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(); void performMappingMigration();