2015-09-23 01:47:16 +08:00
|
|
|
// Package dropbox provides an interface to Dropbox object storage
|
2014-07-09 04:59:30 +08:00
|
|
|
package dropbox
|
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
// FIXME dropbox for business would be quite easy to add
|
|
|
|
|
2014-07-09 04:59:30 +08:00
|
|
|
/*
|
2017-06-12 05:43:31 +08:00
|
|
|
The Case folding of PathDisplay problem
|
2017-05-22 04:35:33 +08:00
|
|
|
|
2017-06-12 05:43:31 +08:00
|
|
|
From the docs:
|
2014-07-09 04:59:30 +08:00
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
path_display String. The cased path to be used for display purposes
|
|
|
|
only. In rare instances the casing will not correctly match the user's
|
|
|
|
filesystem, but this behavior will match the path provided in the Core
|
|
|
|
API v1, and at least the last path component will have the correct
|
|
|
|
casing. Changes to only the casing of paths won't be returned by
|
|
|
|
list_folder/continue. This field will be null if the file or folder is
|
|
|
|
not mounted. This field is optional.
|
2017-06-05 23:14:24 +08:00
|
|
|
|
2017-08-10 19:06:50 +08:00
|
|
|
We solve this by not implementing the ListR interface. The dropbox
|
|
|
|
remote will recurse directory by directory only using the last element
|
|
|
|
of path_display and all will be well.
|
2014-07-09 04:59:30 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
2019-06-17 16:34:30 +08:00
|
|
|
"context"
|
2021-11-04 18:12:57 +08:00
|
|
|
"errors"
|
2014-07-09 04:59:30 +08:00
|
|
|
"fmt"
|
|
|
|
"io"
|
2014-07-14 18:24:04 +08:00
|
|
|
"path"
|
2015-08-21 01:36:06 +08:00
|
|
|
"regexp"
|
2014-07-09 04:59:30 +08:00
|
|
|
"strings"
|
|
|
|
"time"
|
2020-11-27 19:49:37 +08:00
|
|
|
"unicode/utf8"
|
2014-07-09 04:59:30 +08:00
|
|
|
|
2021-10-16 12:29:52 +08:00
|
|
|
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox"
|
|
|
|
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/auth"
|
|
|
|
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/common"
|
|
|
|
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
|
|
|
|
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/sharing"
|
|
|
|
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/team"
|
|
|
|
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/users"
|
2019-09-23 21:32:36 +08:00
|
|
|
"github.com/rclone/rclone/backend/dropbox/dbhash"
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/config"
|
|
|
|
"github.com/rclone/rclone/fs/config/configmap"
|
|
|
|
"github.com/rclone/rclone/fs/config/configstruct"
|
|
|
|
"github.com/rclone/rclone/fs/config/obscure"
|
|
|
|
"github.com/rclone/rclone/fs/fserrors"
|
|
|
|
"github.com/rclone/rclone/fs/hash"
|
2023-09-12 23:10:45 +08:00
|
|
|
"github.com/rclone/rclone/lib/batcher"
|
2020-01-15 01:33:35 +08:00
|
|
|
"github.com/rclone/rclone/lib/encoder"
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/lib/oauthutil"
|
|
|
|
"github.com/rclone/rclone/lib/pacer"
|
|
|
|
"github.com/rclone/rclone/lib/readers"
|
2017-05-29 00:55:18 +08:00
|
|
|
"golang.org/x/oauth2"
|
2014-07-09 04:59:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
const (
|
2017-05-22 04:35:33 +08:00
|
|
|
rcloneClientID = "5jcck7diasz0rqy"
|
|
|
|
rcloneEncryptedClientSecret = "fRS5vVLr2v6FbyXYnIgjwBuUAt0osq_QZTXAEcmZ7g"
|
2023-05-12 18:45:53 +08:00
|
|
|
defaultMinSleep = fs.Duration(10 * time.Millisecond)
|
2017-05-29 00:55:18 +08:00
|
|
|
maxSleep = 2 * time.Second
|
|
|
|
decayConstant = 2 // bigger for slower decay, exponential
|
2015-08-26 02:01:37 +08:00
|
|
|
// Upload chunk size - setting too small makes uploads slow.
|
2017-11-22 01:30:50 +08:00
|
|
|
// Chunks are buffered into memory for retries.
|
|
|
|
//
|
2021-03-03 03:11:57 +08:00
|
|
|
// Speed vs chunk size uploading a 1 GiB file on 2017-11-22
|
2017-11-22 01:30:50 +08:00
|
|
|
//
|
2021-08-22 01:54:21 +08:00
|
|
|
// Chunk Size MiB, Speed MiB/s, % of max
|
2017-11-22 01:30:50 +08:00
|
|
|
// 1 1.364 11%
|
|
|
|
// 2 2.443 19%
|
|
|
|
// 4 4.288 33%
|
|
|
|
// 8 6.79 52%
|
|
|
|
// 16 8.916 69%
|
|
|
|
// 24 10.195 79%
|
|
|
|
// 32 10.427 81%
|
|
|
|
// 40 10.96 85%
|
|
|
|
// 48 11.828 91%
|
|
|
|
// 56 11.763 91%
|
|
|
|
// 64 12.047 93%
|
|
|
|
// 96 12.302 95%
|
|
|
|
// 128 12.945 100%
|
|
|
|
//
|
2021-03-03 03:11:57 +08:00
|
|
|
// Choose 48 MiB which is 91% of Maximum speed. rclone by
|
|
|
|
// default does 4 transfers so this should use 4*48 MiB = 192 MiB
|
2017-11-22 01:30:50 +08:00
|
|
|
// by default.
|
2021-03-03 03:11:57 +08:00
|
|
|
defaultChunkSize = 48 * fs.Mebi
|
|
|
|
maxChunkSize = 150 * fs.Mebi
|
2020-11-27 19:49:37 +08:00
|
|
|
// Max length of filename parts: https://help.dropbox.com/installs-integrations/sync-uploads/files-not-syncing
|
|
|
|
maxFileNameLength = 255
|
2018-05-15 01:06:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Description of how to auth for this app
|
|
|
|
dropboxConfig = &oauth2.Config{
|
2021-02-12 00:29:52 +08:00
|
|
|
Scopes: []string{
|
|
|
|
"files.metadata.write",
|
|
|
|
"files.content.write",
|
|
|
|
"files.content.read",
|
|
|
|
"sharing.write",
|
2021-04-13 18:43:00 +08:00
|
|
|
"account_info.read", // needed for About
|
2021-02-12 00:29:52 +08:00
|
|
|
// "file_requests.write",
|
|
|
|
// "members.read", // needed for impersonate - but causes app to need to be approved by Dropbox Team Admin during the flow
|
2021-04-17 23:28:44 +08:00
|
|
|
// "team_data.member"
|
2021-02-12 00:29:52 +08:00
|
|
|
},
|
2018-05-15 01:06:57 +08:00
|
|
|
// Endpoint: oauth2.Endpoint{
|
|
|
|
// AuthURL: "https://www.dropbox.com/1/oauth2/authorize",
|
|
|
|
// TokenURL: "https://api.dropboxapi.com/1/oauth2/token",
|
|
|
|
// },
|
|
|
|
Endpoint: dropbox.OAuthEndpoint(""),
|
|
|
|
ClientID: rcloneClientID,
|
|
|
|
ClientSecret: obscure.MustReveal(rcloneEncryptedClientSecret),
|
|
|
|
RedirectURL: oauthutil.RedirectLocalhostURL,
|
|
|
|
}
|
|
|
|
// A regexp matching path names for files Dropbox ignores
|
|
|
|
// See https://www.dropbox.com/en/help/145 - Ignored files
|
|
|
|
ignoredFiles = regexp.MustCompile(`(?i)(^|/)(desktop\.ini|thumbs\.db|\.ds_store|icon\r|\.dropbox|\.dropbox.attr)$`)
|
2019-09-23 21:32:36 +08:00
|
|
|
|
|
|
|
// DbHashType is the hash.Type for Dropbox
|
|
|
|
DbHashType hash.Type
|
2020-11-26 19:58:43 +08:00
|
|
|
|
|
|
|
// Errors
|
|
|
|
errNotSupportedInSharedMode = fserrors.NoRetryError(errors.New("not supported in shared files mode"))
|
2023-09-12 23:10:45 +08:00
|
|
|
|
|
|
|
// Configure the batcher
|
|
|
|
defaultBatcherOptions = batcher.Options{
|
|
|
|
MaxBatchSize: 1000,
|
|
|
|
DefaultTimeoutSync: 500 * time.Millisecond,
|
|
|
|
DefaultTimeoutAsync: 10 * time.Second,
|
|
|
|
DefaultBatchSizeAsync: 100,
|
|
|
|
}
|
2015-08-26 02:01:37 +08:00
|
|
|
)
|
2015-08-21 01:36:06 +08:00
|
|
|
|
2021-02-12 00:29:52 +08:00
|
|
|
// Gets an oauth config with the right scopes
|
|
|
|
func getOauthConfig(m configmap.Mapper) *oauth2.Config {
|
|
|
|
// If not impersonating, use standard scopes
|
|
|
|
if impersonate, _ := m.Get("impersonate"); impersonate == "" {
|
|
|
|
return dropboxConfig
|
|
|
|
}
|
|
|
|
// Make a copy of the config
|
|
|
|
config := *dropboxConfig
|
2021-04-17 23:28:44 +08:00
|
|
|
// Make a copy of the scopes with extra scopes requires appended
|
|
|
|
config.Scopes = append(config.Scopes, "members.read", "team_data.member")
|
2021-02-12 00:29:52 +08:00
|
|
|
return &config
|
|
|
|
}
|
|
|
|
|
2014-07-09 04:59:30 +08:00
|
|
|
// Register with Fs
|
|
|
|
func init() {
|
2021-05-21 22:32:33 +08:00
|
|
|
DbHashType = hash.RegisterHash("dropbox", "DropboxHash", 64, dbhash.New)
|
2016-02-18 19:35:25 +08:00
|
|
|
fs.Register(&fs.RegInfo{
|
2016-02-16 02:11:53 +08:00
|
|
|
Name: "dropbox",
|
|
|
|
Description: "Dropbox",
|
|
|
|
NewFs: NewFs,
|
2021-04-29 16:28:18 +08:00
|
|
|
Config: func(ctx context.Context, name string, m configmap.Mapper, config fs.ConfigIn) (*fs.ConfigOut, error) {
|
|
|
|
return oauthutil.ConfigOut("", &oauthutil.Options{
|
|
|
|
OAuth2Config: getOauthConfig(m),
|
|
|
|
NoOffline: true,
|
2020-11-23 18:38:52 +08:00
|
|
|
OAuth2Opts: []oauth2.AuthCodeOption{
|
|
|
|
oauth2.SetAuthURLParam("token_access_type", "offline"),
|
|
|
|
},
|
2021-04-29 16:28:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
},
|
2023-09-12 23:10:45 +08:00
|
|
|
Options: append(append(oauthutil.SharedOptions, []fs.Option{{
|
2018-10-02 01:36:15 +08:00
|
|
|
Name: "chunk_size",
|
2021-08-16 17:30:01 +08:00
|
|
|
Help: fmt.Sprintf(`Upload chunk size (< %v).
|
2018-10-02 01:36:15 +08:00
|
|
|
|
|
|
|
Any files larger than this will be uploaded in chunks of this size.
|
|
|
|
|
|
|
|
Note that chunks are buffered in memory (one at a time) so rclone can
|
|
|
|
deal with retries. Setting this larger will increase the speed
|
2021-03-03 03:11:57 +08:00
|
|
|
slightly (at most 10%% for 128 MiB in tests) at the cost of using more
|
2019-01-12 01:17:46 +08:00
|
|
|
memory. It can be set smaller if you are tight on memory.`, maxChunkSize),
|
|
|
|
Default: defaultChunkSize,
|
2018-05-15 01:06:57 +08:00
|
|
|
Advanced: true,
|
2018-09-18 08:35:12 +08:00
|
|
|
}, {
|
2021-02-12 00:29:52 +08:00
|
|
|
Name: "impersonate",
|
|
|
|
Help: `Impersonate this user when using a business account.
|
|
|
|
|
|
|
|
Note that if you want to use impersonate, you should make sure this
|
|
|
|
flag is set when running "rclone config" as this will cause rclone to
|
|
|
|
request the "members.read" scope which it won't normally. This is
|
|
|
|
needed to lookup a members email address into the internal ID that
|
|
|
|
dropbox uses in the API.
|
|
|
|
|
|
|
|
Using the "members.read" scope will require a Dropbox Team Admin
|
|
|
|
to approve during the OAuth flow.
|
|
|
|
|
|
|
|
You will have to use your own App (setting your own client_id and
|
|
|
|
client_secret) to use this option as currently rclone's default set of
|
|
|
|
permissions doesn't include "members.read". This can be added once
|
|
|
|
v1.55 or later is in use everywhere.
|
|
|
|
`,
|
2023-07-07 00:55:53 +08:00
|
|
|
Default: "",
|
|
|
|
Advanced: true,
|
|
|
|
Sensitive: true,
|
2020-08-23 22:10:30 +08:00
|
|
|
}, {
|
|
|
|
Name: "shared_files",
|
|
|
|
Help: `Instructs rclone to work on individual shared files.
|
|
|
|
|
|
|
|
In this mode rclone's features are extremely limited - only list (ls, lsl, etc.)
|
|
|
|
operations and read operations (e.g. downloading) are supported in this mode.
|
|
|
|
All other operations will be disabled.`,
|
|
|
|
Default: false,
|
|
|
|
Advanced: true,
|
|
|
|
}, {
|
|
|
|
Name: "shared_folders",
|
|
|
|
Help: `Instructs rclone to work on shared folders.
|
|
|
|
|
|
|
|
When this flag is used with no path only the List operation is supported and
|
|
|
|
all available shared folders will be listed. If you specify a path the first part
|
|
|
|
will be interpreted as the name of shared folder. Rclone will then try to mount this
|
|
|
|
shared to the root namespace. On success shared folder rclone proceeds normally.
|
|
|
|
The shared folder is now pretty much a normal folder and all normal operations
|
|
|
|
are supported.
|
|
|
|
|
|
|
|
Note that we don't unmount the shared folder afterwards so the
|
|
|
|
--dropbox-shared-folders can be omitted after the first use of a particular
|
|
|
|
shared folder.`,
|
|
|
|
Default: false,
|
|
|
|
Advanced: true,
|
2023-05-12 18:45:53 +08:00
|
|
|
}, {
|
|
|
|
Name: "pacer_min_sleep",
|
|
|
|
Default: defaultMinSleep,
|
|
|
|
Help: "Minimum time to sleep between API calls.",
|
|
|
|
Advanced: true,
|
2020-01-15 01:33:35 +08:00
|
|
|
}, {
|
|
|
|
Name: config.ConfigEncoding,
|
|
|
|
Help: config.ConfigEncodingHelp,
|
|
|
|
Advanced: true,
|
2020-01-15 05:51:49 +08:00
|
|
|
// https://www.dropbox.com/help/syncing-uploads/files-not-syncing lists / and \
|
|
|
|
// as invalid characters.
|
|
|
|
// Testing revealed names with trailing spaces and the DEL character don't work.
|
|
|
|
// Also encode invalid UTF-8 bytes as json doesn't handle them properly.
|
2021-02-24 17:33:31 +08:00
|
|
|
Default: encoder.Base |
|
2020-01-15 05:51:49 +08:00
|
|
|
encoder.EncodeBackSlash |
|
|
|
|
encoder.EncodeDel |
|
|
|
|
encoder.EncodeRightSpace |
|
2021-02-24 17:33:31 +08:00
|
|
|
encoder.EncodeInvalidUtf8,
|
2023-09-12 23:10:45 +08:00
|
|
|
}}...), defaultBatcherOptions.FsOptions("For full info see [the main docs](https://rclone.org/dropbox/#batch-mode)\n\n")...),
|
2014-07-09 04:59:30 +08:00
|
|
|
})
|
2018-05-15 01:06:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Options defines the configuration for this backend
|
|
|
|
type Options struct {
|
2023-09-12 23:10:45 +08:00
|
|
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
|
|
|
Impersonate string `config:"impersonate"`
|
|
|
|
SharedFiles bool `config:"shared_files"`
|
|
|
|
SharedFolders bool `config:"shared_folders"`
|
|
|
|
BatchMode string `config:"batch_mode"`
|
|
|
|
BatchSize int `config:"batch_size"`
|
|
|
|
BatchTimeout fs.Duration `config:"batch_timeout"`
|
|
|
|
AsyncBatch bool `config:"async_batch"`
|
|
|
|
PacerMinSleep fs.Duration `config:"pacer_min_sleep"`
|
|
|
|
Enc encoder.MultiEncoder `config:"encoding"`
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-07 19:14:46 +08:00
|
|
|
// Fs represents a remote dropbox server
|
|
|
|
type Fs struct {
|
2018-03-29 15:10:19 +08:00
|
|
|
name string // name of this remote
|
|
|
|
root string // the path we are working on
|
2018-05-15 01:06:57 +08:00
|
|
|
opt Options // parsed options
|
2021-02-24 17:33:31 +08:00
|
|
|
ci *fs.ConfigInfo // global config
|
2018-03-29 15:10:19 +08:00
|
|
|
features *fs.Features // optional features
|
|
|
|
srv files.Client // the connection to the dropbox server
|
2021-02-24 17:33:31 +08:00
|
|
|
svc files.Client // the connection to the dropbox server (unauthorized)
|
2018-05-28 17:50:31 +08:00
|
|
|
sharing sharing.Client // as above, but for generating sharing links
|
2018-04-17 05:19:25 +08:00
|
|
|
users users.Client // as above, but for accessing user information
|
2018-09-18 08:35:12 +08:00
|
|
|
team team.Client // for the Teams API
|
2018-03-29 15:10:19 +08:00
|
|
|
slashRoot string // root with "/" prefix, lowercase
|
|
|
|
slashRootSlash string // root with "/" prefix and postfix, lowercase
|
2019-02-10 04:52:15 +08:00
|
|
|
pacer *fs.Pacer // To pace the API calls
|
2018-05-28 17:50:31 +08:00
|
|
|
ns string // The namespace we are using or "" for none
|
2023-09-12 23:10:45 +08:00
|
|
|
batcher *batcher.Batcher[*files.UploadSessionFinishArg, *files.FileMetadata]
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2015-11-07 19:14:46 +08:00
|
|
|
// Object describes a dropbox object
|
2017-05-26 22:09:31 +08:00
|
|
|
//
|
|
|
|
// Dropbox Objects always have full metadata
|
2015-11-07 19:14:46 +08:00
|
|
|
type Object struct {
|
2020-08-23 22:10:30 +08:00
|
|
|
fs *Fs // what this object is part of
|
|
|
|
id string
|
|
|
|
url string
|
2017-05-26 22:09:31 +08:00
|
|
|
remote string // The remote path
|
|
|
|
bytes int64 // size of the object
|
|
|
|
modTime time.Time // time it was last modified
|
|
|
|
hash string // content_hash of the object
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// Name of the remote (as passed into NewFs)
|
2015-11-07 19:14:46 +08:00
|
|
|
func (f *Fs) Name() string {
|
2015-08-22 23:53:11 +08:00
|
|
|
return f.name
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// Root of the remote (as passed into NewFs)
|
2015-11-07 19:14:46 +08:00
|
|
|
func (f *Fs) Root() string {
|
2015-09-02 03:45:27 +08:00
|
|
|
return f.root
|
|
|
|
}
|
|
|
|
|
2015-11-07 19:14:46 +08:00
|
|
|
// String converts this Fs to a string
|
|
|
|
func (f *Fs) String() string {
|
2014-07-09 04:59:30 +08:00
|
|
|
return fmt.Sprintf("Dropbox root '%s'", f.root)
|
|
|
|
}
|
|
|
|
|
2017-01-14 01:21:47 +08:00
|
|
|
// Features returns the optional features of this Fs
|
|
|
|
func (f *Fs) Features() *fs.Features {
|
|
|
|
return f.features
|
|
|
|
}
|
|
|
|
|
2017-05-29 00:55:18 +08:00
|
|
|
// shouldRetry returns a boolean as to whether this err deserves to be
|
|
|
|
// retried. It returns the err as a convenience
|
2021-03-11 22:44:01 +08:00
|
|
|
func shouldRetry(ctx context.Context, err error) (bool, error) {
|
|
|
|
if fserrors.ContextError(ctx, &err) {
|
|
|
|
return false, err
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
if err == nil {
|
|
|
|
return false, err
|
|
|
|
}
|
2021-11-04 18:12:57 +08:00
|
|
|
errString := err.Error()
|
2020-11-26 20:10:46 +08:00
|
|
|
// First check for specific errors
|
2021-11-04 18:12:57 +08:00
|
|
|
if strings.Contains(errString, "insufficient_space") {
|
2020-03-26 16:45:35 +08:00
|
|
|
return false, fserrors.FatalError(err)
|
2021-11-04 18:12:57 +08:00
|
|
|
} else if strings.Contains(errString, "malformed_path") {
|
2020-11-26 20:10:46 +08:00
|
|
|
return false, fserrors.NoRetryError(err)
|
2020-03-26 16:45:35 +08:00
|
|
|
}
|
|
|
|
// Then handle any official Retry-After header from Dropbox's SDK
|
2018-12-05 23:11:41 +08:00
|
|
|
switch e := err.(type) {
|
|
|
|
case auth.RateLimitAPIError:
|
|
|
|
if e.RateLimitError.RetryAfter > 0 {
|
2021-11-04 18:12:57 +08:00
|
|
|
fs.Logf(errString, "Too many requests or write operations. Trying again in %d seconds.", e.RateLimitError.RetryAfter)
|
2019-02-10 04:52:15 +08:00
|
|
|
err = pacer.RetryAfterError(err, time.Duration(e.RateLimitError.RetryAfter)*time.Second)
|
2018-12-05 23:11:41 +08:00
|
|
|
}
|
|
|
|
return true, err
|
|
|
|
}
|
2019-02-08 01:41:17 +08:00
|
|
|
// Keep old behavior for backward compatibility
|
2021-11-04 18:12:57 +08:00
|
|
|
if strings.Contains(errString, "too_many_write_operations") || strings.Contains(errString, "too_many_requests") || errString == "" {
|
2017-05-29 00:55:18 +08:00
|
|
|
return true, err
|
|
|
|
}
|
2018-01-13 00:30:54 +08:00
|
|
|
return fserrors.ShouldRetry(err), err
|
2017-05-29 00:55:18 +08:00
|
|
|
}
|
|
|
|
|
2018-09-07 19:02:27 +08:00
|
|
|
func checkUploadChunkSize(cs fs.SizeSuffix) error {
|
2021-03-03 03:11:57 +08:00
|
|
|
const minChunkSize = fs.SizeSuffixBase
|
2018-09-07 19:02:27 +08:00
|
|
|
if cs < minChunkSize {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fmt.Errorf("%s is less than %s", cs, minChunkSize)
|
2018-09-07 19:02:27 +08:00
|
|
|
}
|
|
|
|
if cs > maxChunkSize {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fmt.Errorf("%s is greater than %s", cs, maxChunkSize)
|
2018-09-07 19:02:27 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fs) setUploadChunkSize(cs fs.SizeSuffix) (old fs.SizeSuffix, err error) {
|
|
|
|
err = checkUploadChunkSize(cs)
|
|
|
|
if err == nil {
|
|
|
|
old, f.opt.ChunkSize = f.opt.ChunkSize, cs
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-08 01:41:17 +08:00
|
|
|
// NewFs constructs an Fs from the path, container:path
|
2020-11-05 23:18:51 +08:00
|
|
|
func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, error) {
|
2018-05-15 01:06:57 +08:00
|
|
|
// Parse config into Options struct
|
|
|
|
opt := new(Options)
|
|
|
|
err := configstruct.Set(m, opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-09-07 19:02:27 +08:00
|
|
|
err = checkUploadChunkSize(opt.ChunkSize)
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("dropbox: chunk size: %w", err)
|
2015-08-26 02:01:37 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
// Convert the old token if it exists. The old token was just
|
|
|
|
// just a string, the new one is a JSON blob
|
2018-05-15 01:06:57 +08:00
|
|
|
oldToken, ok := m.Get(config.ConfigToken)
|
|
|
|
oldToken = strings.TrimSpace(oldToken)
|
|
|
|
if ok && oldToken != "" && oldToken[0] != '{' {
|
2017-05-22 04:35:33 +08:00
|
|
|
fs.Infof(name, "Converting token to new format")
|
|
|
|
newToken := fmt.Sprintf(`{"access_token":"%s","token_type":"bearer","expiry":"0001-01-01T00:00:00Z"}`, oldToken)
|
2018-01-13 00:30:54 +08:00
|
|
|
err := config.SetValueAndSave(name, config.ConfigToken, newToken)
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("NewFS convert token: %w", err)
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 00:29:52 +08:00
|
|
|
oAuthClient, _, err := oauthutil.NewClient(ctx, name, m, getOauthConfig(m))
|
2015-09-22 14:31:12 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("failed to configure dropbox: %w", err)
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 17:33:31 +08:00
|
|
|
ci := fs.GetConfig(ctx)
|
|
|
|
|
2015-11-07 19:14:46 +08:00
|
|
|
f := &Fs{
|
2018-05-28 17:50:31 +08:00
|
|
|
name: name,
|
2018-05-15 01:06:57 +08:00
|
|
|
opt: *opt,
|
2021-02-24 17:33:31 +08:00
|
|
|
ci: ci,
|
2023-05-12 18:45:53 +08:00
|
|
|
pacer: fs.NewPacer(ctx, pacer.NewDefault(pacer.MinSleep(opt.PacerMinSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))),
|
2018-05-28 17:50:31 +08:00
|
|
|
}
|
2023-09-12 23:10:45 +08:00
|
|
|
batcherOptions := defaultBatcherOptions
|
|
|
|
batcherOptions.Mode = f.opt.BatchMode
|
|
|
|
batcherOptions.Size = f.opt.BatchSize
|
|
|
|
batcherOptions.Timeout = time.Duration(f.opt.BatchTimeout)
|
|
|
|
f.batcher, err = batcher.New(ctx, f, f.commitBatch, batcherOptions)
|
2020-09-07 18:08:46 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-02-24 17:33:31 +08:00
|
|
|
cfg := dropbox.Config{
|
2018-05-28 17:50:31 +08:00
|
|
|
LogLevel: dropbox.LogOff, // logging in the SDK: LogOff, LogDebug, LogInfo
|
|
|
|
Client: oAuthClient, // maybe???
|
|
|
|
HeaderGenerator: f.headerGenerator,
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
2018-09-18 08:35:12 +08:00
|
|
|
|
2021-02-24 17:33:31 +08:00
|
|
|
// unauthorized config for endpoints that fail with auth
|
|
|
|
ucfg := dropbox.Config{
|
|
|
|
LogLevel: dropbox.LogOff, // logging in the SDK: LogOff, LogDebug, LogInfo
|
|
|
|
}
|
|
|
|
|
2018-09-18 08:35:12 +08:00
|
|
|
// NOTE: needs to be created pre-impersonation so we can look up the impersonated user
|
2021-02-24 17:33:31 +08:00
|
|
|
f.team = team.New(cfg)
|
2018-09-18 08:35:12 +08:00
|
|
|
|
|
|
|
if opt.Impersonate != "" {
|
|
|
|
user := team.UserSelectorArg{
|
|
|
|
Email: opt.Impersonate,
|
|
|
|
}
|
|
|
|
user.Tag = "email"
|
|
|
|
|
|
|
|
members := []*team.UserSelectorArg{&user}
|
|
|
|
args := team.NewMembersGetInfoArgs(members)
|
|
|
|
|
2024-02-12 12:10:24 +08:00
|
|
|
memberIDs, err := f.team.MembersGetInfo(args)
|
2018-09-18 08:35:12 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("invalid dropbox team member: %q: %w", opt.Impersonate, err)
|
2018-09-18 08:35:12 +08:00
|
|
|
}
|
2024-02-12 12:10:24 +08:00
|
|
|
if len(memberIDs) == 0 || memberIDs[0].MemberInfo == nil || memberIDs[0].MemberInfo.Profile == nil {
|
2022-05-06 00:12:57 +08:00
|
|
|
return nil, fmt.Errorf("dropbox team member not found: %q", opt.Impersonate)
|
|
|
|
}
|
2018-09-18 08:35:12 +08:00
|
|
|
|
2024-02-12 12:10:24 +08:00
|
|
|
cfg.AsMemberID = memberIDs[0].MemberInfo.Profile.MemberProfile.TeamMemberId
|
2018-09-18 08:35:12 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 17:33:31 +08:00
|
|
|
f.srv = files.New(cfg)
|
|
|
|
f.svc = files.New(ucfg)
|
|
|
|
f.sharing = sharing.New(cfg)
|
|
|
|
f.users = users.New(cfg)
|
2017-08-09 22:27:43 +08:00
|
|
|
f.features = (&fs.Features{
|
|
|
|
CaseInsensitive: true,
|
2020-11-29 23:11:03 +08:00
|
|
|
ReadMimeType: false,
|
2017-08-09 22:27:43 +08:00
|
|
|
CanHaveEmptyDirectories: true,
|
2020-08-23 22:10:30 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// do not fill features yet
|
|
|
|
if f.opt.SharedFiles {
|
|
|
|
f.setRoot(root)
|
|
|
|
if f.root == "" {
|
|
|
|
return f, nil
|
|
|
|
}
|
2021-03-11 22:44:01 +08:00
|
|
|
_, err := f.findSharedFile(ctx, f.root)
|
2020-08-23 22:10:30 +08:00
|
|
|
f.root = ""
|
|
|
|
if err == nil {
|
|
|
|
return f, fs.ErrorIsFile
|
|
|
|
}
|
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.opt.SharedFolders {
|
|
|
|
f.setRoot(root)
|
|
|
|
if f.root == "" {
|
|
|
|
return f, nil // our root it empty so we probably want to list shared folders
|
|
|
|
}
|
|
|
|
|
|
|
|
dir := path.Dir(f.root)
|
|
|
|
if dir == "." {
|
|
|
|
dir = f.root
|
|
|
|
}
|
|
|
|
|
|
|
|
// root is not empty so we have find the right shared folder if it exists
|
2021-03-11 22:44:01 +08:00
|
|
|
id, err := f.findSharedFolder(ctx, dir)
|
2020-08-23 22:10:30 +08:00
|
|
|
if err != nil {
|
|
|
|
// if we didn't find the specified shared folder we have to bail out here
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// we found the specified shared folder so let's mount it
|
|
|
|
// this will add it to the users normal root namespace and allows us
|
|
|
|
// to actually perform operations on it using the normal api endpoints.
|
2021-03-11 22:44:01 +08:00
|
|
|
err = f.mountSharedFolder(ctx, id)
|
2020-08-23 22:10:30 +08:00
|
|
|
if err != nil {
|
|
|
|
switch e := err.(type) {
|
|
|
|
case sharing.MountFolderAPIError:
|
|
|
|
if e.EndpointError == nil || (e.EndpointError != nil && e.EndpointError.Tag != sharing.MountFolderErrorAlreadyMounted) {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-09-20 14:54:47 +08:00
|
|
|
// if the mount failed we have to abort here
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
|
|
|
// if the mount succeeded it's now a normal folder in the users root namespace
|
|
|
|
// we disable shared folder mode and proceed normally
|
|
|
|
f.opt.SharedFolders = false
|
|
|
|
}
|
|
|
|
|
2020-11-06 00:00:40 +08:00
|
|
|
f.features.Fill(ctx, f)
|
2014-07-09 04:59:30 +08:00
|
|
|
|
2018-05-28 17:50:31 +08:00
|
|
|
// If root starts with / then use the actual root
|
|
|
|
if strings.HasPrefix(root, "/") {
|
|
|
|
var acc *users.FullAccount
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
|
|
|
acc, err = f.users.GetCurrentAccount()
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2018-05-28 17:50:31 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("get current account failed: %w", err)
|
2018-05-28 17:50:31 +08:00
|
|
|
}
|
|
|
|
switch x := acc.RootInfo.(type) {
|
|
|
|
case *common.TeamRootInfo:
|
|
|
|
f.ns = x.RootNamespaceId
|
|
|
|
case *common.UserRootInfo:
|
|
|
|
f.ns = x.RootNamespaceId
|
|
|
|
default:
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("unknown RootInfo type %v %T", acc.RootInfo, acc.RootInfo)
|
2018-05-28 17:50:31 +08:00
|
|
|
}
|
|
|
|
fs.Debugf(f, "Using root namespace %q", f.ns)
|
|
|
|
}
|
2020-08-23 22:10:30 +08:00
|
|
|
f.setRoot(root)
|
2018-05-28 17:50:31 +08:00
|
|
|
|
2014-07-14 18:24:04 +08:00
|
|
|
// See if the root is actually an object
|
2021-11-09 18:10:44 +08:00
|
|
|
if f.root != "" {
|
|
|
|
_, err = f.getFileMetadata(ctx, f.slashRoot)
|
|
|
|
if err == nil {
|
|
|
|
newRoot := path.Dir(f.root)
|
|
|
|
if newRoot == "." {
|
|
|
|
newRoot = ""
|
|
|
|
}
|
|
|
|
f.setRoot(newRoot)
|
|
|
|
// return an error with an fs which points to the parent
|
|
|
|
return f, fs.ErrorIsFile
|
2014-07-12 19:38:30 +08:00
|
|
|
}
|
2014-07-14 18:24:04 +08:00
|
|
|
}
|
2014-07-09 04:59:30 +08:00
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
|
2018-05-28 17:50:31 +08:00
|
|
|
// headerGenerator for dropbox sdk
|
2021-10-16 12:29:52 +08:00
|
|
|
func (f *Fs) headerGenerator(hostType string, namespace string, route string) map[string]string {
|
2018-05-28 17:50:31 +08:00
|
|
|
if f.ns == "" {
|
|
|
|
return map[string]string{}
|
|
|
|
}
|
|
|
|
return map[string]string{
|
|
|
|
"Dropbox-API-Path-Root": `{".tag": "namespace_id", "namespace_id": "` + f.ns + `"}`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-14 18:24:04 +08:00
|
|
|
// Sets root in f
|
2015-11-07 19:14:46 +08:00
|
|
|
func (f *Fs) setRoot(root string) {
|
2014-07-14 18:24:04 +08:00
|
|
|
f.root = strings.Trim(root, "/")
|
2018-04-05 22:28:40 +08:00
|
|
|
f.slashRoot = "/" + f.root
|
2014-07-14 18:24:04 +08:00
|
|
|
f.slashRootSlash = f.slashRoot
|
2018-04-05 22:28:40 +08:00
|
|
|
if f.root != "" {
|
2014-07-14 18:24:04 +08:00
|
|
|
f.slashRootSlash += "/"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
// getMetadata gets the metadata for a file or directory
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) getMetadata(ctx context.Context, objPath string) (entry files.IsMetadata, notFound bool, err error) {
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2018-11-02 20:14:02 +08:00
|
|
|
entry, err = f.srv.GetMetadata(&files.GetMetadataArg{
|
2020-01-15 01:33:35 +08:00
|
|
|
Path: f.opt.Enc.FromStandardPath(objPath),
|
2018-11-02 20:14:02 +08:00
|
|
|
})
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
|
|
|
switch e := err.(type) {
|
|
|
|
case files.GetMetadataAPIError:
|
2019-10-10 23:34:09 +08:00
|
|
|
if e.EndpointError != nil && e.EndpointError.Path != nil && e.EndpointError.Path.Tag == files.LookupErrorNotFound {
|
2017-05-22 04:35:33 +08:00
|
|
|
notFound = true
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// getFileMetadata gets the metadata for a file
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) getFileMetadata(ctx context.Context, filePath string) (fileInfo *files.FileMetadata, err error) {
|
|
|
|
entry, notFound, err := f.getMetadata(ctx, filePath)
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if notFound {
|
|
|
|
return nil, fs.ErrorObjectNotFound
|
|
|
|
}
|
|
|
|
fileInfo, ok := entry.(*files.FileMetadata)
|
|
|
|
if !ok {
|
2021-09-06 20:54:08 +08:00
|
|
|
if _, ok = entry.(*files.FolderMetadata); ok {
|
|
|
|
return nil, fs.ErrorIsDir
|
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
return nil, fs.ErrorNotAFile
|
|
|
|
}
|
|
|
|
return fileInfo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// getDirMetadata gets the metadata for a directory
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) getDirMetadata(ctx context.Context, dirPath string) (dirInfo *files.FolderMetadata, err error) {
|
|
|
|
entry, notFound, err := f.getMetadata(ctx, dirPath)
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if notFound {
|
|
|
|
return nil, fs.ErrorDirNotFound
|
|
|
|
}
|
|
|
|
dirInfo, ok := entry.(*files.FolderMetadata)
|
|
|
|
if !ok {
|
|
|
|
return nil, fs.ErrorIsFile
|
|
|
|
}
|
|
|
|
return dirInfo, nil
|
|
|
|
}
|
|
|
|
|
2016-06-26 04:58:34 +08:00
|
|
|
// Return an Object from a path
|
2014-07-30 00:50:07 +08:00
|
|
|
//
|
2016-06-26 04:23:20 +08:00
|
|
|
// If it can't be found it returns the error fs.ErrorObjectNotFound.
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) newObjectWithInfo(ctx context.Context, remote string, info *files.FileMetadata) (fs.Object, error) {
|
2017-02-25 23:23:27 +08:00
|
|
|
o := &Object{
|
2015-11-07 19:14:46 +08:00
|
|
|
fs: f,
|
|
|
|
remote: remote,
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
2017-02-25 23:23:27 +08:00
|
|
|
var err error
|
2014-07-12 18:46:45 +08:00
|
|
|
if info != nil {
|
2017-02-25 19:09:57 +08:00
|
|
|
err = o.setMetadataFromEntry(info)
|
2014-07-09 04:59:30 +08:00
|
|
|
} else {
|
2021-03-11 22:44:01 +08:00
|
|
|
err = o.readEntryAndSetMetadata(ctx)
|
2017-02-25 19:09:57 +08:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
2016-06-26 04:23:20 +08:00
|
|
|
return o, nil
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2016-06-26 04:23:20 +08:00
|
|
|
// NewObject finds the Object at remote. If it can't be found
|
|
|
|
// it returns the error fs.ErrorObjectNotFound.
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
if f.opt.SharedFiles {
|
2021-03-11 22:44:01 +08:00
|
|
|
return f.findSharedFile(ctx, remote)
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
2021-03-11 22:44:01 +08:00
|
|
|
return f.newObjectWithInfo(ctx, remote, nil)
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2020-08-23 22:10:30 +08:00
|
|
|
// listSharedFoldersApi lists all available shared folders mounted and not mounted
|
|
|
|
// we'll need the id later so we have to return them in original format
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) listSharedFolders(ctx context.Context) (entries fs.DirEntries, err error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
started := false
|
|
|
|
var res *sharing.ListFoldersResult
|
|
|
|
for {
|
|
|
|
if !started {
|
|
|
|
arg := sharing.ListFoldersArgs{
|
|
|
|
Limit: 100,
|
|
|
|
}
|
|
|
|
err := f.pacer.Call(func() (bool, error) {
|
|
|
|
res, err = f.sharing.ListFolders(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2020-08-23 22:10:30 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
started = true
|
|
|
|
} else {
|
|
|
|
arg := sharing.ListFoldersContinueArg{
|
|
|
|
Cursor: res.Cursor,
|
|
|
|
}
|
|
|
|
err := f.pacer.Call(func() (bool, error) {
|
|
|
|
res, err = f.sharing.ListFoldersContinue(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2020-08-23 22:10:30 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("list continue: %w", err)
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
|
|
|
}
|
2020-08-27 07:12:10 +08:00
|
|
|
for _, entry := range res.Entries {
|
|
|
|
leaf := f.opt.Enc.ToStandardName(entry.Name)
|
2023-05-03 17:43:31 +08:00
|
|
|
d := fs.NewDir(leaf, time.Time{}).SetID(entry.SharedFolderId)
|
2020-08-27 07:12:10 +08:00
|
|
|
entries = append(entries, d)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 22:10:30 +08:00
|
|
|
if res.Cursor == "" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return entries, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// findSharedFolder find the id for a given shared folder name
|
|
|
|
// somewhat annoyingly there is no endpoint to query a shared folder by it's name
|
|
|
|
// so our only option is to iterate over all shared folders
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) findSharedFolder(ctx context.Context, name string) (id string, err error) {
|
|
|
|
entries, err := f.listSharedFolders(ctx)
|
2020-08-23 22:10:30 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
for _, entry := range entries {
|
2020-08-27 07:12:10 +08:00
|
|
|
if entry.(*fs.Dir).Remote() == name {
|
|
|
|
return entry.(*fs.Dir).ID(), nil
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", fs.ErrorDirNotFound
|
|
|
|
}
|
|
|
|
|
2021-02-24 17:33:31 +08:00
|
|
|
// mountSharedFolder mount a shared folder to the root namespace
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) mountSharedFolder(ctx context.Context, id string) error {
|
2020-08-23 22:10:30 +08:00
|
|
|
arg := sharing.MountFolderArg{
|
|
|
|
SharedFolderId: id,
|
|
|
|
}
|
|
|
|
err := f.pacer.Call(func() (bool, error) {
|
|
|
|
_, err := f.sharing.MountFolder(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2020-08-23 22:10:30 +08:00
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-24 17:33:31 +08:00
|
|
|
// listReceivedFiles lists shared the user as access to (note this means individual
|
2020-08-23 22:10:30 +08:00
|
|
|
// files not files contained in shared folders)
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) listReceivedFiles(ctx context.Context) (entries fs.DirEntries, err error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
started := false
|
|
|
|
var res *sharing.ListFilesResult
|
|
|
|
for {
|
|
|
|
if !started {
|
|
|
|
arg := sharing.ListFilesArg{
|
|
|
|
Limit: 100,
|
|
|
|
}
|
|
|
|
err := f.pacer.Call(func() (bool, error) {
|
|
|
|
res, err = f.sharing.ListReceivedFiles(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2020-08-23 22:10:30 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
started = true
|
|
|
|
} else {
|
|
|
|
arg := sharing.ListFilesContinueArg{
|
|
|
|
Cursor: res.Cursor,
|
|
|
|
}
|
|
|
|
err := f.pacer.Call(func() (bool, error) {
|
|
|
|
res, err = f.sharing.ListReceivedFilesContinue(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2020-08-23 22:10:30 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("list continue: %w", err)
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, entry := range res.Entries {
|
|
|
|
fmt.Printf("%+v\n", entry)
|
|
|
|
entryPath := entry.Name
|
|
|
|
o := &Object{
|
|
|
|
fs: f,
|
|
|
|
url: entry.PreviewUrl,
|
|
|
|
remote: entryPath,
|
2021-10-16 12:29:52 +08:00
|
|
|
modTime: *entry.TimeInvited,
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
entries = append(entries, o)
|
|
|
|
}
|
|
|
|
if res.Cursor == "" {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entries, nil
|
|
|
|
}
|
|
|
|
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) findSharedFile(ctx context.Context, name string) (o *Object, err error) {
|
|
|
|
files, err := f.listReceivedFiles(ctx)
|
2020-08-23 22:10:30 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, entry := range files {
|
|
|
|
if entry.(*Object).remote == name {
|
|
|
|
return entry.(*Object), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, fs.ErrorObjectNotFound
|
|
|
|
}
|
|
|
|
|
2017-06-12 05:43:31 +08:00
|
|
|
// List the objects and directories in dir into entries. The
|
|
|
|
// entries can be returned in any order but should be for a
|
|
|
|
// complete directory.
|
|
|
|
//
|
|
|
|
// dir should be "" to list the root, and should not have
|
|
|
|
// trailing slashes.
|
|
|
|
//
|
|
|
|
// This should return ErrDirNotFound if the directory isn't
|
|
|
|
// found.
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
if f.opt.SharedFiles {
|
2021-03-11 22:44:01 +08:00
|
|
|
return f.listReceivedFiles(ctx)
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
|
|
|
if f.opt.SharedFolders {
|
2021-03-11 22:44:01 +08:00
|
|
|
return f.listSharedFolders(ctx)
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
|
|
|
|
2016-04-24 04:46:52 +08:00
|
|
|
root := f.slashRoot
|
|
|
|
if dir != "" {
|
|
|
|
root += "/" + dir
|
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
started := false
|
|
|
|
var res *files.ListFolderResult
|
2014-07-12 18:46:45 +08:00
|
|
|
for {
|
2017-05-22 04:35:33 +08:00
|
|
|
if !started {
|
|
|
|
arg := files.ListFolderArg{
|
2020-01-15 01:33:35 +08:00
|
|
|
Path: f.opt.Enc.FromStandardPath(root),
|
2017-06-12 05:43:31 +08:00
|
|
|
Recursive: false,
|
2021-11-09 18:11:59 +08:00
|
|
|
Limit: 1000,
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
|
|
|
if root == "/" {
|
|
|
|
arg.Path = "" // Specify root folder as empty string
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
|
|
|
res, err = f.srv.ListFolder(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
|
|
|
switch e := err.(type) {
|
|
|
|
case files.ListFolderAPIError:
|
2019-10-10 23:34:09 +08:00
|
|
|
if e.EndpointError != nil && e.EndpointError.Path != nil && e.EndpointError.Path.Tag == files.LookupErrorNotFound {
|
2017-05-22 04:35:33 +08:00
|
|
|
err = fs.ErrorDirNotFound
|
|
|
|
}
|
2016-05-07 21:50:35 +08:00
|
|
|
}
|
2017-06-12 05:43:31 +08:00
|
|
|
return nil, err
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
2017-07-08 04:20:07 +08:00
|
|
|
started = true
|
2017-05-22 04:35:33 +08:00
|
|
|
} else {
|
|
|
|
arg := files.ListFolderContinueArg{
|
|
|
|
Cursor: res.Cursor,
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
|
|
|
res, err = f.srv.ListFolderContinue(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("list continue: %w", err)
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, entry := range res.Entries {
|
|
|
|
var fileInfo *files.FileMetadata
|
|
|
|
var folderInfo *files.FolderMetadata
|
|
|
|
var metadata *files.Metadata
|
|
|
|
switch info := entry.(type) {
|
|
|
|
case *files.FolderMetadata:
|
|
|
|
folderInfo = info
|
|
|
|
metadata = &info.Metadata
|
|
|
|
case *files.FileMetadata:
|
|
|
|
fileInfo = info
|
|
|
|
metadata = &info.Metadata
|
|
|
|
default:
|
|
|
|
fs.Errorf(f, "Unknown type %T", entry)
|
|
|
|
continue
|
|
|
|
}
|
2015-05-24 02:56:48 +08:00
|
|
|
|
2017-08-10 19:06:50 +08:00
|
|
|
// Only the last element is reliably cased in PathDisplay
|
|
|
|
entryPath := metadata.PathDisplay
|
2020-01-15 01:33:35 +08:00
|
|
|
leaf := f.opt.Enc.ToStandardName(path.Base(entryPath))
|
2017-08-10 19:06:50 +08:00
|
|
|
remote := path.Join(dir, leaf)
|
2017-05-22 04:35:33 +08:00
|
|
|
if folderInfo != nil {
|
2023-05-03 17:43:31 +08:00
|
|
|
d := fs.NewDir(remote, time.Time{}).SetID(folderInfo.Id)
|
2017-08-10 19:06:50 +08:00
|
|
|
entries = append(entries, d)
|
2017-05-22 04:35:33 +08:00
|
|
|
} else if fileInfo != nil {
|
2021-03-11 22:44:01 +08:00
|
|
|
o, err := f.newObjectWithInfo(ctx, remote, fileInfo)
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
2017-06-12 05:43:31 +08:00
|
|
|
return nil, err
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
2017-06-12 05:43:31 +08:00
|
|
|
entries = append(entries, o)
|
2014-07-12 18:46:45 +08:00
|
|
|
}
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
if !res.HasMore {
|
2016-05-07 21:50:35 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2017-06-12 05:43:31 +08:00
|
|
|
return entries, nil
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put the object
|
|
|
|
//
|
2022-08-05 23:35:41 +08:00
|
|
|
// Copy the reader in to the new object which is returned.
|
2014-07-09 04:59:30 +08:00
|
|
|
//
|
|
|
|
// The new object may have been created if an error is returned
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
if f.opt.SharedFiles || f.opt.SharedFolders {
|
2020-11-26 19:58:43 +08:00
|
|
|
return nil, errNotSupportedInSharedMode
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
2015-11-07 19:14:46 +08:00
|
|
|
// Temporary Object under construction
|
|
|
|
o := &Object{
|
|
|
|
fs: f,
|
2016-02-18 19:35:25 +08:00
|
|
|
remote: src.Remote(),
|
2015-11-07 19:14:46 +08:00
|
|
|
}
|
2019-06-17 16:34:30 +08:00
|
|
|
return o, o.Update(ctx, in, src, options...)
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2017-08-04 03:42:35 +08:00
|
|
|
// PutStream uploads to the remote path with the modTime given of indeterminate size
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) PutStream(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
|
|
|
|
return f.Put(ctx, in, src, options...)
|
2017-08-04 03:42:35 +08:00
|
|
|
}
|
|
|
|
|
2014-07-09 04:59:30 +08:00
|
|
|
// Mkdir creates the container if it doesn't exist
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) Mkdir(ctx context.Context, dir string) error {
|
2020-08-23 22:10:30 +08:00
|
|
|
if f.opt.SharedFiles || f.opt.SharedFolders {
|
2020-11-26 19:58:43 +08:00
|
|
|
return errNotSupportedInSharedMode
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
2016-11-26 05:52:43 +08:00
|
|
|
root := path.Join(f.slashRoot, dir)
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
// can't create or run metadata on root
|
|
|
|
if root == "/" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// check directory doesn't exist
|
2021-03-11 22:44:01 +08:00
|
|
|
_, err := f.getDirMetadata(ctx, root)
|
2014-07-13 17:51:47 +08:00
|
|
|
if err == nil {
|
2017-05-22 04:35:33 +08:00
|
|
|
return nil // directory exists already
|
|
|
|
} else if err != fs.ErrorDirNotFound {
|
|
|
|
return err // some other error
|
|
|
|
}
|
|
|
|
|
|
|
|
// create it
|
|
|
|
arg2 := files.CreateFolderArg{
|
2020-01-15 01:33:35 +08:00
|
|
|
Path: f.opt.Enc.FromStandardPath(root),
|
2014-07-13 17:51:47 +08:00
|
|
|
}
|
2020-11-27 19:49:37 +08:00
|
|
|
// Don't attempt to create filenames that are too long
|
|
|
|
if cErr := checkPathLength(arg2.Path); cErr != nil {
|
|
|
|
return cErr
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2017-08-09 19:58:48 +08:00
|
|
|
_, err = f.srv.CreateFolderV2(&arg2)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2014-07-09 04:59:30 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-05 05:25:14 +08:00
|
|
|
// purgeCheck removes the root directory, if check is set then it
|
|
|
|
// refuses to do so if it has anything in
|
|
|
|
func (f *Fs) purgeCheck(ctx context.Context, dir string, check bool) (err error) {
|
2016-11-26 05:52:43 +08:00
|
|
|
root := path.Join(f.slashRoot, dir)
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
// can't remove root
|
|
|
|
if root == "/" {
|
|
|
|
return errors.New("can't remove root directory")
|
|
|
|
}
|
2023-11-21 20:18:49 +08:00
|
|
|
encRoot := f.opt.Enc.FromStandardPath(root)
|
2017-05-22 04:35:33 +08:00
|
|
|
|
2020-06-05 05:25:14 +08:00
|
|
|
if check {
|
|
|
|
// check directory exists
|
2021-03-11 22:44:01 +08:00
|
|
|
_, err = f.getDirMetadata(ctx, root)
|
2020-06-05 05:25:14 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fmt.Errorf("Rmdir: %w", err)
|
2020-06-05 05:25:14 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
2020-06-05 05:25:14 +08:00
|
|
|
// check directory empty
|
|
|
|
arg := files.ListFolderArg{
|
2023-11-21 20:18:49 +08:00
|
|
|
Path: encRoot,
|
2020-06-05 05:25:14 +08:00
|
|
|
Recursive: false,
|
|
|
|
}
|
|
|
|
if root == "/" {
|
|
|
|
arg.Path = "" // Specify root folder as empty string
|
|
|
|
}
|
|
|
|
var res *files.ListFolderResult
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
|
|
|
res, err = f.srv.ListFolder(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2020-06-05 05:25:14 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fmt.Errorf("Rmdir: %w", err)
|
2020-06-05 05:25:14 +08:00
|
|
|
}
|
|
|
|
if len(res.Entries) != 0 {
|
|
|
|
return errors.New("directory not empty")
|
|
|
|
}
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
// remove it
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2023-11-21 20:18:49 +08:00
|
|
|
_, err = f.srv.DeleteV2(&files.DeleteArg{Path: encRoot})
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2016-11-26 05:52:43 +08:00
|
|
|
return err
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2020-06-05 05:25:14 +08:00
|
|
|
// Rmdir deletes the container
|
|
|
|
//
|
|
|
|
// Returns an error if it isn't empty
|
|
|
|
func (f *Fs) Rmdir(ctx context.Context, dir string) error {
|
2020-08-23 22:10:30 +08:00
|
|
|
if f.opt.SharedFiles || f.opt.SharedFolders {
|
2020-11-26 19:58:43 +08:00
|
|
|
return errNotSupportedInSharedMode
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
2020-06-05 05:25:14 +08:00
|
|
|
return f.purgeCheck(ctx, dir, true)
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// Precision returns the precision
|
2015-11-07 19:14:46 +08:00
|
|
|
func (f *Fs) Precision() time.Duration {
|
2017-05-22 04:35:33 +08:00
|
|
|
return time.Second
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2020-10-14 05:43:40 +08:00
|
|
|
// Copy src to this remote using server-side copy operations.
|
2015-02-15 02:48:08 +08:00
|
|
|
//
|
2022-08-05 23:35:41 +08:00
|
|
|
// This is stored with the remote path given.
|
2015-02-15 02:48:08 +08:00
|
|
|
//
|
2022-08-05 23:35:41 +08:00
|
|
|
// It returns the destination Object and a possible error.
|
2015-02-15 02:48:08 +08:00
|
|
|
//
|
|
|
|
// Will only be called if src.Fs().Name() == f.Name()
|
|
|
|
//
|
|
|
|
// If it isn't possible then return fs.ErrorCantCopy
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
|
2015-11-07 19:14:46 +08:00
|
|
|
srcObj, ok := src.(*Object)
|
2015-02-15 02:48:08 +08:00
|
|
|
if !ok {
|
2017-02-09 19:01:20 +08:00
|
|
|
fs.Debugf(src, "Can't copy - not same remote type")
|
2015-02-15 02:48:08 +08:00
|
|
|
return nil, fs.ErrorCantCopy
|
|
|
|
}
|
|
|
|
|
2015-11-07 19:14:46 +08:00
|
|
|
// Temporary Object under construction
|
|
|
|
dstObj := &Object{
|
|
|
|
fs: f,
|
|
|
|
remote: remote,
|
|
|
|
}
|
2015-02-15 02:48:08 +08:00
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
// Copy
|
2018-11-02 20:14:02 +08:00
|
|
|
arg := files.RelocationArg{
|
|
|
|
RelocationPath: files.RelocationPath{
|
2020-01-15 01:33:35 +08:00
|
|
|
FromPath: f.opt.Enc.FromStandardPath(srcObj.remotePath()),
|
|
|
|
ToPath: f.opt.Enc.FromStandardPath(dstObj.remotePath()),
|
2018-11-02 20:14:02 +08:00
|
|
|
},
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
var err error
|
2017-09-25 03:01:30 +08:00
|
|
|
var result *files.RelocationResult
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2017-09-25 03:01:30 +08:00
|
|
|
result, err = f.srv.CopyV2(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2015-02-15 02:48:08 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("copy failed: %w", err)
|
2015-02-15 02:48:08 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
// Set the metadata
|
2017-09-25 03:01:30 +08:00
|
|
|
fileInfo, ok := result.Metadata.(*files.FileMetadata)
|
2017-05-22 04:35:33 +08:00
|
|
|
if !ok {
|
|
|
|
return nil, fs.ErrorNotAFile
|
|
|
|
}
|
|
|
|
err = dstObj.setMetadataFromEntry(fileInfo)
|
2017-02-25 19:09:57 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("copy failed: %w", err)
|
2017-02-25 19:09:57 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
2015-02-15 02:48:08 +08:00
|
|
|
return dstObj, nil
|
|
|
|
}
|
|
|
|
|
2014-07-09 04:59:30 +08:00
|
|
|
// Purge deletes all the files and the container
|
|
|
|
//
|
2014-07-13 17:53:53 +08:00
|
|
|
// Optional interface: Only implement this if you have a way of
|
|
|
|
// deleting all the files quicker than just running Remove() on the
|
|
|
|
// result of List()
|
2020-06-05 05:25:14 +08:00
|
|
|
func (f *Fs) Purge(ctx context.Context, dir string) (err error) {
|
|
|
|
return f.purgeCheck(ctx, dir, false)
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2020-10-14 05:43:40 +08:00
|
|
|
// Move src to this remote using server-side move operations.
|
2015-09-01 04:05:51 +08:00
|
|
|
//
|
2022-08-05 23:35:41 +08:00
|
|
|
// This is stored with the remote path given.
|
2015-09-01 04:05:51 +08:00
|
|
|
//
|
2022-08-05 23:35:41 +08:00
|
|
|
// It returns the destination Object and a possible error.
|
2015-09-01 04:05:51 +08:00
|
|
|
//
|
|
|
|
// Will only be called if src.Fs().Name() == f.Name()
|
|
|
|
//
|
|
|
|
// If it isn't possible then return fs.ErrorCantMove
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
|
2015-11-07 19:14:46 +08:00
|
|
|
srcObj, ok := src.(*Object)
|
2015-09-01 04:05:51 +08:00
|
|
|
if !ok {
|
2017-02-09 19:01:20 +08:00
|
|
|
fs.Debugf(src, "Can't move - not same remote type")
|
2015-09-01 04:05:51 +08:00
|
|
|
return nil, fs.ErrorCantMove
|
|
|
|
}
|
|
|
|
|
2015-11-07 19:14:46 +08:00
|
|
|
// Temporary Object under construction
|
|
|
|
dstObj := &Object{
|
|
|
|
fs: f,
|
|
|
|
remote: remote,
|
|
|
|
}
|
2015-09-01 04:05:51 +08:00
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
// Do the move
|
2018-11-02 20:14:02 +08:00
|
|
|
arg := files.RelocationArg{
|
|
|
|
RelocationPath: files.RelocationPath{
|
2020-01-15 01:33:35 +08:00
|
|
|
FromPath: f.opt.Enc.FromStandardPath(srcObj.remotePath()),
|
|
|
|
ToPath: f.opt.Enc.FromStandardPath(dstObj.remotePath()),
|
2018-11-02 20:14:02 +08:00
|
|
|
},
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
var err error
|
2017-09-25 03:01:30 +08:00
|
|
|
var result *files.RelocationResult
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2017-09-25 03:01:30 +08:00
|
|
|
result, err = f.srv.MoveV2(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2015-09-01 04:05:51 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("move failed: %w", err)
|
2015-09-01 04:05:51 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
// Set the metadata
|
2017-09-25 03:01:30 +08:00
|
|
|
fileInfo, ok := result.Metadata.(*files.FileMetadata)
|
2017-05-22 04:35:33 +08:00
|
|
|
if !ok {
|
|
|
|
return nil, fs.ErrorNotAFile
|
|
|
|
}
|
|
|
|
err = dstObj.setMetadataFromEntry(fileInfo)
|
2017-02-25 19:09:57 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("move failed: %w", err)
|
2017-02-25 19:09:57 +08:00
|
|
|
}
|
2015-09-01 04:05:51 +08:00
|
|
|
return dstObj, nil
|
|
|
|
}
|
|
|
|
|
2018-03-29 15:10:19 +08:00
|
|
|
// PublicLink adds a "readable by anyone with link" permission on the given file or folder.
|
2020-06-01 05:18:01 +08:00
|
|
|
func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration, unlink bool) (link string, err error) {
|
2020-01-15 01:33:35 +08:00
|
|
|
absPath := f.opt.Enc.FromStandardPath(path.Join(f.slashRoot, remote))
|
2018-03-29 15:10:19 +08:00
|
|
|
fs.Debugf(f, "attempting to share '%s' (absolute path: %s)", remote, absPath)
|
|
|
|
createArg := sharing.CreateSharedLinkWithSettingsArg{
|
|
|
|
Path: absPath,
|
2021-04-07 00:17:27 +08:00
|
|
|
Settings: &sharing.SharedLinkSettings{
|
|
|
|
RequestedVisibility: &sharing.RequestedVisibility{
|
|
|
|
Tagged: dropbox.Tagged{Tag: sharing.RequestedVisibilityPublic},
|
|
|
|
},
|
|
|
|
Audience: &sharing.LinkAudience{
|
|
|
|
Tagged: dropbox.Tagged{Tag: sharing.LinkAudiencePublic},
|
|
|
|
},
|
|
|
|
Access: &sharing.RequestedLinkAccessLevel{
|
|
|
|
Tagged: dropbox.Tagged{Tag: sharing.RequestedLinkAccessLevelViewer},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if expire < fs.DurationOff {
|
|
|
|
expiryTime := time.Now().Add(time.Duration(expire)).UTC().Round(time.Second)
|
2021-10-16 12:29:52 +08:00
|
|
|
createArg.Settings.Expires = &expiryTime
|
2021-04-07 00:17:27 +08:00
|
|
|
}
|
|
|
|
|
2018-03-29 15:10:19 +08:00
|
|
|
var linkRes sharing.IsSharedLinkMetadata
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2018-05-28 17:50:31 +08:00
|
|
|
linkRes, err = f.sharing.CreateSharedLinkWithSettings(&createArg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2018-03-29 15:10:19 +08:00
|
|
|
})
|
|
|
|
|
2018-11-02 20:14:02 +08:00
|
|
|
if err != nil && strings.Contains(err.Error(),
|
|
|
|
sharing.CreateSharedLinkWithSettingsErrorSharedLinkAlreadyExists) {
|
2018-03-29 15:10:19 +08:00
|
|
|
fs.Debugf(absPath, "has a public link already, attempting to retrieve it")
|
|
|
|
listArg := sharing.ListSharedLinksArg{
|
|
|
|
Path: absPath,
|
|
|
|
DirectOnly: true,
|
|
|
|
}
|
|
|
|
var listRes *sharing.ListSharedLinksResult
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2018-05-28 17:50:31 +08:00
|
|
|
listRes, err = f.sharing.ListSharedLinks(&listArg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2018-03-29 15:10:19 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(listRes.Links) == 0 {
|
2022-06-09 04:54:39 +08:00
|
|
|
err = errors.New("sharing link already exists, but list came back empty")
|
2018-03-29 15:10:19 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
linkRes = listRes.Links[0]
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
switch res := linkRes.(type) {
|
|
|
|
case *sharing.FileLinkMetadata:
|
|
|
|
link = res.Url
|
|
|
|
case *sharing.FolderLinkMetadata:
|
|
|
|
link = res.Url
|
|
|
|
default:
|
2022-06-09 04:54:39 +08:00
|
|
|
err = fmt.Errorf("don't know how to extract link, response has unknown format: %T", res)
|
2018-03-29 15:10:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-02-06 05:20:56 +08:00
|
|
|
// DirMove moves src, srcRemote to this remote at dstRemote
|
2020-10-14 05:43:40 +08:00
|
|
|
// using server-side move operations.
|
2015-09-01 04:05:51 +08:00
|
|
|
//
|
|
|
|
// Will only be called if src.Fs().Name() == f.Name()
|
|
|
|
//
|
|
|
|
// If it isn't possible then return fs.ErrorCantDirMove
|
|
|
|
//
|
|
|
|
// If destination exists then return fs.ErrorDirExists
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string) error {
|
2015-11-07 19:14:46 +08:00
|
|
|
srcFs, ok := src.(*Fs)
|
2015-09-01 04:05:51 +08:00
|
|
|
if !ok {
|
2017-02-09 19:01:20 +08:00
|
|
|
fs.Debugf(srcFs, "Can't move directory - not same remote type")
|
2015-09-01 04:05:51 +08:00
|
|
|
return fs.ErrorCantDirMove
|
|
|
|
}
|
2017-02-06 05:20:56 +08:00
|
|
|
srcPath := path.Join(srcFs.slashRoot, srcRemote)
|
|
|
|
dstPath := path.Join(f.slashRoot, dstRemote)
|
2015-09-01 04:05:51 +08:00
|
|
|
|
|
|
|
// Check if destination exists
|
2021-03-11 22:44:01 +08:00
|
|
|
_, err := f.getDirMetadata(ctx, dstPath)
|
2017-05-22 04:35:33 +08:00
|
|
|
if err == nil {
|
2015-09-01 04:05:51 +08:00
|
|
|
return fs.ErrorDirExists
|
2017-05-22 04:35:33 +08:00
|
|
|
} else if err != fs.ErrorDirNotFound {
|
|
|
|
return err
|
2015-09-01 04:05:51 +08:00
|
|
|
}
|
|
|
|
|
2017-02-06 05:20:56 +08:00
|
|
|
// Make sure the parent directory exists
|
|
|
|
// ...apparently not necessary
|
|
|
|
|
2015-09-01 04:05:51 +08:00
|
|
|
// Do the move
|
2018-11-02 20:14:02 +08:00
|
|
|
arg := files.RelocationArg{
|
|
|
|
RelocationPath: files.RelocationPath{
|
2020-01-15 01:33:35 +08:00
|
|
|
FromPath: f.opt.Enc.FromStandardPath(srcPath),
|
|
|
|
ToPath: f.opt.Enc.FromStandardPath(dstPath),
|
2018-11-02 20:14:02 +08:00
|
|
|
},
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2017-09-25 03:01:30 +08:00
|
|
|
_, err = f.srv.MoveV2(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2015-09-01 04:05:51 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fmt.Errorf("MoveDir failed: %w", err)
|
2015-09-01 04:05:51 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
2015-09-01 04:05:51 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-04-17 05:19:25 +08:00
|
|
|
// About gets quota information
|
2019-06-17 16:34:30 +08:00
|
|
|
func (f *Fs) About(ctx context.Context) (usage *fs.Usage, err error) {
|
2018-04-17 05:19:25 +08:00
|
|
|
var q *users.SpaceUsage
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
|
|
|
q, err = f.users.GetSpaceUsage()
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2018-04-17 05:19:25 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2022-01-15 05:18:32 +08:00
|
|
|
return nil, err
|
2018-04-17 05:19:25 +08:00
|
|
|
}
|
|
|
|
var total uint64
|
2024-02-12 12:10:24 +08:00
|
|
|
used := q.Used
|
2018-04-17 05:19:25 +08:00
|
|
|
if q.Allocation != nil {
|
|
|
|
if q.Allocation.Individual != nil {
|
|
|
|
total += q.Allocation.Individual.Allocated
|
|
|
|
}
|
|
|
|
if q.Allocation.Team != nil {
|
|
|
|
total += q.Allocation.Team.Allocated
|
2023-12-08 19:47:20 +08:00
|
|
|
// Override used with Team.Used as this includes q.Used already
|
|
|
|
used = q.Allocation.Team.Used
|
2018-04-17 05:19:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
usage = &fs.Usage{
|
2023-12-08 19:47:20 +08:00
|
|
|
Total: fs.NewUsageValue(int64(total)), // quota of bytes that can be used
|
|
|
|
Used: fs.NewUsageValue(int64(used)), // bytes in use
|
|
|
|
Free: fs.NewUsageValue(int64(total - used)), // bytes which can be uploaded before reaching the quota
|
2018-04-17 05:19:25 +08:00
|
|
|
}
|
|
|
|
return usage, nil
|
|
|
|
}
|
|
|
|
|
2021-02-24 17:33:31 +08:00
|
|
|
// ChangeNotify calls the passed function with a path that has had changes.
|
|
|
|
// If the implementation uses polling, it should adhere to the given interval.
|
|
|
|
//
|
|
|
|
// Automatically restarts itself in case of unexpected behavior of the remote.
|
|
|
|
//
|
|
|
|
// Close the returned channel to stop being notified.
|
|
|
|
func (f *Fs) ChangeNotify(ctx context.Context, notifyFunc func(string, fs.EntryType), pollIntervalChan <-chan time.Duration) {
|
|
|
|
go func() {
|
|
|
|
// get the StartCursor early so all changes from now on get processed
|
2021-03-11 22:44:01 +08:00
|
|
|
startCursor, err := f.changeNotifyCursor(ctx)
|
2021-02-24 17:33:31 +08:00
|
|
|
if err != nil {
|
|
|
|
fs.Infof(f, "Failed to get StartCursor: %s", err)
|
|
|
|
}
|
|
|
|
var ticker *time.Ticker
|
|
|
|
var tickerC <-chan time.Time
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case pollInterval, ok := <-pollIntervalChan:
|
|
|
|
if !ok {
|
|
|
|
if ticker != nil {
|
|
|
|
ticker.Stop()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if ticker != nil {
|
|
|
|
ticker.Stop()
|
|
|
|
ticker, tickerC = nil, nil
|
|
|
|
}
|
|
|
|
if pollInterval != 0 {
|
|
|
|
ticker = time.NewTicker(pollInterval)
|
|
|
|
tickerC = ticker.C
|
|
|
|
}
|
|
|
|
case <-tickerC:
|
|
|
|
if startCursor == "" {
|
2021-03-11 22:44:01 +08:00
|
|
|
startCursor, err = f.changeNotifyCursor(ctx)
|
2021-02-24 17:33:31 +08:00
|
|
|
if err != nil {
|
|
|
|
fs.Infof(f, "Failed to get StartCursor: %s", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fs.Debugf(f, "Checking for changes on remote")
|
|
|
|
startCursor, err = f.changeNotifyRunner(ctx, notifyFunc, startCursor)
|
|
|
|
if err != nil {
|
|
|
|
fs.Infof(f, "Change notify listener failure: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2021-03-11 22:44:01 +08:00
|
|
|
func (f *Fs) changeNotifyCursor(ctx context.Context) (cursor string, err error) {
|
2021-02-24 17:33:31 +08:00
|
|
|
var startCursor *files.ListFolderGetLatestCursorResult
|
|
|
|
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
2021-03-06 01:44:47 +08:00
|
|
|
arg := files.ListFolderArg{
|
|
|
|
Path: f.opt.Enc.FromStandardPath(f.slashRoot),
|
|
|
|
Recursive: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
if arg.Path == "/" {
|
|
|
|
arg.Path = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
startCursor, err = f.srv.ListFolderGetLatestCursor(&arg)
|
|
|
|
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2021-02-24 17:33:31 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return startCursor.Cursor, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fs) changeNotifyRunner(ctx context.Context, notifyFunc func(string, fs.EntryType), startCursor string) (newCursor string, err error) {
|
|
|
|
cursor := startCursor
|
|
|
|
var res *files.ListFolderLongpollResult
|
|
|
|
|
|
|
|
// Dropbox sets a timeout range of 30 - 480
|
2021-03-01 20:05:36 +08:00
|
|
|
timeout := uint64(f.ci.TimeoutOrInfinite() / time.Second)
|
2021-03-06 01:44:47 +08:00
|
|
|
|
|
|
|
if timeout < 30 {
|
|
|
|
timeout = 30
|
2022-05-31 19:08:01 +08:00
|
|
|
fs.Debugf(f, "Increasing poll interval to minimum 30s")
|
2021-03-06 01:44:47 +08:00
|
|
|
}
|
|
|
|
|
2021-02-24 17:33:31 +08:00
|
|
|
if timeout > 480 {
|
|
|
|
timeout = 480
|
2022-05-31 19:08:01 +08:00
|
|
|
fs.Debugf(f, "Decreasing poll interval to maximum 480s")
|
2021-02-24 17:33:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
|
|
|
args := files.ListFolderLongpollArg{
|
|
|
|
Cursor: cursor,
|
|
|
|
Timeout: timeout,
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err = f.svc.ListFolderLongpoll(&args)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2021-02-24 17:33:31 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !res.Changes {
|
|
|
|
return cursor, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.Backoff != 0 {
|
|
|
|
fs.Debugf(f, "Waiting to poll for %d seconds", res.Backoff)
|
|
|
|
time.Sleep(time.Duration(res.Backoff) * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
var changeList *files.ListFolderResult
|
|
|
|
|
|
|
|
arg := files.ListFolderContinueArg{
|
|
|
|
Cursor: cursor,
|
|
|
|
}
|
|
|
|
err = f.pacer.Call(func() (bool, error) {
|
|
|
|
changeList, err = f.srv.ListFolderContinue(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2021-02-24 17:33:31 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return "", fmt.Errorf("list continue: %w", err)
|
2021-02-24 17:33:31 +08:00
|
|
|
}
|
|
|
|
cursor = changeList.Cursor
|
|
|
|
var entryType fs.EntryType
|
|
|
|
for _, entry := range changeList.Entries {
|
|
|
|
entryPath := ""
|
|
|
|
switch info := entry.(type) {
|
|
|
|
case *files.FolderMetadata:
|
|
|
|
entryType = fs.EntryDirectory
|
2021-04-19 22:38:01 +08:00
|
|
|
entryPath = strings.TrimPrefix(info.PathDisplay, f.slashRootSlash)
|
2021-02-24 17:33:31 +08:00
|
|
|
case *files.FileMetadata:
|
|
|
|
entryType = fs.EntryObject
|
2021-04-19 22:38:01 +08:00
|
|
|
entryPath = strings.TrimPrefix(info.PathDisplay, f.slashRootSlash)
|
2021-02-24 17:33:31 +08:00
|
|
|
case *files.DeletedMetadata:
|
|
|
|
entryType = fs.EntryObject
|
2021-04-19 22:38:01 +08:00
|
|
|
entryPath = strings.TrimPrefix(info.PathDisplay, f.slashRootSlash)
|
2021-02-24 17:33:31 +08:00
|
|
|
default:
|
|
|
|
fs.Errorf(entry, "dropbox ChangeNotify: ignoring unknown EntryType %T", entry)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if entryPath != "" {
|
2022-07-17 19:47:40 +08:00
|
|
|
notifyFunc(f.opt.Enc.ToStandardPath(entryPath), entryType)
|
2021-02-24 17:33:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if !changeList.HasMore {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cursor, nil
|
|
|
|
}
|
|
|
|
|
2016-01-11 20:39:33 +08:00
|
|
|
// Hashes returns the supported hash sets.
|
2018-01-13 00:30:54 +08:00
|
|
|
func (f *Fs) Hashes() hash.Set {
|
2019-09-23 21:32:36 +08:00
|
|
|
return hash.Set(DbHashType)
|
2016-01-11 20:39:33 +08:00
|
|
|
}
|
|
|
|
|
2020-09-07 18:08:46 +08:00
|
|
|
// Shutdown the backend, closing any background tasks and any
|
|
|
|
// cached connections.
|
|
|
|
func (f *Fs) Shutdown(ctx context.Context) error {
|
|
|
|
f.batcher.Shutdown()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-07-09 04:59:30 +08:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// Fs returns the parent Fs
|
2016-02-18 19:35:25 +08:00
|
|
|
func (o *Object) Fs() fs.Info {
|
2015-11-07 19:14:46 +08:00
|
|
|
return o.fs
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a string version
|
2015-11-07 19:14:46 +08:00
|
|
|
func (o *Object) String() string {
|
2014-07-09 04:59:30 +08:00
|
|
|
if o == nil {
|
|
|
|
return "<nil>"
|
|
|
|
}
|
|
|
|
return o.remote
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// Remote returns the remote path
|
2015-11-07 19:14:46 +08:00
|
|
|
func (o *Object) Remote() string {
|
2014-07-09 04:59:30 +08:00
|
|
|
return o.remote
|
|
|
|
}
|
|
|
|
|
2020-08-27 07:12:10 +08:00
|
|
|
// ID returns the object id
|
|
|
|
func (o *Object) ID() string {
|
|
|
|
return o.id
|
|
|
|
}
|
|
|
|
|
2017-05-26 22:09:31 +08:00
|
|
|
// Hash returns the dropbox special hash
|
2019-06-17 16:34:30 +08:00
|
|
|
func (o *Object) Hash(ctx context.Context, t hash.Type) (string, error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
if o.fs.opt.SharedFiles || o.fs.opt.SharedFolders {
|
2020-11-26 19:58:43 +08:00
|
|
|
return "", errNotSupportedInSharedMode
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
2019-09-23 21:32:36 +08:00
|
|
|
if t != DbHashType {
|
2018-01-19 04:27:52 +08:00
|
|
|
return "", hash.ErrUnsupported
|
2017-05-26 22:09:31 +08:00
|
|
|
}
|
2021-03-11 22:44:01 +08:00
|
|
|
err := o.readMetaData(ctx)
|
2017-05-26 22:09:31 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return "", fmt.Errorf("failed to read hash from metadata: %w", err)
|
2017-05-26 22:09:31 +08:00
|
|
|
}
|
|
|
|
return o.hash, nil
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Size returns the size of an object in bytes
|
2015-11-07 19:14:46 +08:00
|
|
|
func (o *Object) Size() int64 {
|
2014-07-09 04:59:30 +08:00
|
|
|
return o.bytes
|
|
|
|
}
|
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
// setMetadataFromEntry sets the fs data from a files.FileMetadata
|
2014-07-10 07:17:40 +08:00
|
|
|
//
|
Spelling fixes
Fix spelling of: above, already, anonymous, associated,
authentication, bandwidth, because, between, blocks, calculate,
candidates, cautious, changelog, cleaner, clipboard, command,
completely, concurrently, considered, constructs, corrupt, current,
daemon, dependencies, deprecated, directory, dispatcher, download,
eligible, ellipsis, encrypter, endpoint, entrieslist, essentially,
existing writers, existing, expires, filesystem, flushing, frequently,
hierarchy, however, implementation, implements, inaccurate,
individually, insensitive, longer, maximum, metadata, modified,
multipart, namedirfirst, nextcloud, obscured, opened, optional,
owncloud, pacific, passphrase, password, permanently, persimmon,
positive, potato, protocol, quota, receiving, recommends, referring,
requires, revisited, satisfied, satisfies, satisfy, semver,
serialized, session, storage, strategies, stringlist, successful,
supported, surprise, temporarily, temporary, transactions, unneeded,
update, uploads, wrapped
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-10-09 08:17:24 +08:00
|
|
|
// This isn't a complete set of metadata and has an inaccurate date
|
2017-05-22 04:35:33 +08:00
|
|
|
func (o *Object) setMetadataFromEntry(info *files.FileMetadata) error {
|
2020-08-23 22:10:30 +08:00
|
|
|
o.id = info.Id
|
2017-05-22 04:35:33 +08:00
|
|
|
o.bytes = int64(info.Size)
|
|
|
|
o.modTime = info.ClientModified
|
2017-05-26 22:09:31 +08:00
|
|
|
o.hash = info.ContentHash
|
2017-02-25 19:09:57 +08:00
|
|
|
return nil
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
// Reads the entry for a file from dropbox
|
2021-03-11 22:44:01 +08:00
|
|
|
func (o *Object) readEntry(ctx context.Context) (*files.FileMetadata, error) {
|
|
|
|
return o.fs.getFileMetadata(ctx, o.remotePath())
|
2014-07-10 07:17:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read entry if not set and set metadata from it
|
2021-03-11 22:44:01 +08:00
|
|
|
func (o *Object) readEntryAndSetMetadata(ctx context.Context) error {
|
2014-07-10 07:17:40 +08:00
|
|
|
// Last resort set time from client
|
|
|
|
if !o.modTime.IsZero() {
|
|
|
|
return nil
|
|
|
|
}
|
2021-03-11 22:44:01 +08:00
|
|
|
entry, err := o.readEntry(ctx)
|
2014-07-10 07:17:40 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-25 19:09:57 +08:00
|
|
|
return o.setMetadataFromEntry(entry)
|
2014-07-10 07:17:40 +08:00
|
|
|
}
|
|
|
|
|
2014-07-09 04:59:30 +08:00
|
|
|
// Returns the remote path for the object
|
2015-11-07 19:14:46 +08:00
|
|
|
func (o *Object) remotePath() string {
|
|
|
|
return o.fs.slashRootSlash + o.remote
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// readMetaData gets the info if it hasn't already been fetched
|
2021-03-11 22:44:01 +08:00
|
|
|
func (o *Object) readMetaData(ctx context.Context) (err error) {
|
2017-05-26 22:09:31 +08:00
|
|
|
if !o.modTime.IsZero() {
|
2014-07-09 04:59:30 +08:00
|
|
|
return nil
|
|
|
|
}
|
2014-07-10 07:17:40 +08:00
|
|
|
// Last resort
|
2021-03-11 22:44:01 +08:00
|
|
|
return o.readEntryAndSetMetadata(ctx)
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ModTime returns the modification time of the object
|
|
|
|
//
|
|
|
|
// It attempts to read the objects mtime and if that isn't present the
|
|
|
|
// LastModified returned in the http headers
|
2019-06-17 16:34:30 +08:00
|
|
|
func (o *Object) ModTime(ctx context.Context) time.Time {
|
2021-03-11 22:44:01 +08:00
|
|
|
err := o.readMetaData(ctx)
|
2014-07-09 04:59:30 +08:00
|
|
|
if err != nil {
|
2017-02-10 01:08:51 +08:00
|
|
|
fs.Debugf(o, "Failed to read metadata: %v", err)
|
2014-07-09 04:59:30 +08:00
|
|
|
return time.Now()
|
|
|
|
}
|
|
|
|
return o.modTime
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// SetModTime sets the modification time of the local fs object
|
2014-07-10 07:17:40 +08:00
|
|
|
//
|
|
|
|
// Commits the datastore
|
2019-06-17 16:34:30 +08:00
|
|
|
func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error {
|
2017-05-22 04:35:33 +08:00
|
|
|
// Dropbox doesn't have a way of doing this so returning this
|
2017-06-13 20:58:39 +08:00
|
|
|
// error will cause the file to be deleted first then
|
|
|
|
// re-uploaded to set the time.
|
2018-04-06 22:34:56 +08:00
|
|
|
return fs.ErrorCantSetModTimeWithoutDelete
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2015-09-23 01:47:16 +08:00
|
|
|
// Storable returns whether this object is storable
|
2015-11-07 19:14:46 +08:00
|
|
|
func (o *Object) Storable() bool {
|
2014-07-09 04:59:30 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open an object for read
|
2019-06-17 16:34:30 +08:00
|
|
|
func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
if o.fs.opt.SharedFiles {
|
|
|
|
if len(options) != 0 {
|
|
|
|
return nil, errors.New("OpenOptions not supported for shared files")
|
|
|
|
}
|
|
|
|
arg := sharing.GetSharedLinkMetadataArg{
|
|
|
|
Url: o.url,
|
|
|
|
}
|
|
|
|
err = o.fs.pacer.Call(func() (bool, error) {
|
|
|
|
_, in, err = o.fs.sharing.GetSharedLinkFile(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2020-08-23 22:10:30 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-06 22:18:08 +08:00
|
|
|
fs.FixRangeOption(options, o.bytes)
|
2017-05-22 04:35:33 +08:00
|
|
|
headers := fs.OpenOptionHeaders(options)
|
2018-11-02 20:14:02 +08:00
|
|
|
arg := files.DownloadArg{
|
2020-08-23 22:10:30 +08:00
|
|
|
Path: o.id,
|
2018-11-02 20:14:02 +08:00
|
|
|
ExtraHeaders: headers,
|
|
|
|
}
|
2017-05-29 00:55:18 +08:00
|
|
|
err = o.fs.pacer.Call(func() (bool, error) {
|
|
|
|
_, in, err = o.fs.srv.Download(&arg)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
switch e := err.(type) {
|
|
|
|
case files.DownloadAPIError:
|
|
|
|
// Don't attempt to retry copyright violation errors
|
2019-10-10 23:34:09 +08:00
|
|
|
if e.EndpointError != nil && e.EndpointError.Path != nil && e.EndpointError.Path.Tag == files.LookupErrorRestrictedContent {
|
2018-01-13 00:30:54 +08:00
|
|
|
return nil, fserrors.NoRetryError(err)
|
2016-09-10 18:29:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 04:35:33 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// uploadChunked uploads the object in parts
|
|
|
|
//
|
2021-03-31 13:10:29 +08:00
|
|
|
// Will introduce two additional network requests to start and finish the session.
|
|
|
|
// If the size is unknown (i.e. -1) the method incurs one additional
|
|
|
|
// request to the Dropbox API that does not carry a payload to close the append session.
|
2021-03-11 22:44:01 +08:00
|
|
|
func (o *Object) uploadChunked(ctx context.Context, in0 io.Reader, commitInfo *files.CommitInfo, size int64) (entry *files.FileMetadata, err error) {
|
2021-03-31 13:10:29 +08:00
|
|
|
// start upload
|
2017-05-29 00:55:18 +08:00
|
|
|
var res *files.UploadSessionStartResult
|
2017-11-08 17:18:16 +08:00
|
|
|
err = o.fs.pacer.Call(func() (bool, error) {
|
2021-03-31 13:10:29 +08:00
|
|
|
res, err = o.fs.srv.UploadSessionStart(&files.UploadSessionStartArg{}, nil)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-31 13:10:29 +08:00
|
|
|
chunkSize := int64(o.fs.opt.ChunkSize)
|
|
|
|
chunks, remainder := size/chunkSize, size%chunkSize
|
|
|
|
if remainder > 0 {
|
|
|
|
chunks++
|
|
|
|
}
|
|
|
|
|
|
|
|
// write chunks
|
|
|
|
in := readers.NewCountingReader(in0)
|
|
|
|
buf := make([]byte, int(chunkSize))
|
2017-05-22 04:35:33 +08:00
|
|
|
cursor := files.UploadSessionCursor{
|
|
|
|
SessionId: res.SessionId,
|
2017-08-04 03:42:35 +08:00
|
|
|
Offset: 0,
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
2021-03-31 13:10:29 +08:00
|
|
|
appendArg := files.UploadSessionAppendArg{Cursor: &cursor}
|
|
|
|
for currentChunk := 1; ; currentChunk++ {
|
|
|
|
cursor.Offset = in.BytesRead()
|
2017-05-22 04:35:33 +08:00
|
|
|
|
2021-03-31 13:10:29 +08:00
|
|
|
if chunks < 0 {
|
|
|
|
fs.Debugf(o, "Streaming chunk %d/unknown", currentChunk)
|
2020-09-07 18:08:46 +08:00
|
|
|
} else {
|
2021-03-31 13:10:29 +08:00
|
|
|
fs.Debugf(o, "Uploading chunk %d/%d", currentChunk, chunks)
|
2017-08-04 03:42:35 +08:00
|
|
|
}
|
2021-03-31 13:10:29 +08:00
|
|
|
|
|
|
|
chunk := readers.NewRepeatableLimitReaderBuffer(in, buf, chunkSize)
|
2022-03-21 19:34:42 +08:00
|
|
|
skip := int64(0)
|
2017-11-08 17:18:16 +08:00
|
|
|
err = o.fs.pacer.Call(func() (bool, error) {
|
|
|
|
// seek to the start in case this is a retry
|
2022-03-21 19:34:42 +08:00
|
|
|
if _, err = chunk.Seek(skip, io.SeekStart); err != nil {
|
|
|
|
return false, err
|
2017-11-08 17:18:16 +08:00
|
|
|
}
|
|
|
|
err = o.fs.srv.UploadSessionAppendV2(&appendArg, chunk)
|
2021-03-31 13:10:29 +08:00
|
|
|
// after session is started, we retry everything
|
2022-03-21 19:34:42 +08:00
|
|
|
if err != nil {
|
|
|
|
// Check for incorrect offset error and retry with new offset
|
|
|
|
if uErr, ok := err.(files.UploadSessionAppendV2APIError); ok {
|
|
|
|
if uErr.EndpointError != nil && uErr.EndpointError.IncorrectOffset != nil {
|
|
|
|
correctOffset := uErr.EndpointError.IncorrectOffset.CorrectOffset
|
|
|
|
delta := int64(correctOffset) - int64(cursor.Offset)
|
|
|
|
skip += delta
|
2022-08-14 10:56:32 +08:00
|
|
|
what := fmt.Sprintf("incorrect offset error received: sent %d, need %d, skip %d", cursor.Offset, correctOffset, skip)
|
2022-03-21 19:34:42 +08:00
|
|
|
if skip < 0 {
|
|
|
|
return false, fmt.Errorf("can't seek backwards to correct offset: %s", what)
|
|
|
|
} else if skip == chunkSize {
|
|
|
|
fs.Debugf(o, "%s: chunk received OK - continuing", what)
|
|
|
|
return false, nil
|
|
|
|
} else if skip > chunkSize {
|
|
|
|
// This error should never happen
|
|
|
|
return false, fmt.Errorf("can't seek forwards by more than a chunk to correct offset: %s", what)
|
|
|
|
}
|
|
|
|
// Skip the sent data on next retry
|
|
|
|
cursor.Offset = uint64(int64(cursor.Offset) + delta)
|
|
|
|
fs.Debugf(o, "%s: skipping bytes on retry to fix offset", what)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 18:03:44 +08:00
|
|
|
return err != nil, err
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-07-04 20:45:10 +08:00
|
|
|
}
|
2021-03-31 13:10:29 +08:00
|
|
|
if appendArg.Close {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if size > 0 {
|
|
|
|
// if size is known, check if next chunk is final
|
|
|
|
appendArg.Close = uint64(size)-in.BytesRead() <= uint64(chunkSize)
|
2022-07-30 00:40:05 +08:00
|
|
|
if in.BytesRead() > uint64(size) {
|
|
|
|
return nil, fmt.Errorf("expected %d bytes in input, but have read %d so far", size, in.BytesRead())
|
|
|
|
}
|
2021-03-31 13:10:29 +08:00
|
|
|
} else {
|
|
|
|
// if size is unknown, upload as long as we can read full chunks from the reader
|
|
|
|
appendArg.Close = in.BytesRead()-cursor.Offset < uint64(chunkSize)
|
|
|
|
}
|
2016-07-04 20:45:10 +08:00
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
2021-03-31 13:10:29 +08:00
|
|
|
// finish upload
|
2017-08-19 20:07:23 +08:00
|
|
|
cursor.Offset = in.BytesRead()
|
2017-05-22 04:35:33 +08:00
|
|
|
args := &files.UploadSessionFinishArg{
|
|
|
|
Cursor: &cursor,
|
|
|
|
Commit: commitInfo,
|
|
|
|
}
|
2020-09-07 18:08:46 +08:00
|
|
|
// If we are batching then we should have written all the data now
|
|
|
|
// store the commit info now for a batch commit
|
2021-03-31 13:10:29 +08:00
|
|
|
if o.fs.batcher.Batching() {
|
2023-09-12 23:10:45 +08:00
|
|
|
return o.fs.batcher.Commit(ctx, o.remote, args)
|
2020-09-07 18:08:46 +08:00
|
|
|
}
|
|
|
|
|
2017-11-08 17:18:16 +08:00
|
|
|
err = o.fs.pacer.Call(func() (bool, error) {
|
2021-03-31 13:10:29 +08:00
|
|
|
entry, err = o.fs.srv.UploadSessionFinish(args, nil)
|
2020-01-08 20:57:21 +08:00
|
|
|
// If error is insufficient space then don't retry
|
|
|
|
if e, ok := err.(files.UploadSessionFinishAPIError); ok {
|
|
|
|
if e.EndpointError != nil && e.EndpointError.Path != nil && e.EndpointError.Path.Tag == files.WriteErrorInsufficientSpace {
|
|
|
|
err = fserrors.NoRetryError(err)
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 18:03:44 +08:00
|
|
|
// after the first chunk is uploaded, we retry everything
|
|
|
|
return err != nil, err
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return entry, nil
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2020-11-27 19:49:37 +08:00
|
|
|
// checks all the parts of name to see they are below
|
|
|
|
// maxFileNameLength runes.
|
|
|
|
//
|
|
|
|
// This checks the length as runes which isn't quite right as dropbox
|
|
|
|
// seems to encode some symbols (eg ☺) as two "characters". This seems
|
|
|
|
// like utf-16 except that ☺ doesn't need two characters in utf-16.
|
|
|
|
//
|
|
|
|
// Using runes instead of what dropbox is using will work for most
|
|
|
|
// cases, and when it goes wrong we will upload something we should
|
|
|
|
// have detected as too long which is the least damaging way to fail.
|
|
|
|
func checkPathLength(name string) (err error) {
|
|
|
|
for next := ""; len(name) > 0; name = next {
|
|
|
|
if slash := strings.IndexRune(name, '/'); slash >= 0 {
|
|
|
|
name, next = name[:slash], name[slash+1:]
|
|
|
|
} else {
|
|
|
|
next = ""
|
|
|
|
}
|
|
|
|
length := utf8.RuneCountInString(name)
|
|
|
|
if length > maxFileNameLength {
|
|
|
|
return fserrors.NoRetryError(fs.ErrorFileNameTooLong)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-07-09 04:59:30 +08:00
|
|
|
// Update the already existing object
|
|
|
|
//
|
2022-08-05 23:35:41 +08:00
|
|
|
// Copy the reader into the object updating modTime and size.
|
2014-07-09 04:59:30 +08:00
|
|
|
//
|
|
|
|
// The new object may have been created if an error is returned
|
2019-06-17 16:34:30 +08:00
|
|
|
func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error {
|
2020-08-23 22:10:30 +08:00
|
|
|
if o.fs.opt.SharedFiles || o.fs.opt.SharedFolders {
|
2020-11-26 19:58:43 +08:00
|
|
|
return errNotSupportedInSharedMode
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
2015-08-21 01:36:06 +08:00
|
|
|
remote := o.remotePath()
|
|
|
|
if ignoredFiles.MatchString(remote) {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fserrors.NoRetryError(fmt.Errorf("file name %q is disallowed - not uploading", path.Base(remote)))
|
2015-08-21 01:36:06 +08:00
|
|
|
}
|
2020-01-15 01:33:35 +08:00
|
|
|
commitInfo := files.NewCommitInfo(o.fs.opt.Enc.FromStandardPath(o.remotePath()))
|
2017-05-22 04:35:33 +08:00
|
|
|
commitInfo.Mode.Tag = "overwrite"
|
|
|
|
// The Dropbox API only accepts timestamps in UTC with second precision.
|
2021-10-16 12:29:52 +08:00
|
|
|
clientModified := src.ModTime(ctx).UTC().Round(time.Second)
|
|
|
|
commitInfo.ClientModified = &clientModified
|
2020-11-27 19:49:37 +08:00
|
|
|
// Don't attempt to create filenames that are too long
|
|
|
|
if cErr := checkPathLength(commitInfo.Path); cErr != nil {
|
|
|
|
return cErr
|
|
|
|
}
|
2017-05-22 04:35:33 +08:00
|
|
|
|
|
|
|
size := src.Size()
|
|
|
|
var err error
|
|
|
|
var entry *files.FileMetadata
|
2020-09-07 18:08:46 +08:00
|
|
|
if size > int64(o.fs.opt.ChunkSize) || size < 0 || o.fs.batcher.Batching() {
|
2021-03-11 22:44:01 +08:00
|
|
|
entry, err = o.uploadChunked(ctx, in, commitInfo, size)
|
2017-05-22 04:35:33 +08:00
|
|
|
} else {
|
2017-05-29 00:55:18 +08:00
|
|
|
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
2022-04-01 17:26:47 +08:00
|
|
|
entry, err = o.fs.srv.Upload(&files.UploadArg{CommitInfo: *commitInfo}, in)
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2017-05-22 04:35:33 +08:00
|
|
|
}
|
2014-07-09 04:59:30 +08:00
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return fmt.Errorf("upload failed: %w", err)
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
2020-09-07 18:08:46 +08:00
|
|
|
// If we haven't received data back from batch upload then fake it
|
|
|
|
//
|
|
|
|
// This will only happen if we are uploading async batches
|
|
|
|
if entry == nil {
|
|
|
|
o.bytes = size
|
2021-10-16 12:29:52 +08:00
|
|
|
o.modTime = *commitInfo.ClientModified
|
2020-09-07 18:08:46 +08:00
|
|
|
o.hash = "" // we don't have this
|
|
|
|
return nil
|
|
|
|
}
|
2017-02-25 19:09:57 +08:00
|
|
|
return o.setMetadataFromEntry(entry)
|
2014-07-09 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove an object
|
2019-06-17 16:34:30 +08:00
|
|
|
func (o *Object) Remove(ctx context.Context) (err error) {
|
2020-08-23 22:10:30 +08:00
|
|
|
if o.fs.opt.SharedFiles || o.fs.opt.SharedFolders {
|
2020-11-26 19:58:43 +08:00
|
|
|
return errNotSupportedInSharedMode
|
2020-08-23 22:10:30 +08:00
|
|
|
}
|
2017-11-08 17:18:16 +08:00
|
|
|
err = o.fs.pacer.Call(func() (bool, error) {
|
2018-11-02 20:14:02 +08:00
|
|
|
_, err = o.fs.srv.DeleteV2(&files.DeleteArg{
|
2020-01-15 01:33:35 +08:00
|
|
|
Path: o.fs.opt.Enc.FromStandardPath(o.remotePath()),
|
2018-11-02 20:14:02 +08:00
|
|
|
})
|
2021-03-11 22:44:01 +08:00
|
|
|
return shouldRetry(ctx, err)
|
2017-05-29 00:55:18 +08:00
|
|
|
})
|
2014-07-09 04:59:30 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the interfaces are satisfied
|
2015-09-01 04:05:51 +08:00
|
|
|
var (
|
2018-03-29 15:10:19 +08:00
|
|
|
_ fs.Fs = (*Fs)(nil)
|
|
|
|
_ fs.Copier = (*Fs)(nil)
|
|
|
|
_ fs.Purger = (*Fs)(nil)
|
|
|
|
_ fs.PutStreamer = (*Fs)(nil)
|
|
|
|
_ fs.Mover = (*Fs)(nil)
|
|
|
|
_ fs.PublicLinker = (*Fs)(nil)
|
|
|
|
_ fs.DirMover = (*Fs)(nil)
|
2018-04-17 05:19:25 +08:00
|
|
|
_ fs.Abouter = (*Fs)(nil)
|
2020-09-07 18:08:46 +08:00
|
|
|
_ fs.Shutdowner = &Fs{}
|
2018-03-29 15:10:19 +08:00
|
|
|
_ fs.Object = (*Object)(nil)
|
2020-08-27 07:12:10 +08:00
|
|
|
_ fs.IDer = (*Object)(nil)
|
2015-09-01 04:05:51 +08:00
|
|
|
)
|