Skip to content

Commit

Permalink
Merge pull request #4007 from kobergj/CloseArchiveWriterProperly
Browse files Browse the repository at this point in the history
Close archive writer properly
  • Loading branch information
kobergj authored Jun 22, 2023
2 parents 85eb1be + 268154a commit 874d1f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/close-archive-writer-properly.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions internal/http/services/archiver/manager/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 874d1f0

Please sign in to comment.