@@ -9,10 +9,8 @@ import (
9
9
"errors"
10
10
"fmt"
11
11
"os"
12
- "os/exec"
13
12
"path/filepath"
14
13
"strings"
15
- "time"
16
14
17
15
"github.com/gitpod-io/gitpod/common-go/log"
18
16
"github.com/gitpod-io/gitpod/content-service/pkg/archive"
@@ -291,48 +289,36 @@ func (s3st *s3Storage) DownloadSnapshot(ctx context.Context, destination string,
291
289
return s3st .download (ctx , destination , name , mappings )
292
290
}
293
291
294
- // download object using s5cmd (prior to which we used aws sdk)
295
292
func (s3st * s3Storage ) download (ctx context.Context , destination string , obj string , mappings []archive.IDMapping ) (found bool , err error ) {
296
- tempFile , err := os .CreateTemp ("" , "temporal-s3-file" )
293
+ downloader := s3manager .NewDownloader (s3st .client , func (d * s3manager.Downloader ) {
294
+ d .Concurrency = defaultCopyConcurrency
295
+ d .PartSize = defaultPartSize * megabytes
296
+ d .BufferProvider = s3manager .NewPooledBufferedWriterReadFromProvider (25 * megabytes )
297
+ })
298
+
299
+ s3File , err := os .CreateTemp ("" , "temporal-s3-file" )
297
300
if err != nil {
298
301
return true , xerrors .Errorf ("creating temporal file: %s" , err .Error ())
299
302
}
300
- tempFile .Close ()
301
-
302
- args := []string {
303
- "cp" ,
304
- // # of file parts to download at once
305
- "--concurrency" , "20" ,
306
- // size in MB of each part
307
- "--part-size" , "25" ,
308
- destination ,
309
- tempFile .Name (),
310
- }
311
- cmd := exec .Command ("s5cmd" , args ... )
312
- downloadStart := time .Now ()
313
- out , err := cmd .CombinedOutput ()
303
+ defer os .Remove (s3File .Name ())
304
+
305
+ _ , err = downloader .Download (ctx , s3File , & s3.GetObjectInput {
306
+ Bucket : aws .String (s3st .Config .Bucket ),
307
+ Key : aws .String (obj ),
308
+ })
314
309
if err != nil {
315
- log .WithError (err ).WithField ("out" , string (out )).Error ("unexpected error downloading file" )
316
- return false , xerrors .Errorf ("unexpected error downloading file" )
310
+ return false , err
317
311
}
318
- downloadDuration := time .Since (downloadStart )
319
- log .WithField ("downloadDuration" , downloadDuration .String ()).Info ("S3 download duration" )
320
312
321
- tempFile , err = os . Open ( tempFile . Name () )
313
+ _ , err = s3File . Seek ( 0 , 0 )
322
314
if err != nil {
323
- return true , xerrors . Errorf ( "unexpected error opening downloaded file" )
315
+ return false , err
324
316
}
325
317
326
- defer os .Remove (tempFile .Name ())
327
- defer tempFile .Close ()
328
-
329
- extractStart := time .Now ()
330
- err = archive .ExtractTarbal (ctx , tempFile , destination , archive .WithUIDMapping (mappings ), archive .WithGIDMapping (mappings ))
318
+ err = archive .ExtractTarbal (ctx , s3File , destination , archive .WithUIDMapping (mappings ), archive .WithGIDMapping (mappings ))
331
319
if err != nil {
332
320
return true , xerrors .Errorf ("tar %s: %s" , destination , err .Error ())
333
321
}
334
- extractDuration := time .Since (extractStart )
335
- log .WithField ("extractdDuration" , extractDuration .String ()).Info ("tarbar extraction duration" )
336
322
337
323
return true , nil
338
324
}
0 commit comments