aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2016-05-10 15:33:52 +0000
committerGravatar Klaus Aehlig <aehlig@google.com>2016-05-10 15:58:05 +0000
commitddc4e22d8aa6c21ec4fac175f4564571dde7eb3b (patch)
tree5e615470b18165097b26fd8000a916de236521fe
parentef35d9508c4aaf645b96f6f3392bd20c1d95a516 (diff)
Make deleting runfiles tree on Windows "best effort".
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
-rw-r--r--src/main/tools/build-runfiles.cc23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/main/tools/build-runfiles.cc b/src/main/tools/build-runfiles.cc
index cbf096d648..ae4520081f 100644
--- a/src/main/tools/build-runfiles.cc
+++ b/src/main/tools/build-runfiles.cc
@@ -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) {
@@ -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);
@@ -416,6 +422,7 @@ class RunfilesCreator {
if (rmdir(path.c_str()) != 0) {
PDIE("rmdir '%s'", path.c_str());
}
+ return true;
}
private: