Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore toleration of missing to-be-deleted files on Windows #1913

Merged
merged 3 commits into from
Feb 12, 2021

Conversation

bradking
Copy link
Contributor

@bradking bradking commented Feb 12, 2021

Since #1892 we use DeleteFile without checking if it failed due to a path missing. Fix the GetFileAttributes logic to check for multiple variants of "file not found" as we do in StatSingleFile. Then fall back to the original remove() logic that already checks for ENOENT on failure. Add the check after DeleteFile too.

Issue: #1886

@bradking
Copy link
Contributor Author

I run nightly testing of CMake with a nightly build of ninja. After #1892, I started noticing failures with output from ninja:

Cleaning... ninja: error: remove(...): The system cannot find the path specified.

@bradking
Copy link
Contributor Author

bradking commented Feb 12, 2021

Cc: @jhasse @mathstuf

@jhasse
Copy link
Collaborator

jhasse commented Feb 12, 2021

Thx!

You've also added the A suffix to the winapi functions, any reason for that?

@bradking
Copy link
Contributor Author

The A suffix on winapi functions is already used elsewhere in the same source file. I added it for consistency. If we add unicode support in the future, they should all be converted to W suffixes together.

@jhasse
Copy link
Collaborator

jhasse commented Feb 12, 2021

Then fall back to the original remove() logic that already checks for ENOENT on failure.

Is this really needed? Couldn't this patch be broken down to just adding || win_err == ERROR_PATH_NOT_FOUND?

@bradking
Copy link
Contributor Author

I was trying to minimize the net change from before #1892 rather than a current net change, since the older code has been deployed and working for years. Try

git diff 2d7f7e55~1 HEAD -- src/disk_interface.cc

If you want to switch to DeleteFileA then I can re-work the change.

@bradking bradking force-pushed the windows-remove branch 2 times, most recently from e6bca0a to 703cfda Compare February 12, 2021 15:33
@bradking
Copy link
Contributor Author

bradking commented Feb 12, 2021

@jhasse something is wrong with the macOS builder in CI.

@bradking bradking requested a review from jhasse February 12, 2021 16:25
@jhasse
Copy link
Collaborator

jhasse commented Feb 12, 2021

I'm not a fan of the A/W suffix. When we switch to UNICODE this will just create an unnecessary huge diff. std::wstring has a c_str() function, too, so that line could eventually be untouched. That's why I didn't add it in #1892.

The reason to catch an acceptable error directly after GetFileAttributes was to avoid the subsequent calls.

I also deliberately used DeleteFile instead of remove, because it has better Unicode support. Otherwise we would have to #ifdefon Windows anyway and use _wremove and _wcserror instead.

@jhasse something is wrong with the macOS builder in CI.

Seems to be working now.

Copy link
Collaborator

@jhasse jhasse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the remove(%s) wording as people might have grep'ed for it.

Can you keep the DeleteFile code path?

…Windows

Revise the logic from commit 2d7f7e5 (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: ninja-build#1886
@bradking
Copy link
Contributor Author

Thanks for explaining your reasoning. I added a corresponding comment about remove().

@jhasse jhasse merged commit 9c66e69 into ninja-build:master Feb 12, 2021
@jhasse
Copy link
Collaborator

jhasse commented Feb 12, 2021

Thank you for the PR!

@bradking bradking deleted the windows-remove branch February 15, 2021 14:55
@jhasse
Copy link
Collaborator

jhasse commented Feb 17, 2021

I've just discovered that Windows now supports UTF-8 and we might not need UNICODE after all ...
#1915

If that really works, using remove sounds like the better idea. Sorry for the bad timing. If you find another issue with DeleteFile, feel free to to create a PR with your idea of using remove on Windows, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants