fix: return error on non-ErrNotExist stat failures in Tar.Sync()#13684
fix: return error on non-ErrNotExist stat failures in Tar.Sync()#13684glours merged 2 commits intodocker:mainfrom
Conversation
glours
left a comment
There was a problem hiding this comment.
Looks good, unfortunately we just merged the removal of testify library which means you need to update your tests, sorry for that.
internal/sync/tar_test.go
Outdated
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" |
There was a problem hiding this comment.
Sorry but PR #13689 just remove the testify library, can update the test to use gotest.tools/v3 assertions?
There was a problem hiding this comment.
Done, rebased on latest main and migrated all assertions to gotest.tools/v3 in c86e506.
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>
8e9d666 to
c86e506
Compare
|
@Lidang-Jiang for legal reason you need to sign-off your last commit otherwise I won't be able to merge your PR |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
c86e506 to
0b25251
Compare
|
Done, added |


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