Skip to content

Commit

Permalink
fix: untar file error (#37)
Browse files Browse the repository at this point in the history
* fix: untar file error

* fix: untar file error

* add codecov token
  • Loading branch information
shipengqi authored Sep 6, 2023
1 parent 71dc75a commit a603fe4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- name: codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
fail_ci_if_error: true
files: coverage.out
7 changes: 6 additions & 1 deletion fsutil/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func untar(reader io.Reader, dst string) error {
for {
header, err := tr.Next()
if err != nil {
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
if errors.Is(err, io.EOF) {
break
}
return err
Expand All @@ -114,6 +114,11 @@ func untar(reader io.Reader, dst string) error {
continue
}
dstPath := filepath.Join(dst, header.Name)
baseDir := filepath.Dir(dstPath)
if err = MkDirAll(baseDir); err != nil {
return err
}

switch header.Typeflag {
case tar.TypeDir: // directory
if err = MkDirAll(dstPath); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions fsutil/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ func TestTar(t *testing.T) {
assert.NoError(t, err)
}

func TestTarFile(t *testing.T) {
src := "testdata/src/subdir/c.txt"
dst := "testdata/dst.tar"
defer func() { _ = os.RemoveAll(dst) }()
err := Tar(src, dst)
assert.NoError(t, err)

unsrc := dst
undst := "testdata/src2"
defer func() { _ = os.RemoveAll(undst) }()
err = UnTar(unsrc, undst)
assert.NoError(t, err)
}

func TestCompress(t *testing.T) {
src := "testdata/src"
dst := "testdata/dst.tar.gz"
Expand Down

0 comments on commit a603fe4

Please sign in to comment.