Skip to content

Commit

Permalink
refactor: set directly to the fields
Browse files Browse the repository at this point in the history
  • Loading branch information
denizsurmeli committed Sep 11, 2023
1 parent c177bb2 commit b55e596
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
43 changes: 23 additions & 20 deletions command/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,23 +690,24 @@ func (c Copy) doUpload(ctx context.Context, srcurl *url.URL, dsturl *url.URL, ex
return err
}

metadata := storage.Metadata{UserDefined: extradata}
metadata.ACL = c.acl
metadata.CacheControl = c.cacheControl
metadata.Expires = c.expires
metadata.StorageClass = string(c.storageClass)
metadata := storage.Metadata{
UserDefined: extradata,
ACL: c.acl,
CacheControl: c.cacheControl,
Expires: c.expires,
StorageClass: string(c.storageClass),
ContentEncoding: c.contentEncoding,
ContentDisposition: c.contentDisposition,
EncryptionMethod: c.encryptionMethod,
EncryptionKeyID: c.encryptionKeyID,
}

if c.contentType != "" {
metadata.ContentType = c.contentType
} else {
metadata.ContentType = guessContentType(file)
}

metadata.ContentEncoding = c.contentEncoding
metadata.ContentDisposition = c.contentDisposition
metadata.EncryptionMethod = c.encryptionMethod
metadata.EncryptionKeyID = c.encryptionKeyID

reader := newCountingReaderWriter(file, c.progressbar)
err = dstClient.Put(ctx, reader, dsturl, metadata, c.concurrency, c.partSize)

Expand Down Expand Up @@ -753,16 +754,18 @@ func (c Copy) doCopy(ctx context.Context, srcurl, dsturl *url.URL, extradata map
return err
}

metadata := storage.Metadata{UserDefined: extradata}
metadata.ACL = c.acl
metadata.CacheControl = c.cacheControl
metadata.Expires = c.expires
metadata.StorageClass = string(c.storageClass)
metadata.ContentType = c.contentType
metadata.ContentEncoding = c.contentEncoding
metadata.ContentDisposition = c.contentDisposition
metadata.EncryptionMethod = c.encryptionMethod
metadata.EncryptionKeyID = c.encryptionKeyID
metadata := storage.Metadata{
UserDefined: extradata,
ACL: c.acl,
CacheControl: c.cacheControl,
Expires: c.expires,
StorageClass: string(c.storageClass),
ContentType: c.contentType,
ContentEncoding: c.contentEncoding,
ContentDisposition: c.contentDisposition,
EncryptionMethod: c.encryptionMethod,
EncryptionKeyID: c.encryptionKeyID,
}

err = c.shouldOverride(ctx, srcurl, dsturl)
if err != nil {
Expand Down
21 changes: 12 additions & 9 deletions command/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,23 @@ func (c Pipe) Run(ctx context.Context) error {
return err
}

metadata := storage.Metadata{UserDefined: c.metadata}
metadata.ACL = c.acl
metadata.CacheControl = c.cacheControl
metadata.Expires = c.expires
metadata.StorageClass = string(c.storageClass)
metadata := storage.Metadata{
UserDefined: c.metadata,
ACL: c.acl,
CacheControl: c.cacheControl,
Expires: c.expires,
StorageClass: string(c.storageClass),
ContentEncoding: c.contentEncoding,
ContentDisposition: c.contentDisposition,
EncryptionMethod: c.encryptionMethod,
EncryptionKeyID: c.encryptionKeyID,
}

if c.contentType != "" {
metadata.ContentType = c.contentType
} else {
metadata.ContentType = guessContentTypeByExtension(c.dst)
}
metadata.ContentEncoding = c.contentEncoding
metadata.ContentDisposition = c.contentDisposition
metadata.EncryptionMethod = c.encryptionMethod
metadata.EncryptionKeyID = c.encryptionKeyID

err = client.Put(ctx, &stdin{file: os.Stdin}, c.dst, metadata, c.concurrency, c.partSize)
if err != nil {
Expand Down

0 comments on commit b55e596

Please sign in to comment.