From 224f8dca4249374e13031807779c214c69a0782d Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sun, 15 Aug 2021 10:40:58 +0200 Subject: [PATCH] s3 and storj storage: use nill when purgeDays is 0 --- server/storage.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/storage.go b/server/storage.go index 1e4e719..a0cdbe4 100644 --- a/server/storage.go +++ b/server/storage.go @@ -273,11 +273,16 @@ func (s *S3Storage) Put(token string, filename string, reader io.Reader, content u.LeavePartsOnError = false }) + var expire *time.Time + if s.purgeDays.Hours() > 0 { + expire = aws.Time(time.Now().Add(s.purgeDays)) + } + _, err = uploader.Upload(&s3manager.UploadInput{ Bucket: aws.String(s.bucket), Key: aws.String(key), Body: reader, - Expires: aws.Time(time.Now().Add(s.purgeDays)), + Expires: expire, }) return @@ -713,7 +718,12 @@ func (s *StorjStorage) Put(token string, filename string, reader io.Reader, cont ctx := context.TODO() - writer, err := s.project.UploadObject(ctx, s.bucket.Name, key, &uplink.UploadOptions{Expires: time.Now().Add(s.purgeDays)}) + var uploadOptions *uplink.UploadOptions + if s.purgeDays.Hours() > 0 { + uploadOptions = &uplink.UploadOptions{Expires: time.Now().Add(s.purgeDays)} + } + + writer, err := s.project.UploadObject(ctx, s.bucket.Name, key, uploadOptions) if err != nil { return err }