Skip to content

Commit

Permalink
Consider some relative path case in io::JoinPath.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Oct 29, 2023
1 parent 5687d89 commit db99c1a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/io-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#endif

#include "io-util.hh"
#include "str-util.hh"

namespace tinyusdz {
namespace io {
Expand Down Expand Up @@ -502,10 +503,24 @@ std::string JoinPath(const std::string &dir, const std::string &filename) {
} else {
// check '/'
char lastChar = *dir.rbegin();

// TODO: Support more relative path case.

std::string basedir;
if (lastChar != '/') {
return dir + std::string("/") + filename;
basedir = dir + std::string("/");
} else {
basedir = dir;
}

if (basedir.size()) {
if (startsWith(filename, "./")) {
// strip "./"
return basedir + removePrefix(filename, "./");
}
return basedir + filename;
} else {
return dir + filename;
return filename;
}
}
}
Expand Down Expand Up @@ -611,6 +626,13 @@ std::string FindFile(const std::string &filename,
return filename;
}

if (search_paths.empty()) {
std::string absPath = io::ExpandFilePath(filename, /* userdata */ nullptr);
if (io::FileExists(absPath, /* userdata */ nullptr)) {
return absPath;
}
}

for (size_t i = 0; i < search_paths.size(); i++) {
std::string absPath = io::ExpandFilePath(
io::JoinPath(search_paths[i], filename), /* userdata */ nullptr);
Expand Down

0 comments on commit db99c1a

Please sign in to comment.