Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ws-daemon] remove failed backups #5325

Merged
merged 1 commit into from
Aug 23, 2021
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
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