mirror of
https://github.com/rclone/rclone.git
synced 2025-01-13 20:38:12 +02:00
Fix MimeType propagation
In fs.Copy, don't wrap objects if possible, and if not, then add a MimeType method into the wrapped object.
This commit is contained in:
parent
1cc58e4e09
commit
4ab7e05e02
@ -211,7 +211,7 @@ func MimeType(o ObjectInfo) (mimeType string) {
|
|||||||
// Read the MimeType from the optional interface if available
|
// Read the MimeType from the optional interface if available
|
||||||
if do, ok := o.(MimeTyper); ok {
|
if do, ok := o.(MimeTyper); ok {
|
||||||
mimeType = do.MimeType()
|
mimeType = do.MimeType()
|
||||||
Debugf(o, "Read MimeType as %q", mimeType)
|
// Debugf(o, "Read MimeType as %q", mimeType)
|
||||||
if mimeType != "" {
|
if mimeType != "" {
|
||||||
return mimeType
|
return mimeType
|
||||||
}
|
}
|
||||||
@ -246,6 +246,18 @@ func (o *overrideRemoteObject) Remote() string {
|
|||||||
return o.remote
|
return o.remote
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MimeType returns the mime type of the underlying object or "" if it
|
||||||
|
// can't be worked out
|
||||||
|
func (o *overrideRemoteObject) MimeType() string {
|
||||||
|
if do, ok := o.Object.(MimeTyper); ok {
|
||||||
|
return do.MimeType()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check interface is satisfied
|
||||||
|
var _ MimeTyper = (*overrideRemoteObject)(nil)
|
||||||
|
|
||||||
// Copy src object to dst or f if nil. If dst is nil then it uses
|
// Copy src object to dst or f if nil. If dst is nil then it uses
|
||||||
// remote as the name of the new object.
|
// remote as the name of the new object.
|
||||||
func Copy(f Fs, dst Object, remote string, src Object) (err error) {
|
func Copy(f Fs, dst Object, remote string, src Object) (err error) {
|
||||||
@ -278,8 +290,11 @@ func Copy(f Fs, dst Object, remote string, src Object) (err error) {
|
|||||||
err = errors.Wrap(err, "failed to open source object")
|
err = errors.Wrap(err, "failed to open source object")
|
||||||
} else {
|
} else {
|
||||||
in := NewAccount(in0, src).WithBuffer() // account and buffer the transfer
|
in := NewAccount(in0, src).WithBuffer() // account and buffer the transfer
|
||||||
|
var wrappedSrc ObjectInfo = src
|
||||||
wrappedSrc := &overrideRemoteObject{Object: src, remote: remote}
|
// We try to pass the original object if possible
|
||||||
|
if src.Remote() != remote {
|
||||||
|
wrappedSrc = &overrideRemoteObject{Object: src, remote: remote}
|
||||||
|
}
|
||||||
if doUpdate {
|
if doUpdate {
|
||||||
actionTaken = "Copied (replaced existing)"
|
actionTaken = "Copied (replaced existing)"
|
||||||
err = dst.Update(in, wrappedSrc)
|
err = dst.Update(in, wrappedSrc)
|
||||||
|
Loading…
Reference in New Issue
Block a user