Repository navigation
fix(extensions): fall back to in-memory archive when the unlinked download file can't be written - #5561
Conversation
…nload file can't be written Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The regression tests leave buffered flush/close failures, descriptor cleanup after fdopen errors, and real fallback installation with unsafe-archive rejection unverified.
3 open issues
What changed in this PR
Adds an in-memory fallback to Spec Kit’s shared URL extension installer, addressing the gocryptfs failure in #5551 for CLI and init-time installs.
Changes:
- Uses
BytesIOwhen writing, flushing, or seeking the transient download file raisesOSError. - Closes failed file handles or raw descriptors before switching to the fallback.
- Adds a regression test for rejected writes to an already-unlinked file.
Verification was limited to source inspection and standard-library checks; project tests and a real gocryptfs mount were not exercised.
AI-generated review for the requester (identity unavailable): GitHub Copilot, model unknown, automated mode; inspection, verification, and review drafting.
| File | Description |
|---|---|
tests/specify_cli/extensions/test_command_add_path_traversal.py |
Adds write-rejection fallback coverage and verifies archive bytes reach the installer. |
src/specify_cli/extensions/_commands.py |
Adds the in-memory fallback and descriptor cleanup while preserving hardened file creation. |
Review effort: Max (adaptive)
… and real install via in-memory fallback Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
|
@copilot thanks, all three were real gaps. I changed the regression test so the fake download file is now a buffered stream, and its flush fails the way gocryptfs does. Because close() also flushes, close fails too. The test is now parametrized to also cover |
|
Thank you! |

install_extension_from_url()(used byspecify extension add --from <url>and by init-time URL installs) writes the downloaded archive into an exclusively created file that has already been unlinked, then reads it back through the descriptor. Some FUSE filesystems, such as gocryptfs, reject writes and flushes to an already-unlinked inode withENOENT. On those filesystems the command aborted withCould not safely write download file: [Errno 2] No such file or directory.The archive is already fully buffered in memory (bounded by
read_response_limited). So when writing the transient file raisesOSError, the installer now closes that handle and passes anio.BytesIOof the buffered bytes todetect_archive_format()andinstall_from_zip(archive_file=...). The workflow installer already consumes archives this way. On filesystems that behave normally, nothing changes: the hardened, descriptor-anchored transient file is still used. I also made sure a raw descriptor isn't leaked ifos.fdopenitself fails.I kept the existing temp-file path rather than removing it. Dropping it would leave the cache-dir and leaf-creation hardening helpers, and the tests that cover them, unused, which would be a much larger change. If you'd rather always use the in-memory buffer and delete that machinery, I'm happy to do it as a follow-up.
Testing: I added
test_url_install_tolerates_fs_rejecting_writes_to_unlinked_file. It makes the transient download file raiseFileNotFoundErroron write, the way gocryptfs does. On main it fails with the exact error from the report; with this change the install succeeds and the installer receives the original bytes.tests/specify_cli/extensions/test_command_add_path_traversal.pyandtests/specify_cli/extensions/test_command_add.pypass. I could not test on a real gocryptfs mount.AI disclosure: this change was prepared with an AI coding assistant (Claude).
🤖 Generated with Claude Code
Fixes #5551
This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.