summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Niklas Hasse <jhasse@bixense.com>2021-02-12 19:28:56 (GMT)
committerGitHub <noreply@github.com>2021-02-12 19:28:56 (GMT)
commit9c66e698466ed29a493df8746b767558684205b2 (patch)
treedc83e5f592341fe241f84968bf6a163344cb1ec2
parentb0662970ba2cc69a64d7d2ebe3e07dcef948dabe (diff)
parent5392e0e7bf7095039ae6bd69c0a8dfc77ef80a05 (diff)
downloadNinja-9c66e698466ed29a493df8746b767558684205b2.zip
Ninja-9c66e698466ed29a493df8746b767558684205b2.tar.gz
Ninja-9c66e698466ed29a493df8746b767558684205b2.tar.bz2
Merge pull request #1913 from bradking/windows-remove
Restore toleration of missing to-be-deleted files on Windows
-rw-r--r--src/disk_interface.cc23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index 8d4cc7f..a9497cb 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -267,17 +267,24 @@ FileReader::Status RealDiskInterface::ReadFile(const string& path,
int RealDiskInterface::RemoveFile(const string& path) {
#ifdef _WIN32
DWORD attributes = GetFileAttributes(path.c_str());
- if (attributes == INVALID_FILE_ATTRIBUTES &&
- GetLastError() == ERROR_FILE_NOT_FOUND) {
- return 1;
- }
- if (attributes & FILE_ATTRIBUTE_READONLY) {
- // On non-Windows systems remove will happily delete read-only files. On
- // Windows Ninja should behave the same. See
- // https://github.com/ninja-build/ninja/issues/1886
+ if (attributes == INVALID_FILE_ATTRIBUTES) {
+ DWORD win_err = GetLastError();
+ if (win_err == ERROR_FILE_NOT_FOUND || win_err == ERROR_PATH_NOT_FOUND) {
+ return 1;
+ }
+ } else if (attributes & FILE_ATTRIBUTE_READONLY) {
+ // On non-Windows systems, remove() will happily delete read-only files.
+ // On Windows Ninja should behave the same:
+ // https://github.com/ninja-build/ninja/issues/1886
+ // Skip error checking. If this fails, accept whatever happens below.
SetFileAttributes(path.c_str(), attributes & ~FILE_ATTRIBUTE_READONLY);
}
if (!DeleteFile(path.c_str())) {
+ DWORD win_err = GetLastError();
+ if (win_err == ERROR_FILE_NOT_FOUND || win_err == ERROR_PATH_NOT_FOUND) {
+ return 1;
+ }
+ // Report as remove(), not DeleteFile(), for cross-platform consistency.
Error("remove(%s): %s", path.c_str(), GetLastErrorString().c_str());
return -1;
}