Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Improve error handling and close files post-tarring
Browse files Browse the repository at this point in the history
  • Loading branch information
kegsay committed Jul 8, 2021
1 parent f297472 commit 717d163
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/dendrite-upgrade-tests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func downloadArchive(cli *http.Client, tmpDir, archiveURL string, dockerfile []b
if resp.StatusCode != 200 {
return nil, fmt.Errorf("got HTTP %d", resp.StatusCode)
}
_ = os.RemoveAll(tmpDir)
if err = os.Mkdir(tmpDir, os.ModePerm); err != nil {
return nil, fmt.Errorf("failed to make temporary directory: %s", err)
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/dendrite-upgrade-tests/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func compress(src string, buf io.Writer) error {
tw := tar.NewWriter(zr)

// walk through every file in the folder
_ = filepath.Walk(src, func(file string, fi os.FileInfo, e error) error {
err := filepath.Walk(src, func(file string, fi os.FileInfo, e error) error {
// generate tar header
header, err := tar.FileInfoHeader(fi, file)
if err != nil {
Expand All @@ -40,9 +40,15 @@ func compress(src string, buf io.Writer) error {
if _, err := io.Copy(tw, data); err != nil {
return err
}
if err = data.Close(); err != nil {
return err
}
}
return nil
})
if err != nil {
return err
}

// produce tar
if err := tw.Close(); err != nil {
Expand Down

0 comments on commit 717d163

Please sign in to comment.