Repository navigation
fix: return a safe file handle in dry-run mode - #879
Open
terryrankine wants to merge 1 commit into
Open
terryrankine wants to merge 1 commit into
terryrankine wants to merge 1 commit into
Conversation
Create() and CreateTemp() returned `&os.File{}` in dry-run mode, which
panics on Name() (nil inner *file). Handing out os.NewFile(0, os.DevNull)
instead would alias stdin, so doDownload's file.Close() closed fd 0 and
`s5cmd --dry-run run < commands.txt` failed after the first download.
Open os.DevNull for writing and return that handle instead.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 17, 2026
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.
Context
cp --dry-runfor a download panicked on the destination file handle, and the obvious fix (a/dev/nullhandle fromos.NewFile(0, …)) introduces a worse bug: fd 0 is stdin.Root cause
Filesystem.Create()andCreateTemp()returned&os.File{}in dry-run mode. Its inner*fileis nil, soName()panics. Wrapping fd 0 instead aliases stdin:doDownloadcallsfile.Close(), which closes stdin, ands5cmd --dry-run run < commands.txtstops reading after the first download (it hangs).Fix
Return
os.OpenFile(os.DevNull, os.O_WRONLY, 0)— a real, independent handle that is safe to write, name and close. No file is created on disk.Tests
storage/fs_test.go:TestFilesystemCreateDryRun(Create and CreateTemp) — non-nil handle,Name() == os.DevNull,Fd() != 0, Write and Close succeed, stdin still usable afterwards, nothing on disk.e2e/run_test.go:TestRunDryRunDownloadFromStdin— pipes 200cp s3://… dir/lines into--dry-run run. Hangs (10 mingo testtimeout) with an fd-0 handle; passes with this fix.Linux, Go 1.24,
go test -count=1 -race ./...: all packagesok(command,e2e,orderedwriter,progressbar,storage,storage/url,strutil).gofmt,go vet,staticcheck,unparam,semgrep: clean.🤖 Generated with Claude Code