forked from TrueCloudLab/rclone
onedrive: use token renewer to stop auth errors on long uploads
Fixes #820
This commit is contained in:
parent
bd29015022
commit
74702554da
1 changed files with 17 additions and 7 deletions
|
@ -86,6 +86,7 @@ type Fs struct {
|
||||||
srv *rest.Client // the connection to the one drive server
|
srv *rest.Client // the connection to the one drive server
|
||||||
dirCache *dircache.DirCache // Map of directory path to directory id
|
dirCache *dircache.DirCache // Map of directory path to directory id
|
||||||
pacer *pacer.Pacer // pacer for API calls
|
pacer *pacer.Pacer // pacer for API calls
|
||||||
|
tokenRenewer *oauthutil.Renew // renew the token on expiry
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object describes a one drive object
|
// Object describes a one drive object
|
||||||
|
@ -179,7 +180,7 @@ func errorHandler(resp *http.Response) error {
|
||||||
// NewFs constructs an Fs from the path, container:path
|
// NewFs constructs an Fs from the path, container:path
|
||||||
func NewFs(name, root string) (fs.Fs, error) {
|
func NewFs(name, root string) (fs.Fs, error) {
|
||||||
root = parsePath(root)
|
root = parsePath(root)
|
||||||
oAuthClient, _, err := oauthutil.NewClient(name, oauthConfig)
|
oAuthClient, ts, err := oauthutil.NewClient(name, oauthConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to configure One Drive: %v", err)
|
log.Fatalf("Failed to configure One Drive: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -199,6 +200,12 @@ func NewFs(name, root string) (fs.Fs, error) {
|
||||||
return nil, errors.Wrap(err, "failed to get root")
|
return nil, errors.Wrap(err, "failed to get root")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renew the token in the background
|
||||||
|
f.tokenRenewer = oauthutil.NewRenew(f.String(), ts, func() error {
|
||||||
|
_, _, err := f.readMetaDataForPath("")
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
|
||||||
f.dirCache = dircache.New(root, rootInfo.ID, f)
|
f.dirCache = dircache.New(root, rootInfo.ID, f)
|
||||||
|
|
||||||
// Find the current root
|
// Find the current root
|
||||||
|
@ -924,6 +931,9 @@ func (o *Object) uploadMultipart(in io.Reader, size int64) (err error) {
|
||||||
//
|
//
|
||||||
// The new object may have been created if an error is returned
|
// The new object may have been created if an error is returned
|
||||||
func (o *Object) Update(in io.Reader, src fs.ObjectInfo) (err error) {
|
func (o *Object) Update(in io.Reader, src fs.ObjectInfo) (err error) {
|
||||||
|
o.fs.tokenRenewer.Start()
|
||||||
|
defer o.fs.tokenRenewer.Stop()
|
||||||
|
|
||||||
size := src.Size()
|
size := src.Size()
|
||||||
modTime := src.ModTime()
|
modTime := src.ModTime()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue