fix: return error on non-ErrNotExist stat failures in Tar.Sync()#13684
Open
Lidang-Jiang wants to merge 1 commit intodocker:mainfrom
Open
fix: return error on non-ErrNotExist stat failures in Tar.Sync()#13684Lidang-Jiang wants to merge 1 commit intodocker:mainfrom
Lidang-Jiang wants to merge 1 commit intodocker:mainfrom
Conversation
Previously, Sync() only checked for fs.ErrNotExist when classifying paths into copy vs delete. Non-NotExist stat errors (e.g. EACCES, EIO) caused the condition to be false, falling through to the else clause which incorrectly treated the path as copyable. This masked real errors and led to cryptic failures downstream. Restructure the condition into a three-way branch: - err == nil → copy - ErrNotExist → delete - other errors → return immediately with context This follows the pattern already used by entriesForPath() in the same file. Fixes docker#13654 Signed-off-by: Lidang Jiang <lidangjiang@gmail.com> Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
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.
Summary
ErrNotExiststat errors inTar.Sync()(internal/sync/tar.go)The previous two-way branch only checked for
fs.ErrNotExist. Any otheros.Staterror (e.g.EACCES,EIO) fell through to theelseclause, silently treating the path as copyable. This masked real errors and caused failures downstream with the original cause lost.The fix restructures the condition into a three-way branch, following the pattern already used by
entriesForPath()in the same file.Fixes #13654
Before / After
Before (buggy behavior)
Non-
ErrNotExiststat errors are silently treated as "copy":The path with a permission error is incorrectly added to the copy list instead of surfacing the error.
After (fixed behavior)
Permission errors are now properly returned:
Unit test output:
Lint:
Test plan
TestSync_ExistingPath— existing host path is correctly added to copy listTestSync_NonExistentPath— missing host path triggersrm -rfdelete commandTestSync_StatPermissionError—EACCESerror is returned immediately (skipped on root/Windows)TestSync_MixedPaths— mix of existing and missing paths handled correctly in one callgolangci-lint run ./internal/sync/...— 0 issues