Skip to content

Commit a3924d0

Browse files
authored
Fix crash downloading a non existent file (#47)
1 parent d4cdd0d commit a3924d0

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • components/connections/data_store

components/connections/data_store/s5cmd.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,19 @@ func (c *S5cmdClient) GetFile(object string, bucket string) ([]byte, error) {
9090
return nil, err
9191
}
9292

93-
reader := make([]byte, s5DownloadPartSize)
94-
file := aws.NewWriteAtBuffer(reader)
95-
9693
ctx, cancel := context.WithCancel(context.Background())
9794
defer cancel()
95+
obj, err := c.GetClient().Stat(ctx, storeUrl)
96+
if err != nil {
97+
if err == s5store.ErrGivenObjectNotFound {
98+
zap.S().Errorf("[%s] File not found %s", storeUrl.String())
99+
return nil, fmt.Errorf("File not found %s", storeUrl.String())
100+
}
101+
return nil, err
102+
}
103+
reader := make([]byte, obj.Size)
104+
file := aws.NewWriteAtBuffer(reader)
105+
98106
size, err := c.GetClient().Get(ctx, storeUrl, file, s5DownloadConcurrency, s5DownloadPartSize)
99107
if err != nil {
100108
return nil, err

0 commit comments

Comments
 (0)