mirror of
https://github.com/rclone/rclone.git
synced 2024-12-01 21:04:56 +01:00
onedrive: Removed upload cutoff and always do session uploads
Set modtime on copy
Added versioning issue to OneDrive documentation
(cherry picked from commit 7f74403
)
This commit is contained in:
parent
b709f73aab
commit
e114be11ec
@ -43,7 +43,6 @@ const (
|
|||||||
driveTypePersonal = "personal"
|
driveTypePersonal = "personal"
|
||||||
driveTypeBusiness = "business"
|
driveTypeBusiness = "business"
|
||||||
driveTypeSharepoint = "documentLibrary"
|
driveTypeSharepoint = "documentLibrary"
|
||||||
singlePartUploadSizeLimit = fs.SizeSuffix(4 * 1024 * 1024)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
@ -843,8 +842,9 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need to copy the modification date from the source
|
// Copy does NOT copy the modTime from the source and there seems to
|
||||||
// since onedrive sets the current date for the newly created file
|
// be no way to set date before
|
||||||
|
// This will create TWO versions on OneDrive
|
||||||
err = dstObj.SetModTime(srcObj.ModTime())
|
err = dstObj.SetModTime(srcObj.ModTime())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1364,49 +1364,6 @@ func (o *Object) uploadMultipart(in io.Reader, size int64, modTime time.Time) (i
|
|||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// uploadSinglepart uploads a file as a single part
|
|
||||||
func (o *Object) uploadSinglepart(in io.Reader, size int64, modTime time.Time) (info *api.Item, err error) {
|
|
||||||
var resp *http.Response
|
|
||||||
var opts rest.Opts
|
|
||||||
_, directoryID, _ := o.fs.dirCache.FindPath(o.remote, false)
|
|
||||||
_, drive, rootURL := parseDirID(directoryID)
|
|
||||||
if drive != "" {
|
|
||||||
opts = rest.Opts{
|
|
||||||
Method: "PUT",
|
|
||||||
RootURL: rootURL,
|
|
||||||
Path: "/" + drive + "/root:/" + rest.URLPathEscape(o.srvPath()) + ":/content",
|
|
||||||
ContentLength: &size,
|
|
||||||
Body: in,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
opts = rest.Opts{
|
|
||||||
Method: "PUT",
|
|
||||||
Path: "/root:/" + rest.URLPathEscape(o.srvPath()) + ":/content",
|
|
||||||
ContentLength: &size,
|
|
||||||
Body: in,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// for go1.8 (see release notes) we must nil the Body if we want a
|
|
||||||
// "Content-Length: 0" header which onedrive requires for all files.
|
|
||||||
if size == 0 {
|
|
||||||
opts.Body = nil
|
|
||||||
}
|
|
||||||
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
|
||||||
resp, err = o.fs.srv.CallJSON(&opts, nil, &info)
|
|
||||||
return shouldRetry(resp, err)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = o.setMetaData(info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// Set the mod time now and read metadata
|
|
||||||
return o.setModTime(modTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the object with the contents of the io.Reader, modTime and size
|
// Update the object with the contents of the io.Reader, modTime and size
|
||||||
//
|
//
|
||||||
// The new object may have been created if an error is returned
|
// The new object may have been created if an error is returned
|
||||||
@ -1417,24 +1374,13 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOptio
|
|||||||
size := src.Size()
|
size := src.Size()
|
||||||
modTime := src.ModTime()
|
modTime := src.ModTime()
|
||||||
|
|
||||||
var info *api.Item
|
info, err := o.uploadMultipart(in, size, modTime)
|
||||||
if size <= int64(singlePartUploadSizeLimit) {
|
|
||||||
info, err = o.uploadSinglepart(in, size, modTime)
|
|
||||||
} else {
|
|
||||||
info, err = o.uploadMultipart(in, size, modTime)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// is the info set by either the multipart upload OR the single PUT for smaller files?
|
|
||||||
if nil != info {
|
|
||||||
return o.setMetaData(info)
|
return o.setMetaData(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove an object
|
// Remove an object
|
||||||
func (o *Object) Remove() error {
|
func (o *Object) Remove() error {
|
||||||
return o.fs.deleteObject(o.id)
|
return o.fs.deleteObject(o.id)
|
||||||
|
Loading…
Reference in New Issue
Block a user