Repository navigation
Check permissions and length in fake os.truncate and os.ftruncate - #1343
kratos0718 wants to merge 2 commits into
Conversation
|
Please add an issue so that this change can be tracked in CHANGES.md. |
os.truncate succeeded on a read-only file, os.ftruncate truncated a file through a descriptor opened read-only, and a negative length raised ENOSPC. The real calls raise EACCES, EINVAL and EINVAL.
7405f10 to
569a6d0
Compare
|
Rebased onto current main and added a CHANGES.md entry under Unreleased that points to this PR (per the suggestion on #1344 that the PR can serve as the reference). I can open a separate issue as well if you prefer. |
CPython's Windows os.truncate checks the result of _chsize_s with < 0, but _chsize_s returns a positive errno, so the error is dropped and the file is left as it was. os.ftruncate checks != 0 and still raises.
|
The Windows failures came from the real-fs run: under Windows, |
|
Please rebase and resolve the conflicts - otherwise the tests won't run (seems to be a new behavior). |
Describe the changes
os.truncate()on a read-only file succeeded and emptied it; the real call raisesEACCES(checked withis_root()like the other permission checks).os.ftruncate()on a descriptor opened withO_RDONLYtruncated the file; POSIX raisesEINVAL. Left unchanged under Windows, where I could not check the real behavior.ENOSPCfrom the size setter; both calls raiseEINVAL.os.truncate(fd, ...)now goes throughftruncate, so it gets the same checks.The new tests also run against the real fs (
TEST_REAL_FS=1passes on macOS and as a non-root user on Linux), and they fail without the change.Tasks