diff --git a/changelog/unreleased/close-archive-writer-properly.md b/changelog/unreleased/close-archive-writer-properly.md new file mode 100644 index 0000000000..a7b5c4f170 --- /dev/null +++ b/changelog/unreleased/close-archive-writer-properly.md @@ -0,0 +1,6 @@ +Bugfix: Close archive writer properly + +When running into max size error (or random other error) the archiver would not close the writer. Only it success case it would. +This resulted in broken archives on the client. We now `defer` the writer close. + +https://github.com/cs3org/reva/pull/4007 diff --git a/internal/http/services/archiver/manager/archiver.go b/internal/http/services/archiver/manager/archiver.go index 7fdfd84c64..da5c406495 100644 --- a/internal/http/services/archiver/manager/archiver.go +++ b/internal/http/services/archiver/manager/archiver.go @@ -63,6 +63,7 @@ func NewArchiver(r []*provider.ResourceId, w walker.Walker, d downloader.Downloa // CreateTar creates a tar and write it into the dst Writer func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) error { w := tar.NewWriter(dst) + defer w.Close() var filesCount, sizeFiles int64 @@ -129,12 +130,13 @@ func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) error { } } - return w.Close() + return nil } // CreateZip creates a zip and write it into the dst Writer func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error { w := zip.NewWriter(dst) + defer w.Close() var filesCount, sizeFiles int64 @@ -197,7 +199,7 @@ func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error { } } - return w.Close() + return nil } func isSpaceRoot(info *provider.ResourceInfo) bool {