summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-02-12 16:37:23 (GMT)
committerBrad King <brad.king@kitware.com>2021-02-12 16:47:12 (GMT)
commit5392e0e7bf7095039ae6bd69c0a8dfc77ef80a05 (patch)
treedc83e5f592341fe241f84968bf6a163344cb1ec2 /src
parentc7e3e5ef45c1877d12d6365fbfb68fa840c1518b (diff)
downloadNinja-5392e0e7bf7095039ae6bd69c0a8dfc77ef80a05.zip
Ninja-5392e0e7bf7095039ae6bd69c0a8dfc77ef80a05.tar.gz
Ninja-5392e0e7bf7095039ae6bd69c0a8dfc77ef80a05.tar.bz2
disk_interface: Restore toleration of missing files in RemoveFile on Windows
Revise the logic from commit 2d7f7e55 (Delete read-only files on Windows, too, 2020-12-07) to check if `GetFileAttributes` or `DeleteFile` failed due either variant of the file/path-not-found error. Issue: #1886
Diffstat (limited to 'src')
-rw-r--r--src/disk_interface.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/disk_interface.cc b/src/disk_interface.cc
index 6290680..a9497cb 100644
--- a/src/disk_interface.cc
+++ b/src/disk_interface.cc
@@ -268,16 +268,23 @@ int RealDiskInterface::RemoveFile(const string& path) {
#ifdef _WIN32
DWORD attributes = GetFileAttributes(path.c_str());
if (attributes == INVALID_FILE_ATTRIBUTES) {
- if (GetLastError() == ERROR_FILE_NOT_FOUND) {
+ 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;
}