mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 13:26:11 +08:00
Support setting modification times on Koofr backend.
Configuration time option to disable the above for if using Dropbox (does not allow setting mtime on copy) or Amazon Drive (neither on upload nor on copy).
This commit is contained in:
parent
3df9dbf887
commit
a35aa1360e
|
@ -40,6 +40,12 @@ func init() {
|
||||||
Required: false,
|
Required: false,
|
||||||
Default: "",
|
Default: "",
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: "setmtime",
|
||||||
|
Help: "Does the backend support setting modification time. Set this to false if you use a mount ID that points to a Dropbox or Amazon Drive backend.",
|
||||||
|
Default: true,
|
||||||
|
Required: true,
|
||||||
|
Advanced: true,
|
||||||
}, {
|
}, {
|
||||||
Name: "user",
|
Name: "user",
|
||||||
Help: "Your Koofr user name",
|
Help: "Your Koofr user name",
|
||||||
|
@ -60,6 +66,7 @@ type Options struct {
|
||||||
MountID string `config:"mountid"`
|
MountID string `config:"mountid"`
|
||||||
User string `config:"user"`
|
User string `config:"user"`
|
||||||
Password string `config:"password"`
|
Password string `config:"password"`
|
||||||
|
SetMTime bool `config:"setmtime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Fs is a representation of a remote Koofr Fs
|
// A Fs is a representation of a remote Koofr Fs
|
||||||
|
@ -140,7 +147,7 @@ func (o *Object) Storable() bool {
|
||||||
|
|
||||||
// SetModTime is not supported
|
// SetModTime is not supported
|
||||||
func (o *Object) SetModTime(ctx context.Context, mtime time.Time) error {
|
func (o *Object) SetModTime(ctx context.Context, mtime time.Time) error {
|
||||||
return nil
|
return fs.ErrorCantSetModTimeWithoutDelete
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open opens the Object for reading
|
// Open opens the Object for reading
|
||||||
|
@ -179,10 +186,12 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadClo
|
||||||
|
|
||||||
// Update updates the Object contents
|
// Update updates the Object contents
|
||||||
func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
|
func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
|
||||||
putopts := &koofrclient.PutFilter{
|
mtime := src.ModTime(ctx).UnixNano() / 1000 / 1000
|
||||||
ForceOverwrite: true,
|
putopts := &koofrclient.PutOptions{
|
||||||
NoRename: true,
|
ForceOverwrite: true,
|
||||||
IgnoreNonExisting: true,
|
NoRename: true,
|
||||||
|
OverwriteIgnoreNonExisting: true,
|
||||||
|
SetModified: &mtime,
|
||||||
}
|
}
|
||||||
fullPath := o.fullPath()
|
fullPath := o.fullPath()
|
||||||
dirPath := dir(fullPath)
|
dirPath := dir(fullPath)
|
||||||
|
@ -191,7 +200,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
info, err := o.fs.client.FilesPutOptions(o.fs.mountID, dirPath, name, in, putopts)
|
info, err := o.fs.client.FilesPutWithOptions(o.fs.mountID, dirPath, name, in, putopts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -226,7 +235,10 @@ func (f *Fs) Features() *fs.Features {
|
||||||
|
|
||||||
// Precision denotes that setting modification times is not supported
|
// Precision denotes that setting modification times is not supported
|
||||||
func (f *Fs) Precision() time.Duration {
|
func (f *Fs) Precision() time.Duration {
|
||||||
return fs.ModTimeNotSupported
|
if !f.opt.SetMTime {
|
||||||
|
return fs.ModTimeNotSupported
|
||||||
|
}
|
||||||
|
return time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hashes returns a set of hashes are Provided by the Fs
|
// Hashes returns a set of hashes are Provided by the Fs
|
||||||
|
@ -336,10 +348,12 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (obj fs.Object, err e
|
||||||
|
|
||||||
// Put updates a remote Object
|
// Put updates a remote Object
|
||||||
func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (obj fs.Object, err error) {
|
func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (obj fs.Object, err error) {
|
||||||
putopts := &koofrclient.PutFilter{
|
mtime := src.ModTime(ctx).UnixNano() / 1000 / 1000
|
||||||
ForceOverwrite: true,
|
putopts := &koofrclient.PutOptions{
|
||||||
NoRename: true,
|
ForceOverwrite: true,
|
||||||
IgnoreNonExisting: true,
|
NoRename: true,
|
||||||
|
OverwriteIgnoreNonExisting: true,
|
||||||
|
SetModified: &mtime,
|
||||||
}
|
}
|
||||||
fullPath := f.fullPath(src.Remote())
|
fullPath := f.fullPath(src.Remote())
|
||||||
dirPath := dir(fullPath)
|
dirPath := dir(fullPath)
|
||||||
|
@ -348,7 +362,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info, err := f.client.FilesPutOptions(f.mountID, dirPath, name, in, putopts)
|
info, err := f.client.FilesPutWithOptions(f.mountID, dirPath, name, in, putopts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, translateErrorsObject(err)
|
return nil, translateErrorsObject(err)
|
||||||
}
|
}
|
||||||
|
@ -466,9 +480,10 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fs.ErrorCantCopy
|
return nil, fs.ErrorCantCopy
|
||||||
}
|
}
|
||||||
|
mtime := src.ModTime(ctx).UnixNano() / 1000 / 1000
|
||||||
err = f.client.FilesCopy((src.(*Object)).fs.mountID,
|
err = f.client.FilesCopy((src.(*Object)).fs.mountID,
|
||||||
(src.(*Object)).fs.fullPath((src.(*Object)).remote),
|
(src.(*Object)).fs.fullPath((src.(*Object)).remote),
|
||||||
f.mountID, dstFullPath)
|
f.mountID, dstFullPath, koofrclient.CopyOptions{SetModified: &mtime})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fs.ErrorCantCopy
|
return nil, fs.ErrorCantCopy
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user