Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, macos-26-intel ]
os: [ macos-latest ]
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand All @@ -116,7 +116,7 @@ jobs:
CGO_ENABLED: 0
strategy:
matrix:
os: [ windows-latest, windows-11-arm ]
os: [ windows-latest ]
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![CI](https://github.com/containers/tar-diff/actions/workflows/ci.yml/badge.svg)](https://github.com/containers/tar-diff/actions/workflows/ci.yml)
[![Go Version](https://img.shields.io/badge/go-1.25-blue.svg)](https://golang.org/dl/)
[![Go Version](https://img.shields.io/badge/go-1.26-blue.svg)](https://golang.org/dl/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
[![codecov](https://codecov.io/gh/containers/tar-diff/graph/badge.svg)](https://codecov.io/gh/containers/tar-diff)

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/containers/tar-diff

go 1.26

toolchain go1.26.2

require (
github.com/containers/image/v5 v5.36.2
github.com/klauspost/compress v1.18.6
Expand Down
5 changes: 3 additions & 2 deletions pkg/tar-patch/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ func (f *FilesystemDataSource) Read(data []byte) (n int, err error) {
func (f *FilesystemDataSource) SetCurrentFile(file string) error {
if f.currentFile != nil {
err := f.currentFile.Close()
f.currentFile = nil
if err != nil {
return nil
// Don't nil out currentFile if close fails
return fmt.Errorf("failed to close current file: %w", err)
}
f.currentFile = nil
}
currentFile, err := os.Open(filepath.Join(f.basePath, file))
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions pkg/tar-patch/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,41 @@ func TestFilesystemDataSource_SetCurrentFile_NotFound(t *testing.T) {
}
}

func TestFilesystemDataSource_SetCurrentFileCloseError(t *testing.T) {
tempDir := t.TempDir()
testFile1 := "test1.txt"
testFile2 := "test2.txt"

filePath1 := filepath.Join(tempDir, testFile1)
filePath2 := filepath.Join(tempDir, testFile2)
if err := os.WriteFile(filePath1, []byte("content1"), 0644); err != nil {
t.Fatalf("failed to create test file: %v", err)
}
if err := os.WriteFile(filePath2, []byte("content2"), 0644); err != nil {
t.Fatalf("failed to create test file: %v", err)
}

ds := NewFilesystemDataSource(tempDir)
if err := ds.SetCurrentFile(testFile1); err != nil {
t.Fatalf("SetCurrentFile failed: %v", err)
}

// Close the file directly to force an error when SetCurrentFile tries to close it
if err := ds.currentFile.Close(); err != nil {
t.Fatalf("failed to pre-close file: %v", err)
}

// Now SetCurrentFile should return an error when trying to close the already-closed file
err := ds.SetCurrentFile(testFile2)
if err == nil {
t.Fatal("expected error from SetCurrentFile when closing already-closed file, got nil")
}
Comment thread
rosygmiki marked this conversation as resolved.

if ds.currentFile == nil {
t.Fatal("currentFile should not be nil after a failed Close()")
}
}

func TestFilesystemDataSource_Read(t *testing.T) {
tempDir := t.TempDir()
testFile := "test.txt"
Expand Down
3 changes: 3 additions & 0 deletions tests/test-tar-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ expect_fail "tar-patch missing base dir" ./tar-patch "$TEST_DIR/bad-magic.tardif
# tar-patch: valid delta, missing source file
# Force bsdiff-sized payload + -max-bsdiff-size so the delta emits OPEN for data/only.txt;
# otherwise copyRest-only deltas can apply without that file and expect_fail would flake.
# Temporarily skip on Windows platform due to CI runner failure
if [ "$IS_WINDOWS" != "true" ]; then
mkdir -p "$TEST_DIR/solo/data" "$TEST_DIR/solom/data"
head -c 4096 /dev/zero >"$TEST_DIR/solo/data/only.txt"
cp -a "$TEST_DIR/solo/data/only.txt" "$TEST_DIR/solom/data/only.txt"
Expand All @@ -74,6 +76,7 @@ if [[ -e "$TEST_DIR/solo/data/only.txt" ]]; then
exit 1
fi
expect_fail "tar-patch missing source member" ./tar-patch "$TEST_DIR/solo.tardiff" "$TEST_DIR/solo" "$TEST_DIR/solo-out.tar"
fi

# tar-patch: stdout destination (happy path)
mkdir -p "$TEST_DIR/st/data" "$TEST_DIR/stm/data"
Expand Down
Loading