mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
ComputePathTo: Handle case where from == to.
This commit is contained in:
parent
d8136adbed
commit
0e3cf9862e
3 changed files with 15 additions and 3 deletions
|
@ -346,6 +346,11 @@ bool Path::IsAbsolute() const {
|
|||
}
|
||||
|
||||
bool Path::ComputePathTo(const Path &other, std::string &path) const {
|
||||
if (other == *this) {
|
||||
path.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!other.StartsWith(*this)) {
|
||||
// Can't do this. Should return an error.
|
||||
return false;
|
||||
|
|
|
@ -507,15 +507,19 @@ static bool ListFileSuffixesRecursively(const Path &root, Path folder, std::vect
|
|||
if (file.isDirectory) {
|
||||
std::string dirSuffix;
|
||||
if (root.ComputePathTo(file.fullName, dirSuffix)) {
|
||||
dirSuffixes.push_back(dirSuffix);
|
||||
ListFileSuffixesRecursively(root, folder / file.name, dirSuffixes, fileSuffixes);
|
||||
if (!dirSuffix.empty()) {
|
||||
dirSuffixes.push_back(dirSuffix);
|
||||
ListFileSuffixesRecursively(root, folder / file.name, dirSuffixes, fileSuffixes);
|
||||
}
|
||||
} else {
|
||||
ERROR_LOG_REPORT(SYSTEM, "Failed to compute PathTo from '%s' to '%s'", root.c_str(), folder.c_str());
|
||||
}
|
||||
} else {
|
||||
std::string fileSuffix;
|
||||
if (root.ComputePathTo(file.fullName, fileSuffix)) {
|
||||
fileSuffixes.push_back(FileSuffix{ fileSuffix, file.size });
|
||||
if (!fileSuffix.empty()) {
|
||||
fileSuffixes.push_back(FileSuffix{ fileSuffix, file.size });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -661,6 +661,9 @@ static bool TestPath() {
|
|||
EXPECT_TRUE(Path("/").ComputePathTo(Path("/home/foo/bar"), computedPath));
|
||||
EXPECT_EQ_STR(computedPath, std::string("home/foo/bar"));
|
||||
|
||||
EXPECT_TRUE(Path("/a/b").ComputePathTo(Path("/a/b"), computedPath));
|
||||
EXPECT_EQ_STR(computedPath, std::string());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue