mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 00:13:49 +01:00
dropbox: make limited fs work (copy single file)
This commit is contained in:
parent
f8bb0d9cc8
commit
7c9bdb4b7a
@ -25,6 +25,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -122,12 +123,6 @@ func (f *FsDropbox) String() string {
|
|||||||
return fmt.Sprintf("Dropbox root '%s'", f.root)
|
return fmt.Sprintf("Dropbox root '%s'", f.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseParse parses a dropbox 'url'
|
|
||||||
func parseDropboxPath(path string) (root string, err error) {
|
|
||||||
root = strings.Trim(path, "/")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makes a new dropbox from the config
|
// Makes a new dropbox from the config
|
||||||
func newDropbox(name string) *dropbox.Dropbox {
|
func newDropbox(name string) *dropbox.Dropbox {
|
||||||
db := dropbox.NewDropbox()
|
db := dropbox.NewDropbox()
|
||||||
@ -147,24 +142,12 @@ func newDropbox(name string) *dropbox.Dropbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewFs contstructs an FsDropbox from the path, container:path
|
// NewFs contstructs an FsDropbox from the path, container:path
|
||||||
func NewFs(name, path string) (fs.Fs, error) {
|
func NewFs(name, root string) (fs.Fs, error) {
|
||||||
db := newDropbox(name)
|
db := newDropbox(name)
|
||||||
|
|
||||||
root, err := parseDropboxPath(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
slashRoot := "/" + root
|
|
||||||
slashRootSlash := slashRoot
|
|
||||||
if root != "" {
|
|
||||||
slashRootSlash += "/"
|
|
||||||
}
|
|
||||||
f := &FsDropbox{
|
f := &FsDropbox{
|
||||||
root: root,
|
db: db,
|
||||||
slashRoot: slashRoot,
|
|
||||||
slashRootSlash: slashRootSlash,
|
|
||||||
db: db,
|
|
||||||
}
|
}
|
||||||
|
f.setRoot(root)
|
||||||
|
|
||||||
// Read the token from the config file
|
// Read the token from the config file
|
||||||
token := fs.ConfigFile.MustValue(name, "token")
|
token := fs.ConfigFile.MustValue(name, "token")
|
||||||
@ -176,31 +159,59 @@ func NewFs(name, path string) (fs.Fs, error) {
|
|||||||
f.datastoreManager = db.NewDatastoreManager()
|
f.datastoreManager = db.NewDatastoreManager()
|
||||||
|
|
||||||
// Open the datastore in the background
|
// Open the datastore in the background
|
||||||
go func() {
|
go f.openDataStore()
|
||||||
f.datastoreMutex.Lock()
|
|
||||||
defer f.datastoreMutex.Unlock()
|
|
||||||
fs.Debug(f, "Open rclone datastore")
|
|
||||||
// Open the rclone datastore
|
|
||||||
f.datastore, err = f.datastoreManager.OpenDatastore(datastoreName)
|
|
||||||
if err != nil {
|
|
||||||
fs.Log(f, "Failed to open datastore: %v", err)
|
|
||||||
f.datastoreErr = err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the table we are using
|
// See if the root is actually an object
|
||||||
f.table, err = f.datastore.GetTable(tableName)
|
entry, err := f.db.Metadata(f.slashRoot, false, false, "", "", metadataLimit)
|
||||||
if err != nil {
|
if err == nil && !entry.IsDir {
|
||||||
fs.Log(f, "Failed to open datastore table: %v", err)
|
remote := path.Base(f.root)
|
||||||
f.datastoreErr = err
|
newRoot := path.Dir(f.root)
|
||||||
return
|
if newRoot == "." {
|
||||||
|
newRoot = ""
|
||||||
}
|
}
|
||||||
fs.Debug(f, "Open rclone datastore finished")
|
f.setRoot(newRoot)
|
||||||
}()
|
obj := f.NewFsObject(remote)
|
||||||
|
// return a Fs Limited to this object
|
||||||
|
return fs.NewLimited(f, obj), nil
|
||||||
|
}
|
||||||
|
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets root in f
|
||||||
|
func (f *FsDropbox) setRoot(root string) {
|
||||||
|
f.root = strings.Trim(root, "/")
|
||||||
|
f.slashRoot = "/" + f.root
|
||||||
|
f.slashRootSlash = f.slashRoot
|
||||||
|
if f.root != "" {
|
||||||
|
f.slashRootSlash += "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Opens the datastore in f
|
||||||
|
func (f *FsDropbox) openDataStore() {
|
||||||
|
f.datastoreMutex.Lock()
|
||||||
|
defer f.datastoreMutex.Unlock()
|
||||||
|
fs.Debug(f, "Open rclone datastore")
|
||||||
|
// Open the rclone datastore
|
||||||
|
var err error
|
||||||
|
f.datastore, err = f.datastoreManager.OpenDatastore(datastoreName)
|
||||||
|
if err != nil {
|
||||||
|
fs.Log(f, "Failed to open datastore: %v", err)
|
||||||
|
f.datastoreErr = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the table we are using
|
||||||
|
f.table, err = f.datastore.GetTable(tableName)
|
||||||
|
if err != nil {
|
||||||
|
fs.Log(f, "Failed to open datastore table: %v", err)
|
||||||
|
f.datastoreErr = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fs.Debug(f, "Open rclone datastore finished")
|
||||||
|
}
|
||||||
|
|
||||||
// Return an FsObject from a path
|
// Return an FsObject from a path
|
||||||
func (f *FsDropbox) newFsObjectWithInfo(remote string, info *dropbox.Entry) (fs.Object, error) {
|
func (f *FsDropbox) newFsObjectWithInfo(remote string, info *dropbox.Entry) (fs.Object, error) {
|
||||||
o := &FsObjectDropbox{
|
o := &FsObjectDropbox{
|
||||||
|
Loading…
Reference in New Issue
Block a user