Skip to content

Commit

Permalink
Canonicalize path in DiskInterface::Stat for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Takuto Ikuta committed Apr 9, 2018
1 parent 265a6ea commit 7957ee6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/disk_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,33 @@ bool DiskInterface::MakeDirs(const string& path) {
TimeStamp RealDiskInterface::Stat(const string& path, string* err) const {
METRIC_RECORD("node stat");
#ifdef _WIN32
uint64_t slash_bits;
string canonicalized_path = path;
if (!CanonicalizePath(&canonicalized_path, &slash_bits, err)) {
ostringstream err_stream;
err_stream << "Stat(" << path << "): Failed to canonicalize path " << *err;
*err = err_stream.str();
return -1;
}

// MSDN: "Naming Files, Paths, and Namespaces"
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
if (!path.empty() && path[0] != '\\' && path.size() > MAX_PATH) {
if (!canonicalized_path.empty() && canonicalized_path[0] != '\\' && canonicalized_path.size() > MAX_PATH) {
ostringstream err_stream;
err_stream << "Stat(" << path << "): Filename longer than " << MAX_PATH
err_stream << "Stat(" << canonicalized_path << "): Filename longer than " << MAX_PATH
<< " characters";
*err = err_stream.str();
return -1;
}
if (!use_cache_)
return StatSingleFile(path, err);
return StatSingleFile(canonicalized_path, err);

string dir = DirName(path);
string base(path.substr(dir.size() ? dir.size() + 1 : 0));
string dir = DirName(canonicalized_path);
string base(canonicalized_path.substr(dir.size() ? dir.size() + 1 : 0));
if (base == "..") {
// StatAllFilesInDir does not report any information for base = "..".
base = ".";
dir = path;
dir = canonicalized_path;
}

transform(dir.begin(), dir.end(), dir.begin(), ::tolower);
Expand Down

0 comments on commit 7957ee6

Please sign in to comment.