Repository navigation
fix: allow fetch-config --output to special files - #2227
Merged
TerryHowe merged 2 commits intoNov 2, 2026
Merged
Conversation
`oras manifest fetch-config --output <path>` has written through a temp file plus rename since oras-project#2222. This broke targets that cannot be replaced, such as /dev/stdout, /dev/fd/N, FIFOs and devices (the temp file was created in /dev). It also forced mode 0644 and replaced symbolic links with regular files. Add writeOutputFile and use it for `--output`: - symbolic links and existing non-regular files are written through directly, so links, FIFOs and devices keep working and stay intact; - otherwise the content is still written to a temp file in the same directory and renamed, keeping the write atomic; - an existing regular file keeps its permission bits, and a new file gets 0666 filtered by the umask instead of a hard-coded 0644. Fixes oras-project#2224 Fixes oras-project#2226 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Havinash Gangisetty <[email protected]>
havinash-007
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
October 7, 2026 02:20
TerryHowe
reviewed
Oct 7, 2026
TerryHowe
left a comment
Member
There was a problem hiding this comment.
Reviewed the new writeOutputFile; findings inline.
- resolve symlinks with EvalSymlinks and keep the atomic rename for the target instead of truncating it in place before digest verification - chmod the temp file before writing so content never sits in a wider mode - name the temp file from the directory so long basenames do not exceed the name length limit, and fall back to an in-place write when no temp file can be created (e.g. read-only directory) - drop the redundant symlink check in favour of IsRegular Signed-off-by: Terry Howe <[email protected]>
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (70.76%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2227 +/- ##
===========================================
+ Coverage 57.37% 73.33% +15.96%
===========================================
Files 139 156 +17
Lines 6067 6526 +459
===========================================
+ Hits 3481 4786 +1305
+ Misses 2364 1452 -912
- Partials 222 288 +66 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4 tasks done
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.
Problem
Since #2222,
oras manifest fetch-config --output <path>always writes toos.CreateTemp(filepath.Dir(path)), chmods it to 0644 and renames it over thetarget.
--output /dev/stdoutand other special paths fail #2224:--output /dev/stdout(also/dev/fd/N, FIFOs, devices) fails, e.g.Error: open /dev/oras-config-1550247808: permission denied.--output <file>forces mode 0644, ignoring umask and existing mode #2226: the output file is always 0644 (ignores umask and the existingfile's mode) and a symlink given as
--outputis replaced by a regular file.Repro (before the fix; OCI layout, no registry needed)
After the fix: stdout works, the symlink is kept and its target updated, n.json is 0600.
Fix
New
writeOutputFile(cmd/oras/root/manifest/output_file.go):Lstatthe target. Symlink or existing non-regular file: open and write inplace (no temp file, no rename).
Sync+ rename flow, but create the tempfile in the target directory with 0666 (kernel applies umask) and
Chmodit tothe existing file's permission bits when overwriting.
the rename.
Tests
leaves no temp file, umask honoured, symlink kept (target mode kept), FIFO,
character device (/dev/null). Unix-only ones are in
output_file_unix_test.go(
!windows).go test ./cmd/oras/... ./internal/...passes;go vetandgofmt -lclean;GOOS=windows go vet ./cmd/oras/root/manifest/OK.Not verified / caveats
golangci-lintis not installed locally, so CI lint was not run (gofmt/vet were).failed digest verification can leave a truncated/partial target. In-place writes
open with O_TRUNC, so
-o /dev/stdoutwith stdout redirected by>>to a regularfile truncates it (same as
>; previous pre-fix: limit manifest config fetch size #2222os.Createbehaviour).hard links (mode is preserved).
-(stdout) path is unchanged. Other commands'--outputhandling was not touched.AI assistance
This change was prepared with Claude Code (Claude Sonnet 5.5) for @havinash-007. Tests were run as listed above; the caveats list what was not verified.
Fixes #2224
Fixes #2226
🤖 Generated with Claude Code