Repository navigation
Preserve signed filesystem timestamps in os.utime #9047
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,11 @@ def __exit__(self, exc_type, exc_val, exc_tb): | |
| assert os.write(fd, CONTENT2) == len(CONTENT2) | ||
| os.close(fd) | ||
|
|
||
| # A valid negative access time must reach the invalid modification time. | ||
| for atime in (-1, -0.25): | ||
| assert_raises(TypeError, os.utime, fname, (atime, object())) | ||
| assert_raises(TypeError, os.utime, fname, ns=(-1, object())) | ||
|
Comment on lines
+149
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These new calls add assertions and test logic to AGENTS.md reference: AGENTS.md:L275-L279 Useful? React with 👍 / 👎. |
||
|
|
||
| fd = os.open(fname, os.O_WRONLY | os.O_APPEND) | ||
| assert os.write(fd, CONTENT3) == len(CONTENT3) | ||
| os.close(fd) | ||
|
|
||
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.
In the Windows branch, when the target already has an open read or write handle, switching to
host_nt::set_file_timesmakesos.utime(path, ...)fail with a sharing violation: that helper callsCreateFileWwithdwShareMode = 0(crates/host_env/src/nt.rs:406-412), whereas the previousOpenOptionspath used the normal read/write/delete sharing flags. Preserve those share flags in the new helper so updating timestamps does not regress for open files.Useful? React with 👍 / 👎.
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.
The access-mode change matters here: this helper requests only FILE_WRITE_ATTRIBUTES, whereas the old OpenOptions path requested data-write access. Windows excludes attribute-only access from its sharing-conflict checks, and CPython 3.14.7 uses the same FILE_WRITE_ATTRIBUTES/share-mode-zero call. Sources: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/8c0e3f4f-0729-49f4-a14d-7f7add593819 and https://github.com/python/cpython/blob/v3.14.7/Modules/posixmodule.c#L6269-L6274 . On that evidence, changing the sharing flags is not warranted. This is source verification; I have not run an open-handle Windows runtime test locally.