Refactor some of the win32 POSIX emulation#4192
Merged
Refactor some of the win32 POSIX emulation#4192
Conversation
Introduce mapping from windows error codes to errno values. This allows us to replace our calls to the Windows posix emulation functions with calls to the Win32 APIs for more fine-grained control over the emulation. These mappings match the Windows CRT's mappings for its posix emulation as they were described to me.
Provide a macro that will allow us to run a function with posix-like return values multiple times in a retry loop, with an optional cleanup function called between invocations.
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
This can prevent FILE_SHARED_VIOLATIONS when used in tools such as TortoiseGit TGitCache and FILE_SHARE_DELETE, because files can be opened w/o being locked any more. Signed-off-by: Sven Strickroth <email@cs-ware.de>
POSIX emulation retries should be configurable so that tests can disable them. In particular, maniacally threading tests may end up trying to open locked files and need retries, which will slow continuous integration tests significantly.
Instead of failing to set the timestamp of a read-only file (like any object file), set it writable temporarily to update the timestamp.
The `remediation` function is run in the retry loop in order to attempt to fix any problems that the prior run encountered. There is nothing "cleaned up". Clarify the name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pulls in #3790, which provides retries in more of the POSIX emulation functions to be more resilient in the face of files locked by the aggressive locking semantics in Win32, and #4073, which allows consumers to configure their own locking strategies so that consumers can "get out of the way" of their users a bit more instead of locking files unnecessarily.
I refactored these a bit: this now introduces a
do_with_retriesmacro that will execute the given function up to 10 times, retrying if the error appears to be something like a locked file. Callers can provide a "cleanup" function - perhaps to set the file writable - that will be called between invocations of the main function. This allowed us to clean up some patterns of try / set writable / try again.I introduced the
GIT_RETRYconstant here. This is internal only and should never be returned to callers.These new retryable functions call the win32 functions directly instead of calling Windows' POSIX emulation functions, which allows us to use the win32 error codes which are more fine-grained. This allows us to retry only particular failures (ie,
ERROR_SHARING_VIOLATION) instead of a sharing violation and all the other failures that get mapped to a particular POSIXerrno.This also allows us to bring in the configurable share mode for
CreateFile, in #4073.Once
p_utimescalled a retryable version ofp_open, I noticed quickly that it was retrying all the time. Our ODB freshening test was freshening an object in a repository that had been copied over from a test harness and - as a result - the objects were all writable. Thusp_utimeswould succeed on Windows. But freshening a file that we wrote - and thus marked as read-only - would fail. Oops. So I madep_utimesdeal with read-only files by setting them writable temporarily to update the time.