-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
std.fs: support Lock.none
on Windows
#21306
base: master
Are you sure you want to change the base?
std.fs: support Lock.none
on Windows
#21306
Conversation
Lock.none
on WindowsLock.none
on Windows
83fcda0
to
3c21e22
Compare
Looks good, thanks for getting this fixed! |
4c31c28
to
58c50c5
Compare
This comment was marked as outdated.
This comment was marked as outdated.
fe1d3e8
to
58c50c5
Compare
58c50c5
to
10ce03e
Compare
…ting Posix behavior in case of `Lock.none` Adapted from ziglang#18566
10ce03e
to
2f4cfce
Compare
I apologize for the early requested review btw, I don't know how that happened |
…ors when `windows.UnlockFile` returns `error.Unexpected`
error.Unexpected => unreachable, // Resource deallocation must succeed. | ||
error.Unexpected => return error.Unexpected, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this change also be made in unlock()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unlock
can't return an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it seems questionable to me that we're doing it here. If we're worried that the OS might become able to return an error here in the future, the same concern surely applies to unlock()
? Are we just crossing our fingers and hoping that such an error will be safe to ignore in unlock()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we just crossing our fingers and hoping that such an error will be safe to ignore in
unlock()
?
I think so; same sort of thing with File.close
. I agree that it seems strange for unlock
, not sure that should really count as "resource deallocation."
FWIW, there's exactly one instance of File.unlock
in a defer that I could find:
zig/lib/std/crypto/tls/Client.zig
Lines 1512 to 1513 in 5b4759b
const locked = if (key_log_file.lock(.exclusive)) |_| true else |_| false; | |
defer if (locked) key_log_file.unlock(); |
I guess this isn't strictly related to this PR, and I might just be showing my ignorance, but I don't understand why |
Fixes #18430. Borrows code from #18566.
I also made
std.windows.LockFile
andstd.windows.UnlockFile
use the relevant explicit error set.The doc comments and Windows API for
File.lock
File.tryLock
have been changed to match the POSIX implimentation.