Skip to content

Commit

Permalink
Merge pull request #4010 from kobergj/FixArchiverStatusCode
Browse files Browse the repository at this point in the history
Fix Archiver status codes
  • Loading branch information
kobergj authored Jun 23, 2023
2 parents e2076e5 + 6748a5f commit 919a958
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/omit-spaceroot-when-archiving.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Bugfix: Omit spaceroot when archiving
When archiving a space there was an empty folder named `.` added. This was because of the spaceroot which was wrongly interpreted.
We now omit the space root when creating an archive.

https://github.com/cs3org/reva/pull/4010
https://github.com/cs3org/reva/pull/3999
6 changes: 4 additions & 2 deletions internal/http/services/archiver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ func (s *svc) Handler() http.Handler {
rw.Header().Set("Content-Transfer-Encoding", "binary")

// create the archive
var closeArchive func()
if userAgent.OS == ua.Windows {
err = arch.CreateZip(ctx, rw)
closeArchive, err = arch.CreateZip(ctx, rw)
} else {
err = arch.CreateTar(ctx, rw)
closeArchive, err = arch.CreateTar(ctx, rw)
}
defer closeArchive()

if err != nil {
s.writeHTTPError(rw, err)
Expand Down
20 changes: 12 additions & 8 deletions internal/http/services/archiver/manager/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ 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 {
func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) (func(), error) {
w := tar.NewWriter(dst)
defer w.Close()
closer := func() {
_ = w.Close()
}

var filesCount, sizeFiles int64

Expand Down Expand Up @@ -126,17 +128,19 @@ func (a *Archiver) CreateTar(ctx context.Context, dst io.Writer) error {
})

if err != nil {
return err
return closer, err
}

}
return nil
return closer, nil
}

// CreateZip creates a zip and write it into the dst Writer
func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error {
func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) (func(), error) {
w := zip.NewWriter(dst)
defer w.Close()
closer := func() {
_ = w.Close()
}

var filesCount, sizeFiles int64

Expand Down Expand Up @@ -195,11 +199,11 @@ func (a *Archiver) CreateZip(ctx context.Context, dst io.Writer) error {
})

if err != nil {
return err
return closer, err
}

}
return nil
return closer, nil
}

func isSpaceRoot(info *provider.ResourceInfo) bool {
Expand Down
6 changes: 4 additions & 2 deletions internal/http/services/archiver/manager/archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,11 @@ func TestCreateTar(t *testing.T) {

var tarFile bytes.Buffer

err = arch.CreateTar(ctx, io.Writer(&tarFile))
cl, err := arch.CreateTar(ctx, &tarFile)
if err != tt.err {
t.Fatalf("error result different from expected: got=%v, expected=%v", err, tt.err)
}
cl()

tarTmpDir, cleanup, err := test.TmpDir()
if err != nil {
Expand Down Expand Up @@ -875,10 +876,11 @@ func TestCreateZip(t *testing.T) {

var zipFile bytes.Buffer

err = arch.CreateZip(ctx, io.Writer(&zipFile))
cl, err := arch.CreateZip(ctx, &zipFile)
if err != tt.err {
t.Fatalf("error result different from expected: got=%v, expected=%v", err, tt.err)
}
cl()

if tt.expected != nil {
zipTmpDir, cleanup, err := test.TmpDir()
Expand Down

0 comments on commit 919a958

Please sign in to comment.