Skip to content

Commit

Permalink
[ws-daemon] Remove tar file size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
csweichel authored and roboquat committed Mar 31, 2022
1 parent 5af9055 commit 9d36697
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 76 deletions.
12 changes: 2 additions & 10 deletions components/content-service/pkg/archive/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,13 @@ import (

// TarConfig configures tarbal creation/extraction
type TarConfig struct {
MaxSizeBytes int64
UIDMaps []IDMapping
GIDMaps []IDMapping
UIDMaps []IDMapping
GIDMaps []IDMapping
}

// BuildTarbalOption configures the tarbal creation
type TarOption func(o *TarConfig)

// TarbalMaxSize limits the size of a tarbal
func TarbalMaxSize(n int64) TarOption {
return func(o *TarConfig) {
o.MaxSizeBytes = n
}
}

// IDMapping maps user or group IDs
type IDMapping struct {
ContainerID int
Expand Down
9 changes: 1 addition & 8 deletions components/ws-daemon/pkg/content/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,7 @@ func BuildTarbal(ctx context.Context, src string, dst string, fullWorkspaceBacku

defer fout.Close()

targetOut := newLimitWriter(fout, cfg.MaxSizeBytes)
defer func(e *error) {
if targetOut.DidMaxOut() {
*e = ErrMaxSizeExceeded
}
}(&err)

_, err = io.Copy(targetOut, tarout)
_, err = io.Copy(fout, tarout)
if err != nil {
return cleanCorruptedTarballAndReturnError(dst, xerrors.Errorf("cannot write tar file: %w", err))
}
Expand Down
57 changes: 0 additions & 57 deletions components/ws-daemon/pkg/content/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
package content

import (
"context"
"io"
"os"
"path/filepath"
"testing"

carchive "github.com/gitpod-io/gitpod/content-service/pkg/archive"
)

func TestSizeLimitingWriter(t *testing.T) {
Expand Down Expand Up @@ -51,55 +46,3 @@ func TestSizeLimitingWriter(t *testing.T) {
}
}
}

func TestBuildTarbalMaxSize(t *testing.T) {
tests := []struct {
Name string
MaxSize int64
ContentSize int64
Err error
}{
{"positive", 1024 * 1024, 512, nil},
{"too-big", 512, 1024, ErrMaxSizeExceeded},
}

var cleanup []string
for _, test := range tests {
wd, err := os.MkdirTemp("", "")
if err != nil {
t.Errorf("cannot prepare test: %v", err)
continue
}
cleanup = append(cleanup, wd)

err = os.WriteFile(filepath.Join(wd, "content.txt"), make([]byte, test.ContentSize), 0600)
if err != nil {
t.Errorf("cannot prepare test: %v", err)
continue
}

tgt, err := os.CreateTemp("", "")
if err != nil {
t.Errorf("cannot prepare test: %v", err)
continue
}
tgt.Close()
cleanup = append(cleanup, tgt.Name())

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.")
}
}
}

for _, c := range cleanup {
os.RemoveAll(c)
}
}
2 changes: 1 addition & 1 deletion components/ws-daemon/pkg/content/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (s *WorkspaceService) uploadWorkspaceContent(ctx context.Context, sess *ses
defer tmpf.Close()

var opts []archive.TarOption
opts = append(opts, archive.TarbalMaxSize(int64(s.config.WorkspaceSizeLimit)))
opts = append(opts)
if !sess.FullWorkspaceBackup {
mappings := []archive.IDMapping{
{ContainerID: 0, HostID: wsinit.GitpodUID, Size: 1},
Expand Down

0 comments on commit 9d36697

Please sign in to comment.