diff options
author | Kegan Dougal <kegan@matrix.org> | 2021-07-08 10:07:39 +0100 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2021-07-08 10:17:21 +0100 |
commit | 717d16345cf9b93ef1652c34a70e6109f8f9c97e (patch) | |
tree | 35536ff71d4e89e384eda9aa096ccba5d33a4392 /cmd/dendrite-upgrade-tests | |
parent | f2974721d510077405312436cca455a39834a4fd (diff) |
Improve error handling and close files post-tarring
Diffstat (limited to 'cmd/dendrite-upgrade-tests')
-rw-r--r-- | cmd/dendrite-upgrade-tests/main.go | 1 | ||||
-rw-r--r-- | cmd/dendrite-upgrade-tests/tar.go | 8 |
2 files changed, 8 insertions, 1 deletions
diff --git a/cmd/dendrite-upgrade-tests/main.go b/cmd/dendrite-upgrade-tests/main.go index 5b5cf9d7..46e33c1c 100644 --- a/cmd/dendrite-upgrade-tests/main.go +++ b/cmd/dendrite-upgrade-tests/main.go @@ -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) } diff --git a/cmd/dendrite-upgrade-tests/tar.go b/cmd/dendrite-upgrade-tests/tar.go index 9eadbb3d..8c6402a8 100644 --- a/cmd/dendrite-upgrade-tests/tar.go +++ b/cmd/dendrite-upgrade-tests/tar.go @@ -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 { @@ -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 { |