Skip to content

Commit

Permalink
[ws-daemon] remove failed backups
Browse files Browse the repository at this point in the history
When a backup failed (mostly due to hitting the size limit)
the tar file hangs around on the node without clean up.

fixes #5324
  • Loading branch information
svenefftinge committed Aug 23, 2021
1 parent a169bc0 commit 6e3f74e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/ws-daemon/pkg/content/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func BuildTarbal(ctx context.Context, src string, dst string, fullWorkspaceBacku
return xerrors.Errorf("cannot open archive for writing: %w", err)
}
defer fout.Close()
defer func(e *error) {
if e != nil {
os.Remove(dst)
}
}(&err)
fbout := bufio.NewWriter(fout)
defer fbout.Flush()

Expand Down
7 changes: 7 additions & 0 deletions components/ws-daemon/pkg/content/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ func TestBuildTarbalMaxSize(t *testing.T) {
err = BuildTarbal(context.Background(), wd, tgt.Name(), false, carchive.TarbalMaxSize(test.MaxSize))
if (err == nil && test.Err != nil) || (err != nil && test.Err == nil) || (err != nil && test.Err != nil && err.Error() != test.Err.Error()) {
t.Errorf("%s: unexpected error: expected \"%v\", actual \"%v\"", test.Name, test.Err, err)
} else {

_, doesNotExistErr := os.Stat(tgt.Name())
doesNotExist := doesNotExistErr != nil && os.IsNotExist(doesNotExistErr)
if err != nil && !doesNotExist {
t.Errorf("The file should be deleted when buildTarbal failed.")
}
}
}

Expand Down

0 comments on commit 6e3f74e

Please sign in to comment.