Skip to content

Commit

Permalink
Make deleting runfiles tree on Windows "best effort".
Browse files Browse the repository at this point in the history
On Windows, we use hard links in runfiles tree, and we need
to delete and recreate all of them on every runfiles tree update
(otherwise the links might still point to outdated files).
Occasionally the hard link cannot be unlinked (due to permissions
or file being busy). This CL just ignores the error (and hopes for the best).
This will allow us to make progress on Windows.

Work towards #1212.

--
MOS_MIGRATED_REVID=121949474
  • Loading branch information
dslomov authored and aehlig committed May 10, 2016
1 parent ef35d95 commit ddc4e22
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/main/tools/build-runfiles.cc
Expand Up @@ -260,14 +260,17 @@ class RunfilesCreator {
}

FileInfoMap::iterator expected_it = manifest_.find(entry_path);
// When windows_compatible is enabled, if the hard link already existing
// is still
// in the mainifest, no need to recreate it.
// Note: here we assume the content won't change, which might not be true
// in some rare cases.
if (expected_it == manifest_.end() ||
(!windows_compatible_ && expected_it->second != actual_info)) {
expected_it->second != actual_info) {
#if !defined(__CYGWIN__)
DelTree(entry_path, actual_info.type);
#else
// On Windows, if deleting failed, lamely assume that
// the link points to the right place.
if (!DelTree(entry_path, actual_info.type)) {
manifest_.erase(expected_it);
}
#endif
} else {
manifest_.erase(expected_it);
if (actual_info.type == FILE_TYPE_DIRECTORY) {
Expand Down Expand Up @@ -386,12 +389,15 @@ class RunfilesCreator {
}
}

void DelTree(const std::string &path, FileType file_type) {
bool DelTree(const std::string &path, FileType file_type) {
if (file_type != FILE_TYPE_DIRECTORY) {
if (unlink(path.c_str()) != 0) {
#if !defined(__CYGWIN__)
PDIE("unlinking '%s'", path.c_str());
#endif
return false;
}
return;
return true;
}

EnsureDirReadAndWritePerms(path);
Expand All @@ -416,6 +422,7 @@ class RunfilesCreator {
if (rmdir(path.c_str()) != 0) {
PDIE("rmdir '%s'", path.c_str());
}
return true;
}

private:
Expand Down

0 comments on commit ddc4e22

Please sign in to comment.