Before this change the Seafile backend reported that it doesn't support modification times, so a file uploaded by rclone got the time of the upload as its modification time and rclone compared files by size only. A file which changed without changing its size was not seen as changed by sync or bisync - in both directions. Since Seafile server 12.0.4 the upload API reads an optional last_modify field (RFC 3339) and uses it as the modification time of the uploaded file (haiwen/seafile-server#666). rclone now sends this field when the server is 12.0.4 or newer and reports a precision of 1 second there. The time still can't be changed without uploading the file again, so SetModTime keeps returning fs.ErrorCantSetModTime and rclone uploads the file again when only the time differs. Older servers behave as before. Tested against Seafile Server CE 13.0.28 (docker image): a file uploaded with rclone now lists with its original modification time (to the second), and bisync picks up same-size changes on both sides. The backend integration tests give the same results with and without this change (the existing failures are unrelated to modification times), and the modification time tests (ObjectModTime, FsPrecision) pass. The precision in docs/data/backends/seafile.yaml is updated to 1s, as reported by the current Seafile docker image. Fixes #8337
117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
package seafile
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"time"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/fs/hash"
|
|
)
|
|
|
|
// Object describes a seafile object (also commonly called a file)
|
|
type Object struct {
|
|
fs *Fs // what this object is part of
|
|
remote string // The remote path (full path containing library name if target at root)
|
|
pathInLibrary string // Path of the object without the library name
|
|
size int64 // size of the object
|
|
modTime time.Time // modification time of the object
|
|
libraryID string // Needed to download the file
|
|
}
|
|
|
|
// ==================== Interface fs.DirEntry ====================
|
|
|
|
// Return a string version
|
|
func (o *Object) String() string {
|
|
if o == nil {
|
|
return "<nil>"
|
|
}
|
|
return o.remote
|
|
}
|
|
|
|
// Remote returns the remote string
|
|
func (o *Object) Remote() string {
|
|
return o.remote
|
|
}
|
|
|
|
// ModTime returns last modified time
|
|
func (o *Object) ModTime(context.Context) time.Time {
|
|
return o.modTime
|
|
}
|
|
|
|
// Size returns the size of an object in bytes
|
|
func (o *Object) Size() int64 {
|
|
return o.size
|
|
}
|
|
|
|
// ==================== Interface fs.ObjectInfo ====================
|
|
|
|
// Fs returns the parent Fs
|
|
func (o *Object) Fs() fs.Info {
|
|
return o.fs
|
|
}
|
|
|
|
// Hash returns the selected checksum of the file
|
|
// If no checksum is available it returns ""
|
|
func (o *Object) Hash(ctx context.Context, ty hash.Type) (string, error) {
|
|
return "", hash.ErrUnsupported
|
|
}
|
|
|
|
// Storable says whether this object can be stored
|
|
func (o *Object) Storable() bool {
|
|
return true
|
|
}
|
|
|
|
// ==================== Interface fs.Object ====================
|
|
|
|
// SetModTime sets the metadata on the object to set the modification date
|
|
func (o *Object) SetModTime(ctx context.Context, t time.Time) error {
|
|
return fs.ErrorCantSetModTime
|
|
}
|
|
|
|
// Open opens the file for read. Call Close() on the returned io.ReadCloser
|
|
func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) {
|
|
downloadLink, err := o.fs.getDownloadLink(ctx, o.libraryID, o.pathInLibrary)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reader, err := o.fs.download(ctx, downloadLink, o.Size(), options...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return reader, nil
|
|
}
|
|
|
|
// Update in to the object with the modTime given of the given size
|
|
//
|
|
// When called from outside an Fs by rclone, src.Size() will always be >= 0.
|
|
// But for unknown-sized objects (indicated by src.Size() == -1), Upload should either
|
|
// return an error or update the object properly (rather than e.g. calling panic).
|
|
func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
|
|
uploadLink, err := o.fs.getUploadLink(ctx, o.libraryID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// The upload can't be retried here as the input stream can't be re-read and
|
|
// the upload link is single use, so upload returns a retry
|
|
// error for the caller to retry with a fresh stream.
|
|
uploaded, err := o.fs.upload(ctx, in, uploadLink, o.pathInLibrary, src.ModTime(ctx))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// Set the properties from the upload back to the object
|
|
o.size = uploaded.Size
|
|
if o.fs.uploadModTime {
|
|
// The server keeps whole seconds only
|
|
o.modTime = src.ModTime(ctx).Truncate(time.Second)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Remove this object
|
|
func (o *Object) Remove(ctx context.Context) error {
|
|
return o.fs.deleteFile(ctx, o.libraryID, o.pathInLibrary)
|
|
}
|