Simplify ResolvePath(), accessing paths using \Device\whatever is no longer valid (nothing should legitimately be using this anyway).

This commit is contained in:
gibbed 2015-05-24 01:14:01 -05:00
parent a4f2efe941
commit 25c76e92e9
1 changed files with 13 additions and 16 deletions

View File

@ -153,34 +153,31 @@ std::unique_ptr<Entry> FileSystem::ResolvePath(const std::string& path) {
// Resolve relative paths // Resolve relative paths
std::string normalized_path(xe::fs::CanonicalizePath(path)); std::string normalized_path(xe::fs::CanonicalizePath(path));
// If no path (starts with a slash) do it module-relative.
// Which for now, we just make game:.
if (normalized_path[0] == '\\') {
normalized_path = "game:" + normalized_path;
}
// Resolve symlinks. // Resolve symlinks.
// TODO(benvanik): more robust symlink handling - right now we assume simple std::string device_path;
// drive path -> device mappings with nothing nested. std::string relative_path;
std::string full_path = normalized_path;
for (const auto& it : symlinks_) { for (const auto& it : symlinks_) {
if (xe::find_first_of_case(normalized_path, it.first) == 0) { if (xe::find_first_of_case(normalized_path, it.first) == 0) {
// Found symlink, fixup by replacing the prefix. // Found symlink!
full_path = it.second + full_path.substr(it.first.size()); device_path = it.second;
relative_path = normalized_path.substr(it.first.size());
break; break;
} }
} }
if (device_path.empty()) {
XELOGE("ResolvePath(%s) failed - no root found", path.c_str());
return nullptr;
}
// Scan all devices. // Scan all devices.
for (auto& device : devices_) { for (auto& device : devices_) {
if (xe::find_first_of_case(full_path, device->path()) == 0) { if (strcasecmp(device_path.c_str(), device->path().c_str()) == 0) {
// Found! Trim the device prefix off and pass down. return device->ResolvePath(relative_path.c_str());
auto device_path = full_path.substr(device->path().size());
return device->ResolvePath(device_path.c_str());
} }
} }
XELOGE("ResolvePath(%s) failed - no root found", path.c_str()); XELOGE("ResolvePath(%s) failed - device not found (%s)", path.c_str(), device_path.c_str());
return nullptr; return nullptr;
} }