Compare commits
149
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40b9e312c6 | ||
|
|
2b268f9724 | ||
|
|
7a5a74cecb | ||
|
|
54a0c6b8ad | ||
|
|
1ad23c4dc8 | ||
|
|
7586a345ff | ||
|
|
393b94bb70 | ||
|
|
e3c11c9ca1 | ||
|
|
3c91abce74 | ||
|
|
87d856d71b | ||
|
|
3855c003ce | ||
|
|
abb9f89f65 | ||
|
|
17b4058ee9 | ||
|
|
9663f9b2ab | ||
|
|
d6e10dba33 | ||
|
|
da5cbc194a | ||
|
|
e8eb658ba5 | ||
|
|
28f69f25a0 | ||
|
|
07e4b9bb7f | ||
|
|
708b967f15 | ||
|
|
7e2568a312 | ||
|
|
bde0334bd8 | ||
|
|
5470d34740 | ||
|
|
ac9cb50fdb | ||
|
|
4a8b548add | ||
|
|
481c8a40ea | ||
|
|
25ef3a281b | ||
|
|
219bd97e8a | ||
|
|
8b14cd24aa | ||
|
|
3893c14889 | ||
|
|
c41fbc0f90 | ||
|
|
f45425e5a9 | ||
|
|
bd9fd629bc | ||
|
|
3b19f48929 | ||
|
|
4996edc030 | ||
|
|
964f1f6a7e | ||
|
|
e75c1f70bb | ||
|
|
19a4d74ee7 | ||
|
|
55b5eded23 | ||
|
|
3dbcf0af2d | ||
|
|
4e1a511f88 | ||
|
|
b71e1a16b1 | ||
|
|
ec1271818f | ||
|
|
8318020387 | ||
|
|
c38d7be373 | ||
|
|
dc31212c3d | ||
|
|
ac60b36e77 | ||
|
|
1d73f071f6 | ||
|
|
5c869d5bd3 | ||
|
|
a54210a2e4 | ||
|
|
040d226028 | ||
|
|
8b664c3ec5 | ||
|
|
102a38bb95 | ||
|
|
7a54e13110 | ||
|
|
feee92c790 | ||
|
|
de93852512 | ||
|
|
dfb710eab7 | ||
|
|
25cfeb2a64 | ||
|
|
90377f5e65 | ||
|
|
f1d9bd5eab | ||
|
|
4ee3c21a9d | ||
|
|
fe6f4135b4 | ||
|
|
3dfa63b85c | ||
|
|
ff2343475a | ||
|
|
bffd7f0f14 | ||
|
|
7c55fafe33 | ||
|
|
2e7fe06beb | ||
|
|
8ff91ff31b | ||
|
|
4d1c616e97 | ||
|
|
43daecd89b | ||
|
|
9f99c20232 | ||
|
|
97ed8db75d | ||
|
|
f80d98553a | ||
|
|
b3e7a9d01c | ||
|
|
01fc063128 | ||
|
|
e71edd5577 | ||
|
|
27a34dd183 | ||
|
|
7662f15939 | ||
|
|
bfd9f32188 | ||
|
|
9c9cdf1712 | ||
|
|
0e5537cd25 | ||
|
|
151d0a274e | ||
|
|
dc77ec4ba1 | ||
|
|
0d7573dd81 | ||
|
|
e4d2d228bd | ||
|
|
ede36b001b | ||
|
|
3afb2a4798 | ||
|
|
62dbdcdbcc | ||
|
|
06df133159 | ||
|
|
0ab2693da6 | ||
|
|
4b1cb1be43 | ||
|
|
9d96680329 | ||
|
|
d694bb30e5 | ||
|
|
9c858c3228 | ||
|
|
7125cb10f5 | ||
|
|
ba421fd069 | ||
|
|
77e55b8265 | ||
|
|
18d26e2ddb | ||
|
|
f338a2d907 | ||
|
|
77fa8194f2 | ||
|
|
ccaca04a5d | ||
|
|
84191ac6dc | ||
|
|
7cf8ea354c | ||
|
|
24ef00a258 | ||
|
|
00d30ce0d7 | ||
|
|
db39adeb3e | ||
|
|
ef7ac088c0 | ||
|
|
08a3957880 | ||
|
|
4499b08afc | ||
|
|
422ad38e5b | ||
|
|
0b7f959433 | ||
|
|
4b9da601be | ||
|
|
c789436580 | ||
|
|
277d94feac | ||
|
|
6757244918 | ||
|
|
36157d8ae5 | ||
|
|
251cfc100e | ||
|
|
9fb10064ee | ||
|
|
bedeaf23af | ||
|
|
14e93bfd8a | ||
|
|
65071599a2 | ||
|
|
5403e1c79a | ||
|
|
5697caf20b | ||
|
|
68056f08ab | ||
|
|
81002747c5 | ||
|
|
1bd9f522e0 | ||
|
|
3a1b41ac22 | ||
|
|
375d25f158 | ||
|
|
0e57335396 | ||
|
|
bafe7d5a73 | ||
|
|
c555dc71c2 | ||
|
|
3c620d521d | ||
|
|
0a5c83ece1 | ||
|
|
1ba5e99152 | ||
|
|
95c83b37fb | ||
|
|
89634795b0 | ||
|
|
b88dec51e5 | ||
|
|
f2a789ea98 | ||
|
|
63128834da | ||
|
|
5f822f2660 | ||
|
|
b81601baff | ||
|
|
58064bdd2b | ||
|
|
ba01d5e8ab | ||
|
|
e510d460c2 | ||
|
|
42de601fa6 | ||
|
|
3801b8109e | ||
|
|
e0d41da3e3 | ||
|
|
92662baceb | ||
|
|
87c844bce1 |
No files matched your search
+13
-13
@@ -19,12 +19,12 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
job_name: ['linux', 'mac', 'windows_amd64', 'windows_386', 'other_os', 'modules_race', 'go1.10', 'go1.11', 'go1.12']
|
job_name: ['linux', 'mac', 'windows_amd64', 'windows_386', 'other_os', 'modules_race', 'go1.11', 'go1.12', 'go1.13']
|
||||||
|
|
||||||
include:
|
include:
|
||||||
- job_name: linux
|
- job_name: linux
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
go: '1.13.x'
|
go: '1.14.x'
|
||||||
modules: 'off'
|
modules: 'off'
|
||||||
gotags: cmount
|
gotags: cmount
|
||||||
build_flags: '-include "^linux/"'
|
build_flags: '-include "^linux/"'
|
||||||
@@ -34,7 +34,7 @@ jobs:
|
|||||||
|
|
||||||
- job_name: mac
|
- job_name: mac
|
||||||
os: macOS-latest
|
os: macOS-latest
|
||||||
go: '1.13.x'
|
go: '1.14.x'
|
||||||
modules: 'off'
|
modules: 'off'
|
||||||
gotags: '' # cmount doesn't work on osx travis for some reason
|
gotags: '' # cmount doesn't work on osx travis for some reason
|
||||||
build_flags: '-include "^darwin/amd64" -cgo'
|
build_flags: '-include "^darwin/amd64" -cgo'
|
||||||
@@ -44,7 +44,7 @@ jobs:
|
|||||||
|
|
||||||
- job_name: windows_amd64
|
- job_name: windows_amd64
|
||||||
os: windows-latest
|
os: windows-latest
|
||||||
go: '1.13.x'
|
go: '1.14.x'
|
||||||
modules: 'off'
|
modules: 'off'
|
||||||
gotags: cmount
|
gotags: cmount
|
||||||
build_flags: '-include "^windows/amd64" -cgo'
|
build_flags: '-include "^windows/amd64" -cgo'
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
|
|
||||||
- job_name: windows_386
|
- job_name: windows_386
|
||||||
os: windows-latest
|
os: windows-latest
|
||||||
go: '1.13.x'
|
go: '1.14.x'
|
||||||
modules: 'off'
|
modules: 'off'
|
||||||
gotags: cmount
|
gotags: cmount
|
||||||
goarch: '386'
|
goarch: '386'
|
||||||
@@ -65,7 +65,7 @@ jobs:
|
|||||||
|
|
||||||
- job_name: other_os
|
- job_name: other_os
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
go: '1.13.x'
|
go: '1.14.x'
|
||||||
modules: 'off'
|
modules: 'off'
|
||||||
build_flags: '-exclude "^(windows/|darwin/amd64|linux/)"'
|
build_flags: '-exclude "^(windows/|darwin/amd64|linux/)"'
|
||||||
compile_all: true
|
compile_all: true
|
||||||
@@ -73,17 +73,11 @@ jobs:
|
|||||||
|
|
||||||
- job_name: modules_race
|
- job_name: modules_race
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
go: '1.13.x'
|
go: '1.14.x'
|
||||||
modules: 'on'
|
modules: 'on'
|
||||||
quicktest: true
|
quicktest: true
|
||||||
racequicktest: true
|
racequicktest: true
|
||||||
|
|
||||||
- job_name: go1.10
|
|
||||||
os: ubuntu-latest
|
|
||||||
go: '1.10.x'
|
|
||||||
modules: 'off'
|
|
||||||
quicktest: true
|
|
||||||
|
|
||||||
- job_name: go1.11
|
- job_name: go1.11
|
||||||
os: ubuntu-latest
|
os: ubuntu-latest
|
||||||
go: '1.11.x'
|
go: '1.11.x'
|
||||||
@@ -96,6 +90,12 @@ jobs:
|
|||||||
modules: 'off'
|
modules: 'off'
|
||||||
quicktest: true
|
quicktest: true
|
||||||
|
|
||||||
|
- job_name: go1.13
|
||||||
|
os: ubuntu-latest
|
||||||
|
go: '1.13.x'
|
||||||
|
modules: 'off'
|
||||||
|
quicktest: true
|
||||||
|
|
||||||
name: ${{ matrix.job_name }}
|
name: ${{ matrix.job_name }}
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|||||||
+2
-1
@@ -7,4 +7,5 @@ rclone.iml
|
|||||||
.idea
|
.idea
|
||||||
.history
|
.history
|
||||||
*.test
|
*.test
|
||||||
*.log
|
*.log
|
||||||
|
*.iml
|
||||||
+7
-4
@@ -148,6 +148,7 @@ with modules beneath.
|
|||||||
* ...commands
|
* ...commands
|
||||||
* docs - the documentation and website
|
* docs - the documentation and website
|
||||||
* content - adjust these docs only - everything else is autogenerated
|
* content - adjust these docs only - everything else is autogenerated
|
||||||
|
* command - these are auto generated - edit the corresponding .go file
|
||||||
* fs - main rclone definitions - minimal amount of code
|
* fs - main rclone definitions - minimal amount of code
|
||||||
* accounting - bandwidth limiting and statistics
|
* accounting - bandwidth limiting and statistics
|
||||||
* asyncreader - an io.Reader which reads ahead
|
* asyncreader - an io.Reader which reads ahead
|
||||||
@@ -203,6 +204,9 @@ don't need to run these when adding a feature.
|
|||||||
Documentation for rclone sub commands is with their code, eg
|
Documentation for rclone sub commands is with their code, eg
|
||||||
`cmd/ls/ls.go`.
|
`cmd/ls/ls.go`.
|
||||||
|
|
||||||
|
Note that you can use [GitHub's online editor](https://help.github.com/en/github/managing-files-in-a-repository/editing-files-in-another-users-repository)
|
||||||
|
for small changes in the docs which makes it very easy.
|
||||||
|
|
||||||
## Making a release ##
|
## Making a release ##
|
||||||
|
|
||||||
There are separate instructions for making a release in the RELEASE.md
|
There are separate instructions for making a release in the RELEASE.md
|
||||||
@@ -337,10 +341,9 @@ Getting going
|
|||||||
* Add your remote to the imports in `backend/all/all.go`
|
* Add your remote to the imports in `backend/all/all.go`
|
||||||
* HTTP based remotes are easiest to maintain if they use rclone's rest module, but if there is a really good go SDK then use that instead.
|
* HTTP based remotes are easiest to maintain if they use rclone's rest module, but if there is a really good go SDK then use that instead.
|
||||||
* Try to implement as many optional methods as possible as it makes the remote more usable.
|
* Try to implement as many optional methods as possible as it makes the remote more usable.
|
||||||
* Use fs/encoder to make sure we can encode any path name and `rclone info` to help determine the encodings needed
|
* Use lib/encoder to make sure we can encode any path name and `rclone info` to help determine the encodings needed
|
||||||
* `go install -tags noencode`
|
|
||||||
* `rclone purge -v TestRemote:rclone-info`
|
* `rclone purge -v TestRemote:rclone-info`
|
||||||
* `rclone info -vv --write-json remote.json TestRemote:rclone-info`
|
* `rclone info --remote-encoding None -vv --write-json remote.json TestRemote:rclone-info`
|
||||||
* `go run cmd/info/internal/build_csv/main.go -o remote.csv remote.json`
|
* `go run cmd/info/internal/build_csv/main.go -o remote.csv remote.json`
|
||||||
* open `remote.csv` in a spreadsheet and examine
|
* open `remote.csv` in a spreadsheet and examine
|
||||||
|
|
||||||
@@ -355,7 +358,7 @@ Integration tests
|
|||||||
* Add your backend to `fstest/test_all/config.yaml`
|
* Add your backend to `fstest/test_all/config.yaml`
|
||||||
* Once you've done that then you can use the integration test framework from the project root:
|
* Once you've done that then you can use the integration test framework from the project root:
|
||||||
* go install ./...
|
* go install ./...
|
||||||
* test_all -backend remote
|
* test_all -backends remote
|
||||||
|
|
||||||
Or if you want to run the integration tests manually:
|
Or if you want to run the integration tests manually:
|
||||||
|
|
||||||
|
|||||||
Generated
+8993
-6795
File diff suppressed because it is too large.
Load diff
Generated
+8613
-6262
File diff suppressed because it is too large.
Load diff
@@ -183,6 +183,9 @@ endif
|
|||||||
@echo Beta release ready at $(BETA_URL)
|
@echo Beta release ready at $(BETA_URL)
|
||||||
|
|
||||||
circleci_upload:
|
circleci_upload:
|
||||||
|
sudo chown -R $$USER build
|
||||||
|
find build -type l -delete
|
||||||
|
gzip -r9v build
|
||||||
./rclone --config bin/travis.rclone.conf -v copy build/ $(BETA_UPLOAD)/testbuilds
|
./rclone --config bin/travis.rclone.conf -v copy build/ $(BETA_UPLOAD)/testbuilds
|
||||||
ifndef BRANCH_PATH
|
ifndef BRANCH_PATH
|
||||||
./rclone --config bin/travis.rclone.conf -v copy build/ $(BETA_UPLOAD_ROOT)/test/testbuilds-latest
|
./rclone --config bin/travis.rclone.conf -v copy build/ $(BETA_UPLOAD_ROOT)/test/testbuilds-latest
|
||||||
|
|||||||
@@ -8,10 +8,7 @@
|
|||||||
[Installation](https://rclone.org/install/) |
|
[Installation](https://rclone.org/install/) |
|
||||||
[Forum](https://forum.rclone.org/)
|
[Forum](https://forum.rclone.org/)
|
||||||
|
|
||||||
[](https://travis-ci.org/rclone/rclone)
|
[](https://github.com/rclone/rclone/actions?query=workflow%3Abuild)
|
||||||
[](https://ci.appveyor.com/project/rclone/rclone)
|
|
||||||
[](https://dev.azure.com/rclone/rclone/_build/latest?definitionId=2&branchName=master)
|
|
||||||
[](https://circleci.com/gh/rclone/rclone/tree/master)
|
|
||||||
[](https://goreportcard.com/report/github.com/rclone/rclone)
|
[](https://goreportcard.com/report/github.com/rclone/rclone)
|
||||||
[](https://godoc.org/github.com/rclone/rclone)
|
[](https://godoc.org/github.com/rclone/rclone)
|
||||||
[](https://hub.docker.com/r/rclone/rclone)
|
[](https://hub.docker.com/r/rclone/rclone)
|
||||||
@@ -46,6 +43,7 @@ Rclone *("rsync for cloud storage")* is a command line program to sync files and
|
|||||||
* Mail.ru Cloud [:page_facing_up:](https://rclone.org/mailru/)
|
* Mail.ru Cloud [:page_facing_up:](https://rclone.org/mailru/)
|
||||||
* Memset Memstore [:page_facing_up:](https://rclone.org/swift/)
|
* Memset Memstore [:page_facing_up:](https://rclone.org/swift/)
|
||||||
* Mega [:page_facing_up:](https://rclone.org/mega/)
|
* Mega [:page_facing_up:](https://rclone.org/mega/)
|
||||||
|
* Memory [:page_facing_up:](https://rclone.org/memory/)
|
||||||
* Microsoft Azure Blob Storage [:page_facing_up:](https://rclone.org/azureblob/)
|
* Microsoft Azure Blob Storage [:page_facing_up:](https://rclone.org/azureblob/)
|
||||||
* Microsoft OneDrive [:page_facing_up:](https://rclone.org/onedrive/)
|
* Microsoft OneDrive [:page_facing_up:](https://rclone.org/onedrive/)
|
||||||
* Minio [:page_facing_up:](https://rclone.org/s3/#minio)
|
* Minio [:page_facing_up:](https://rclone.org/s3/#minio)
|
||||||
@@ -62,6 +60,8 @@ Rclone *("rsync for cloud storage")* is a command line program to sync files and
|
|||||||
* Rackspace Cloud Files [:page_facing_up:](https://rclone.org/swift/)
|
* Rackspace Cloud Files [:page_facing_up:](https://rclone.org/swift/)
|
||||||
* Scaleway [:page_facing_up:](https://rclone.org/s3/#scaleway)
|
* Scaleway [:page_facing_up:](https://rclone.org/s3/#scaleway)
|
||||||
* SFTP [:page_facing_up:](https://rclone.org/sftp/)
|
* SFTP [:page_facing_up:](https://rclone.org/sftp/)
|
||||||
|
* StackPath [:page_facing_up:](https://rclone.org/s3/#stackpath)
|
||||||
|
* SugarSync [:page_facing_up:](https://rclone.org/sugarsync/)
|
||||||
* Wasabi [:page_facing_up:](https://rclone.org/s3/#wasabi)
|
* Wasabi [:page_facing_up:](https://rclone.org/s3/#wasabi)
|
||||||
* WebDAV [:page_facing_up:](https://rclone.org/webdav/)
|
* WebDAV [:page_facing_up:](https://rclone.org/webdav/)
|
||||||
* Yandex Disk [:page_facing_up:](https://rclone.org/yandex/)
|
* Yandex Disk [:page_facing_up:](https://rclone.org/yandex/)
|
||||||
|
|||||||
+5
-4
@@ -9,19 +9,20 @@ This file describes how to make the various kinds of releases
|
|||||||
|
|
||||||
## Making a release
|
## Making a release
|
||||||
|
|
||||||
|
* git checkout master
|
||||||
|
* git pull
|
||||||
* git status - make sure everything is checked in
|
* git status - make sure everything is checked in
|
||||||
* Check travis & appveyor builds are green
|
* Check GitHub actions build for master is Green
|
||||||
* make check
|
|
||||||
* make test # see integration test server or run locally
|
* make test # see integration test server or run locally
|
||||||
* make tag
|
* make tag
|
||||||
* edit docs/content/changelog.md
|
* edit docs/content/changelog.md # make sure to remove duplicate logs from point releases
|
||||||
* make tidy
|
* make tidy
|
||||||
* make doc
|
* make doc
|
||||||
* git status - to check for new man pages - git add them
|
* git status - to check for new man pages - git add them
|
||||||
* git commit -a -v -m "Version v1.XX.0"
|
* git commit -a -v -m "Version v1.XX.0"
|
||||||
* make retag
|
* make retag
|
||||||
* git push --tags origin master
|
* git push --tags origin master
|
||||||
* # Wait for the appveyor and travis builds to complete then...
|
* # Wait for the GitHub builds to complete then...
|
||||||
* make fetch_binaries
|
* make fetch_binaries
|
||||||
* make tarball
|
* make tarball
|
||||||
* make sign_upload
|
* make sign_upload
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import (
|
|||||||
_ "github.com/rclone/rclone/backend/local"
|
_ "github.com/rclone/rclone/backend/local"
|
||||||
_ "github.com/rclone/rclone/backend/mailru"
|
_ "github.com/rclone/rclone/backend/mailru"
|
||||||
_ "github.com/rclone/rclone/backend/mega"
|
_ "github.com/rclone/rclone/backend/mega"
|
||||||
|
_ "github.com/rclone/rclone/backend/memory"
|
||||||
_ "github.com/rclone/rclone/backend/onedrive"
|
_ "github.com/rclone/rclone/backend/onedrive"
|
||||||
_ "github.com/rclone/rclone/backend/opendrive"
|
_ "github.com/rclone/rclone/backend/opendrive"
|
||||||
_ "github.com/rclone/rclone/backend/pcloud"
|
_ "github.com/rclone/rclone/backend/pcloud"
|
||||||
@@ -32,6 +33,7 @@ import (
|
|||||||
_ "github.com/rclone/rclone/backend/s3"
|
_ "github.com/rclone/rclone/backend/s3"
|
||||||
_ "github.com/rclone/rclone/backend/sftp"
|
_ "github.com/rclone/rclone/backend/sftp"
|
||||||
_ "github.com/rclone/rclone/backend/sharefile"
|
_ "github.com/rclone/rclone/backend/sharefile"
|
||||||
|
_ "github.com/rclone/rclone/backend/sugarsync"
|
||||||
_ "github.com/rclone/rclone/backend/swift"
|
_ "github.com/rclone/rclone/backend/swift"
|
||||||
_ "github.com/rclone/rclone/backend/union"
|
_ "github.com/rclone/rclone/backend/union"
|
||||||
_ "github.com/rclone/rclone/backend/webdav"
|
_ "github.com/rclone/rclone/backend/webdav"
|
||||||
|
|||||||
@@ -28,18 +28,17 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config"
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
enc = encodings.AmazonCloudDrive
|
|
||||||
folderKind = "FOLDER"
|
folderKind = "FOLDER"
|
||||||
fileKind = "FILE"
|
fileKind = "FILE"
|
||||||
statusAvailable = "AVAILABLE"
|
statusAvailable = "AVAILABLE"
|
||||||
@@ -137,15 +136,23 @@ which downloads the file through a temporary URL directly from the
|
|||||||
underlying S3 storage.`,
|
underlying S3 storage.`,
|
||||||
Default: defaultTempLinkThreshold,
|
Default: defaultTempLinkThreshold,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
Default: (encoder.Base |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Checkpoint string `config:"checkpoint"`
|
Checkpoint string `config:"checkpoint"`
|
||||||
UploadWaitPerGB fs.Duration `config:"upload_wait_per_gb"`
|
UploadWaitPerGB fs.Duration `config:"upload_wait_per_gb"`
|
||||||
TempLinkThreshold fs.SizeSuffix `config:"templink_threshold"`
|
TempLinkThreshold fs.SizeSuffix `config:"templink_threshold"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote acd server
|
// Fs represents a remote acd server
|
||||||
@@ -386,7 +393,7 @@ func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut strin
|
|||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var subFolder *acd.Folder
|
var subFolder *acd.Folder
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
subFolder, resp, err = folder.GetFolder(enc.FromStandardName(leaf))
|
subFolder, resp, err = folder.GetFolder(f.opt.Enc.FromStandardName(leaf))
|
||||||
return f.shouldRetry(resp, err)
|
return f.shouldRetry(resp, err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -413,7 +420,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var info *acd.Folder
|
var info *acd.Folder
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
info, resp, err = folder.CreateFolder(enc.FromStandardName(leaf))
|
info, resp, err = folder.CreateFolder(f.opt.Enc.FromStandardName(leaf))
|
||||||
return f.shouldRetry(resp, err)
|
return f.shouldRetry(resp, err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -481,7 +488,7 @@ func (f *Fs) listAll(dirID string, title string, directoriesOnly bool, filesOnly
|
|||||||
if !hasValidParent {
|
if !hasValidParent {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
*node.Name = enc.ToStandardName(*node.Name)
|
*node.Name = f.opt.Enc.ToStandardName(*node.Name)
|
||||||
// Store the nodes up in case we have to retry the listing
|
// Store the nodes up in case we have to retry the listing
|
||||||
out = append(out, node)
|
out = append(out, node)
|
||||||
}
|
}
|
||||||
@@ -671,7 +678,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
|
|||||||
err = f.pacer.CallNoRetry(func() (bool, error) {
|
err = f.pacer.CallNoRetry(func() (bool, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
f.tokenRenewer.Start()
|
f.tokenRenewer.Start()
|
||||||
info, resp, err = folder.Put(in, enc.FromStandardName(leaf))
|
info, resp, err = folder.Put(in, f.opt.Enc.FromStandardName(leaf))
|
||||||
f.tokenRenewer.Stop()
|
f.tokenRenewer.Stop()
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, info, err = f.checkUpload(ctx, resp, in, src, info, err, time.Since(start))
|
ok, info, err = f.checkUpload(ctx, resp, in, src, info, err, time.Since(start))
|
||||||
@@ -1041,7 +1048,7 @@ func (o *Object) readMetaData(ctx context.Context) (err error) {
|
|||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var info *acd.File
|
var info *acd.File
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
info, resp, err = folder.GetFile(enc.FromStandardName(leaf))
|
info, resp, err = folder.GetFile(o.fs.opt.Enc.FromStandardName(leaf))
|
||||||
return o.fs.shouldRetry(resp, err)
|
return o.fs.shouldRetry(resp, err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1161,7 +1168,7 @@ func (f *Fs) restoreNode(info *acd.Node) (newInfo *acd.Node, err error) {
|
|||||||
func (f *Fs) renameNode(info *acd.Node, newName string) (newInfo *acd.Node, err error) {
|
func (f *Fs) renameNode(info *acd.Node, newName string) (newInfo *acd.Node, err error) {
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
newInfo, resp, err = info.Rename(enc.FromStandardName(newName))
|
newInfo, resp, err = info.Rename(f.opt.Enc.FromStandardName(newName))
|
||||||
return f.shouldRetry(resp, err)
|
return f.shouldRetry(resp, err)
|
||||||
})
|
})
|
||||||
return newInfo, err
|
return newInfo, err
|
||||||
@@ -1357,7 +1364,7 @@ func (f *Fs) changeNotifyRunner(notifyFunc func(string, fs.EntryType), checkpoin
|
|||||||
if len(node.Parents) > 0 {
|
if len(node.Parents) > 0 {
|
||||||
if path, ok := f.dirCache.GetInv(node.Parents[0]); ok {
|
if path, ok := f.dirCache.GetInv(node.Parents[0]); ok {
|
||||||
// and append the drive file name to compute the full file name
|
// and append the drive file name to compute the full file name
|
||||||
name := enc.ToStandardName(*node.Name)
|
name := f.opt.Enc.ToStandardName(*node.Name)
|
||||||
if len(path) > 0 {
|
if len(path) > 0 {
|
||||||
path = path + "/" + name
|
path = path + "/" + name
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -26,14 +25,15 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/accounting"
|
"github.com/rclone/rclone/fs/accounting"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
"github.com/rclone/rclone/lib/bucket"
|
"github.com/rclone/rclone/lib/bucket"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -61,8 +61,6 @@ const (
|
|||||||
emulatorBlobEndpoint = "http://127.0.0.1:10000/devstoreaccount1"
|
emulatorBlobEndpoint = "http://127.0.0.1:10000/devstoreaccount1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.AzureBlob
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
@@ -127,21 +125,32 @@ If blobs are in "archive tier" at remote, trying to perform data transfer
|
|||||||
operations from remote will not be allowed. User should first restore by
|
operations from remote will not be allowed. User should first restore by
|
||||||
tiering blob to "Hot" or "Cool".`,
|
tiering blob to "Hot" or "Cool".`,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
Default: (encoder.EncodeInvalidUtf8 |
|
||||||
|
encoder.EncodeSlash |
|
||||||
|
encoder.EncodeCtl |
|
||||||
|
encoder.EncodeDel |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeRightPeriod),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Account string `config:"account"`
|
Account string `config:"account"`
|
||||||
Key string `config:"key"`
|
Key string `config:"key"`
|
||||||
Endpoint string `config:"endpoint"`
|
Endpoint string `config:"endpoint"`
|
||||||
SASURL string `config:"sas_url"`
|
SASURL string `config:"sas_url"`
|
||||||
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
ListChunkSize uint `config:"list_chunk"`
|
ListChunkSize uint `config:"list_chunk"`
|
||||||
AccessTier string `config:"access_tier"`
|
AccessTier string `config:"access_tier"`
|
||||||
UseEmulator bool `config:"use_emulator"`
|
UseEmulator bool `config:"use_emulator"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote azure server
|
// Fs represents a remote azure server
|
||||||
@@ -189,7 +198,7 @@ func (f *Fs) Root() string {
|
|||||||
// String converts this Fs to a string
|
// String converts this Fs to a string
|
||||||
func (f *Fs) String() string {
|
func (f *Fs) String() string {
|
||||||
if f.rootContainer == "" {
|
if f.rootContainer == "" {
|
||||||
return fmt.Sprintf("Azure root")
|
return "Azure root"
|
||||||
}
|
}
|
||||||
if f.rootDirectory == "" {
|
if f.rootDirectory == "" {
|
||||||
return fmt.Sprintf("Azure container %s", f.rootContainer)
|
return fmt.Sprintf("Azure container %s", f.rootContainer)
|
||||||
@@ -212,7 +221,7 @@ func parsePath(path string) (root string) {
|
|||||||
// relative to f.root
|
// relative to f.root
|
||||||
func (f *Fs) split(rootRelativePath string) (containerName, containerPath string) {
|
func (f *Fs) split(rootRelativePath string) (containerName, containerPath string) {
|
||||||
containerName, containerPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
containerName, containerPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
||||||
return enc.FromStandardName(containerName), enc.FromStandardPath(containerPath)
|
return f.opt.Enc.FromStandardName(containerName), f.opt.Enc.FromStandardPath(containerPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// split returns container and containerPath from the object
|
// split returns container and containerPath from the object
|
||||||
@@ -588,7 +597,7 @@ func (f *Fs) list(ctx context.Context, container, directory, prefix string, addC
|
|||||||
// if prefix != "" && !strings.HasPrefix(file.Name, prefix) {
|
// if prefix != "" && !strings.HasPrefix(file.Name, prefix) {
|
||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
remote := enc.ToStandardPath(file.Name)
|
remote := f.opt.Enc.ToStandardPath(file.Name)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Debugf(f, "Odd name received %q", remote)
|
fs.Debugf(f, "Odd name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -609,7 +618,7 @@ func (f *Fs) list(ctx context.Context, container, directory, prefix string, addC
|
|||||||
// Send the subdirectories
|
// Send the subdirectories
|
||||||
for _, remote := range response.Segment.BlobPrefixes {
|
for _, remote := range response.Segment.BlobPrefixes {
|
||||||
remote := strings.TrimRight(remote.Name, "/")
|
remote := strings.TrimRight(remote.Name, "/")
|
||||||
remote = enc.ToStandardPath(remote)
|
remote = f.opt.Enc.ToStandardPath(remote)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Debugf(f, "Odd directory name received %q", remote)
|
fs.Debugf(f, "Odd directory name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -673,7 +682,7 @@ func (f *Fs) listContainers(ctx context.Context) (entries fs.DirEntries, err err
|
|||||||
return entries, nil
|
return entries, nil
|
||||||
}
|
}
|
||||||
err = f.listContainersToFn(func(container *azblob.ContainerItem) error {
|
err = f.listContainersToFn(func(container *azblob.ContainerItem) error {
|
||||||
d := fs.NewDir(enc.ToStandardName(container.Name), container.Properties.LastModified)
|
d := fs.NewDir(f.opt.Enc.ToStandardName(container.Name), container.Properties.LastModified)
|
||||||
f.cache.MarkOK(container.Name)
|
f.cache.MarkOK(container.Name)
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
return nil
|
return nil
|
||||||
@@ -1111,22 +1120,6 @@ func (o *Object) readMetaData() (err error) {
|
|||||||
return o.decodeMetaDataFromPropertiesResponse(blobProperties)
|
return o.decodeMetaDataFromPropertiesResponse(blobProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseTimeString converts a decimal string number of milliseconds
|
|
||||||
// elapsed since January 1, 1970 UTC into a time.Time and stores it in
|
|
||||||
// the modTime variable.
|
|
||||||
func (o *Object) parseTimeString(timeString string) (err error) {
|
|
||||||
if timeString == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
unixMilliseconds, err := strconv.ParseInt(timeString, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
fs.Debugf(o, "Failed to parse mod time string %q: %v", timeString, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
o.modTime = time.Unix(unixMilliseconds/1e3, (unixMilliseconds%1e3)*1e6).UTC()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ModTime returns the modification time of the object
|
// ModTime returns the modification time of the object
|
||||||
//
|
//
|
||||||
// It attempts to read the objects mtime and if that isn't present the
|
// It attempts to read the objects mtime and if that isn't present the
|
||||||
|
|||||||
+37
-27
@@ -23,20 +23,19 @@ import (
|
|||||||
"github.com/rclone/rclone/backend/b2/api"
|
"github.com/rclone/rclone/backend/b2/api"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/accounting"
|
"github.com/rclone/rclone/fs/accounting"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
"github.com/rclone/rclone/lib/bucket"
|
"github.com/rclone/rclone/lib/bucket"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.B2
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultEndpoint = "https://api.backblazeb2.com"
|
defaultEndpoint = "https://api.backblazeb2.com"
|
||||||
headerPrefix = "x-bz-info-" // lower case as that is what the server returns
|
headerPrefix = "x-bz-info-" // lower case as that is what the server returns
|
||||||
@@ -146,23 +145,34 @@ The duration before the download authorization token will expire.
|
|||||||
The minimum value is 1 second. The maximum value is one week.`,
|
The minimum value is 1 second. The maximum value is one week.`,
|
||||||
Default: fs.Duration(7 * 24 * time.Hour),
|
Default: fs.Duration(7 * 24 * time.Hour),
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// See: https://www.backblaze.com/b2/docs/files.html
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
// FIXME: allow /, but not leading, trailing or double
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Account string `config:"account"`
|
Account string `config:"account"`
|
||||||
Key string `config:"key"`
|
Key string `config:"key"`
|
||||||
Endpoint string `config:"endpoint"`
|
Endpoint string `config:"endpoint"`
|
||||||
TestMode string `config:"test_mode"`
|
TestMode string `config:"test_mode"`
|
||||||
Versions bool `config:"versions"`
|
Versions bool `config:"versions"`
|
||||||
HardDelete bool `config:"hard_delete"`
|
HardDelete bool `config:"hard_delete"`
|
||||||
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
DisableCheckSum bool `config:"disable_checksum"`
|
DisableCheckSum bool `config:"disable_checksum"`
|
||||||
DownloadURL string `config:"download_url"`
|
DownloadURL string `config:"download_url"`
|
||||||
DownloadAuthorizationDuration fs.Duration `config:"download_auth_duration"`
|
DownloadAuthorizationDuration fs.Duration `config:"download_auth_duration"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote b2 server
|
// Fs represents a remote b2 server
|
||||||
@@ -402,7 +412,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
}
|
}
|
||||||
// If this is a key limited to a single bucket, it must exist already
|
// If this is a key limited to a single bucket, it must exist already
|
||||||
if f.rootBucket != "" && f.info.Allowed.BucketID != "" {
|
if f.rootBucket != "" && f.info.Allowed.BucketID != "" {
|
||||||
allowedBucket := enc.ToStandardName(f.info.Allowed.BucketName)
|
allowedBucket := f.opt.Enc.ToStandardName(f.info.Allowed.BucketName)
|
||||||
if allowedBucket == "" {
|
if allowedBucket == "" {
|
||||||
return nil, errors.New("bucket that application key is restricted to no longer exists")
|
return nil, errors.New("bucket that application key is restricted to no longer exists")
|
||||||
}
|
}
|
||||||
@@ -623,11 +633,11 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
var request = api.ListFileNamesRequest{
|
var request = api.ListFileNamesRequest{
|
||||||
BucketID: bucketID,
|
BucketID: bucketID,
|
||||||
MaxFileCount: chunkSize,
|
MaxFileCount: chunkSize,
|
||||||
Prefix: enc.FromStandardPath(directory),
|
Prefix: f.opt.Enc.FromStandardPath(directory),
|
||||||
Delimiter: delimiter,
|
Delimiter: delimiter,
|
||||||
}
|
}
|
||||||
if directory != "" {
|
if directory != "" {
|
||||||
request.StartFileName = enc.FromStandardPath(directory)
|
request.StartFileName = f.opt.Enc.FromStandardPath(directory)
|
||||||
}
|
}
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
@@ -647,7 +657,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
}
|
}
|
||||||
for i := range response.Files {
|
for i := range response.Files {
|
||||||
file := &response.Files[i]
|
file := &response.Files[i]
|
||||||
file.Name = enc.ToStandardPath(file.Name)
|
file.Name = f.opt.Enc.ToStandardPath(file.Name)
|
||||||
// Finish if file name no longer has prefix
|
// Finish if file name no longer has prefix
|
||||||
if prefix != "" && !strings.HasPrefix(file.Name, prefix) {
|
if prefix != "" && !strings.HasPrefix(file.Name, prefix) {
|
||||||
return nil
|
return nil
|
||||||
@@ -848,7 +858,7 @@ func (f *Fs) listBucketsToFn(ctx context.Context, fn listBucketFn) error {
|
|||||||
f._bucketType = make(map[string]string, 1)
|
f._bucketType = make(map[string]string, 1)
|
||||||
for i := range response.Buckets {
|
for i := range response.Buckets {
|
||||||
bucket := &response.Buckets[i]
|
bucket := &response.Buckets[i]
|
||||||
bucket.Name = enc.ToStandardName(bucket.Name)
|
bucket.Name = f.opt.Enc.ToStandardName(bucket.Name)
|
||||||
f.cache.MarkOK(bucket.Name)
|
f.cache.MarkOK(bucket.Name)
|
||||||
f._bucketID[bucket.Name] = bucket.ID
|
f._bucketID[bucket.Name] = bucket.ID
|
||||||
f._bucketType[bucket.Name] = bucket.Type
|
f._bucketType[bucket.Name] = bucket.Type
|
||||||
@@ -970,7 +980,7 @@ func (f *Fs) makeBucket(ctx context.Context, bucket string) error {
|
|||||||
}
|
}
|
||||||
var request = api.CreateBucketRequest{
|
var request = api.CreateBucketRequest{
|
||||||
AccountID: f.info.AccountID,
|
AccountID: f.info.AccountID,
|
||||||
Name: enc.FromStandardName(bucket),
|
Name: f.opt.Enc.FromStandardName(bucket),
|
||||||
Type: "allPrivate",
|
Type: "allPrivate",
|
||||||
}
|
}
|
||||||
var response api.Bucket
|
var response api.Bucket
|
||||||
@@ -1054,7 +1064,7 @@ func (f *Fs) hide(ctx context.Context, bucket, bucketPath string) error {
|
|||||||
}
|
}
|
||||||
var request = api.HideFileRequest{
|
var request = api.HideFileRequest{
|
||||||
BucketID: bucketID,
|
BucketID: bucketID,
|
||||||
Name: enc.FromStandardPath(bucketPath),
|
Name: f.opt.Enc.FromStandardPath(bucketPath),
|
||||||
}
|
}
|
||||||
var response api.File
|
var response api.File
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@@ -1082,7 +1092,7 @@ func (f *Fs) deleteByID(ctx context.Context, ID, Name string) error {
|
|||||||
}
|
}
|
||||||
var request = api.DeleteFileRequest{
|
var request = api.DeleteFileRequest{
|
||||||
ID: ID,
|
ID: ID,
|
||||||
Name: enc.FromStandardPath(Name),
|
Name: f.opt.Enc.FromStandardPath(Name),
|
||||||
}
|
}
|
||||||
var response api.File
|
var response api.File
|
||||||
err := f.pacer.Call(func() (bool, error) {
|
err := f.pacer.Call(func() (bool, error) {
|
||||||
@@ -1220,7 +1230,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
}
|
}
|
||||||
var request = api.CopyFileRequest{
|
var request = api.CopyFileRequest{
|
||||||
SourceID: srcObj.id,
|
SourceID: srcObj.id,
|
||||||
Name: enc.FromStandardPath(dstPath),
|
Name: f.opt.Enc.FromStandardPath(dstPath),
|
||||||
MetadataDirective: "COPY",
|
MetadataDirective: "COPY",
|
||||||
DestBucketID: destBucketID,
|
DestBucketID: destBucketID,
|
||||||
}
|
}
|
||||||
@@ -1268,7 +1278,7 @@ func (f *Fs) getDownloadAuthorization(ctx context.Context, bucket, remote string
|
|||||||
}
|
}
|
||||||
var request = api.GetDownloadAuthorizationRequest{
|
var request = api.GetDownloadAuthorizationRequest{
|
||||||
BucketID: bucketID,
|
BucketID: bucketID,
|
||||||
FileNamePrefix: enc.FromStandardPath(path.Join(f.root, remote)),
|
FileNamePrefix: f.opt.Enc.FromStandardPath(path.Join(f.root, remote)),
|
||||||
ValidDurationInSeconds: validDurationInSeconds,
|
ValidDurationInSeconds: validDurationInSeconds,
|
||||||
}
|
}
|
||||||
var response api.GetDownloadAuthorizationResponse
|
var response api.GetDownloadAuthorizationResponse
|
||||||
@@ -1509,7 +1519,7 @@ func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error {
|
|||||||
}
|
}
|
||||||
var request = api.CopyFileRequest{
|
var request = api.CopyFileRequest{
|
||||||
SourceID: o.id,
|
SourceID: o.id,
|
||||||
Name: enc.FromStandardPath(bucketPath), // copy to same name
|
Name: o.fs.opt.Enc.FromStandardPath(bucketPath), // copy to same name
|
||||||
MetadataDirective: "REPLACE",
|
MetadataDirective: "REPLACE",
|
||||||
ContentType: info.ContentType,
|
ContentType: info.ContentType,
|
||||||
Info: info.Info,
|
Info: info.Info,
|
||||||
@@ -1611,7 +1621,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
|||||||
opts.Path += "/b2api/v1/b2_download_file_by_id?fileId=" + urlEncode(o.id)
|
opts.Path += "/b2api/v1/b2_download_file_by_id?fileId=" + urlEncode(o.id)
|
||||||
} else {
|
} else {
|
||||||
bucket, bucketPath := o.split()
|
bucket, bucketPath := o.split()
|
||||||
opts.Path += "/file/" + urlEncode(enc.FromStandardName(bucket)) + "/" + urlEncode(enc.FromStandardPath(bucketPath))
|
opts.Path += "/file/" + urlEncode(o.fs.opt.Enc.FromStandardName(bucket)) + "/" + urlEncode(o.fs.opt.Enc.FromStandardPath(bucketPath))
|
||||||
}
|
}
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
@@ -1808,7 +1818,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
Body: in,
|
Body: in,
|
||||||
ExtraHeaders: map[string]string{
|
ExtraHeaders: map[string]string{
|
||||||
"Authorization": upload.AuthorizationToken,
|
"Authorization": upload.AuthorizationToken,
|
||||||
"X-Bz-File-Name": urlEncode(enc.FromStandardPath(bucketPath)),
|
"X-Bz-File-Name": urlEncode(o.fs.opt.Enc.FromStandardPath(bucketPath)),
|
||||||
"Content-Type": fs.MimeType(ctx, src),
|
"Content-Type": fs.MimeType(ctx, src),
|
||||||
sha1Header: calculatedSha1,
|
sha1Header: calculatedSha1,
|
||||||
timeHeader: timeString(modTime),
|
timeHeader: timeString(modTime),
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ func (f *Fs) newLargeUpload(ctx context.Context, o *Object, in io.Reader, src fs
|
|||||||
}
|
}
|
||||||
var request = api.StartLargeFileRequest{
|
var request = api.StartLargeFileRequest{
|
||||||
BucketID: bucketID,
|
BucketID: bucketID,
|
||||||
Name: enc.FromStandardPath(bucketPath),
|
Name: f.opt.Enc.FromStandardPath(bucketPath),
|
||||||
ContentType: fs.MimeType(ctx, src),
|
ContentType: fs.MimeType(ctx, src),
|
||||||
Info: map[string]string{
|
Info: map[string]string{
|
||||||
timeKey: timeString(modTime),
|
timeKey: timeString(modTime),
|
||||||
|
|||||||
+24
-10
@@ -25,6 +25,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/jwtutil"
|
"github.com/rclone/rclone/lib/jwtutil"
|
||||||
|
|
||||||
"github.com/youmark/pkcs8"
|
"github.com/youmark/pkcs8"
|
||||||
@@ -36,7 +37,6 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
@@ -48,8 +48,6 @@ import (
|
|||||||
"golang.org/x/oauth2/jws"
|
"golang.org/x/oauth2/jws"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Box
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "d0374ba6pgmaguie02ge15sv1mllndho"
|
rcloneClientID = "d0374ba6pgmaguie02ge15sv1mllndho"
|
||||||
rcloneEncryptedClientSecret = "sYbJYm99WB8jzeaLPU0OPDMJKIkZvD2qOn3SyEMfiJr03RdtDt3xcZEIudRhbIDL"
|
rcloneEncryptedClientSecret = "sYbJYm99WB8jzeaLPU0OPDMJKIkZvD2qOn3SyEMfiJr03RdtDt3xcZEIudRhbIDL"
|
||||||
@@ -146,6 +144,21 @@ func init() {
|
|||||||
Help: "Max number of times to try committing a multipart file.",
|
Help: "Max number of times to try committing a multipart file.",
|
||||||
Default: 100,
|
Default: 100,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// From https://developer.box.com/docs/error-codes#section-400-bad-request :
|
||||||
|
// > Box only supports file or folder names that are 255 characters or less.
|
||||||
|
// > File names containing non-printable ascii, "/" or "\", names with leading
|
||||||
|
// > or trailing spaces, and the special names “.” and “..” are also unsupported.
|
||||||
|
//
|
||||||
|
// Testing revealed names with leading spaces work fine.
|
||||||
|
// Also encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeRightSpace |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -220,8 +233,9 @@ func getDecryptedPrivateKey(boxConfig *api.ConfigJSON) (key *rsa.PrivateKey, err
|
|||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
||||||
CommitRetries int `config:"commit_retries"`
|
CommitRetries int `config:"commit_retries"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote box
|
// Fs represents a remote box
|
||||||
@@ -488,7 +502,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
Parameters: fieldsValue(),
|
Parameters: fieldsValue(),
|
||||||
}
|
}
|
||||||
mkdir := api.CreateFolder{
|
mkdir := api.CreateFolder{
|
||||||
Name: enc.FromStandardName(leaf),
|
Name: f.opt.Enc.FromStandardName(leaf),
|
||||||
Parent: api.Parent{
|
Parent: api.Parent{
|
||||||
ID: pathID,
|
ID: pathID,
|
||||||
},
|
},
|
||||||
@@ -554,7 +568,7 @@ OUTER:
|
|||||||
if item.ItemStatus != api.ItemStatusActive {
|
if item.ItemStatus != api.ItemStatusActive {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
item.Name = enc.ToStandardName(item.Name)
|
item.Name = f.opt.Enc.ToStandardName(item.Name)
|
||||||
if fn(item) {
|
if fn(item) {
|
||||||
found = true
|
found = true
|
||||||
break OUTER
|
break OUTER
|
||||||
@@ -791,7 +805,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
Parameters: fieldsValue(),
|
Parameters: fieldsValue(),
|
||||||
}
|
}
|
||||||
copyFile := api.CopyFile{
|
copyFile := api.CopyFile{
|
||||||
Name: enc.FromStandardName(leaf),
|
Name: f.opt.Enc.FromStandardName(leaf),
|
||||||
Parent: api.Parent{
|
Parent: api.Parent{
|
||||||
ID: directoryID,
|
ID: directoryID,
|
||||||
},
|
},
|
||||||
@@ -830,7 +844,7 @@ func (f *Fs) move(ctx context.Context, endpoint, id, leaf, directoryID string) (
|
|||||||
Parameters: fieldsValue(),
|
Parameters: fieldsValue(),
|
||||||
}
|
}
|
||||||
move := api.UpdateFileMove{
|
move := api.UpdateFileMove{
|
||||||
Name: enc.FromStandardName(leaf),
|
Name: f.opt.Enc.FromStandardName(leaf),
|
||||||
Parent: api.Parent{
|
Parent: api.Parent{
|
||||||
ID: directoryID,
|
ID: directoryID,
|
||||||
},
|
},
|
||||||
@@ -1155,7 +1169,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
|||||||
// This is recommended for less than 50 MB of content
|
// This is recommended for less than 50 MB of content
|
||||||
func (o *Object) upload(ctx context.Context, in io.Reader, leaf, directoryID string, modTime time.Time) (err error) {
|
func (o *Object) upload(ctx context.Context, in io.Reader, leaf, directoryID string, modTime time.Time) (err error) {
|
||||||
upload := api.UploadFile{
|
upload := api.UploadFile{
|
||||||
Name: enc.FromStandardName(leaf),
|
Name: o.fs.opt.Enc.FromStandardName(leaf),
|
||||||
ContentModifiedAt: api.Time(modTime),
|
ContentModifiedAt: api.Time(modTime),
|
||||||
ContentCreatedAt: api.Time(modTime),
|
ContentCreatedAt: api.Time(modTime),
|
||||||
Parent: api.Parent{
|
Parent: api.Parent{
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (o *Object) createUploadSession(ctx context.Context, leaf, directoryID stri
|
|||||||
} else {
|
} else {
|
||||||
opts.Path = "/files/upload_sessions"
|
opts.Path = "/files/upload_sessions"
|
||||||
request.FolderID = directoryID
|
request.FolderID = directoryID
|
||||||
request.FileName = enc.FromStandardName(leaf)
|
request.FileName = o.fs.opt.Enc.FromStandardName(leaf)
|
||||||
}
|
}
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
|
|||||||
Vendored
+1
-38
@@ -1,4 +1,5 @@
|
|||||||
// +build !plan9
|
// +build !plan9
|
||||||
|
// +build !race
|
||||||
|
|
||||||
package cache_test
|
package cache_test
|
||||||
|
|
||||||
@@ -17,7 +18,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -1139,23 +1139,6 @@ func (r *run) randomReader(t *testing.T, size int64) io.ReadCloser {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *run) writeRemoteRandomBytes(t *testing.T, f fs.Fs, p string, size int64) string {
|
|
||||||
remote := path.Join(p, strconv.Itoa(rand.Int())+".bin")
|
|
||||||
// create some rand test data
|
|
||||||
testData := randStringBytes(int(size))
|
|
||||||
|
|
||||||
r.writeRemoteBytes(t, f, remote, testData)
|
|
||||||
return remote
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *run) writeObjectRandomBytes(t *testing.T, f fs.Fs, p string, size int64) fs.Object {
|
|
||||||
remote := path.Join(p, strconv.Itoa(rand.Int())+".bin")
|
|
||||||
// create some rand test data
|
|
||||||
testData := randStringBytes(int(size))
|
|
||||||
|
|
||||||
return r.writeObjectBytes(t, f, remote, testData)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *run) writeRemoteString(t *testing.T, f fs.Fs, remote, content string) {
|
func (r *run) writeRemoteString(t *testing.T, f fs.Fs, remote, content string) {
|
||||||
r.writeRemoteBytes(t, f, remote, []byte(content))
|
r.writeRemoteBytes(t, f, remote, []byte(content))
|
||||||
}
|
}
|
||||||
@@ -1344,26 +1327,6 @@ func (r *run) list(t *testing.T, f fs.Fs, remote string) ([]interface{}, error)
|
|||||||
return l, err
|
return l, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *run) listPath(t *testing.T, f fs.Fs, remote string) []string {
|
|
||||||
var err error
|
|
||||||
var l []string
|
|
||||||
if r.useMount {
|
|
||||||
var list []os.FileInfo
|
|
||||||
list, err = ioutil.ReadDir(path.Join(r.mntDir, remote))
|
|
||||||
for _, ll := range list {
|
|
||||||
l = append(l, ll.Name())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var list fs.DirEntries
|
|
||||||
list, err = f.List(context.Background(), remote)
|
|
||||||
for _, ll := range list {
|
|
||||||
l = append(l, ll.Remote())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
require.NoError(t, err)
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *run) copyFile(t *testing.T, f fs.Fs, src, dst string) error {
|
func (r *run) copyFile(t *testing.T, f fs.Fs, src, dst string) error {
|
||||||
in, err := os.Open(src)
|
in, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+4
-3
@@ -1,7 +1,8 @@
|
|||||||
// +build !linux !go1.11
|
// +build !linux !go1.13
|
||||||
// +build !darwin !go1.11
|
// +build !darwin !go1.13
|
||||||
// +build !freebsd !go1.11
|
// +build !freebsd !go1.13
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
// +build !race
|
||||||
|
|
||||||
package cache_test
|
package cache_test
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
// +build linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// +build linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
|
// +build !race
|
||||||
|
|
||||||
package cache_test
|
package cache_test
|
||||||
|
|
||||||
|
|||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// +build windows
|
// +build windows
|
||||||
|
// +build !race
|
||||||
|
|
||||||
package cache_test
|
package cache_test
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
@@ -1,6 +1,7 @@
|
|||||||
// Test Cache filesystem interface
|
// Test Cache filesystem interface
|
||||||
|
|
||||||
// +build !plan9
|
// +build !plan9
|
||||||
|
// +build !race
|
||||||
|
|
||||||
package cache_test
|
package cache_test
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
@@ -1,4 +1,5 @@
|
|||||||
// +build !plan9
|
// +build !plan9
|
||||||
|
// +build !race
|
||||||
|
|
||||||
package cache_test
|
package cache_test
|
||||||
|
|
||||||
|
|||||||
Vendored
-9
@@ -101,15 +101,6 @@ func (d *Directory) abs() string {
|
|||||||
return cleanPath(path.Join(d.Dir, d.Name))
|
return cleanPath(path.Join(d.Dir, d.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// parentRemote returns the absolute path parent remote
|
|
||||||
func (d *Directory) parentRemote() string {
|
|
||||||
absPath := d.abs()
|
|
||||||
if absPath == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return cleanPath(path.Dir(absPath))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ModTime returns the cached ModTime
|
// ModTime returns the cached ModTime
|
||||||
func (d *Directory) ModTime(ctx context.Context) time.Time {
|
func (d *Directory) ModTime(ctx context.Context) time.Time {
|
||||||
return time.Unix(0, d.CacheModTime)
|
return time.Unix(0, d.CacheModTime)
|
||||||
|
|||||||
Vendored
+18
-10
@@ -24,15 +24,16 @@ const (
|
|||||||
type Object struct {
|
type Object struct {
|
||||||
fs.Object `json:"-"`
|
fs.Object `json:"-"`
|
||||||
|
|
||||||
ParentFs fs.Fs `json:"-"` // parent fs
|
ParentFs fs.Fs `json:"-"` // parent fs
|
||||||
CacheFs *Fs `json:"-"` // cache fs
|
CacheFs *Fs `json:"-"` // cache fs
|
||||||
Name string `json:"name"` // name of the directory
|
Name string `json:"name"` // name of the directory
|
||||||
Dir string `json:"dir"` // abs path of the object
|
Dir string `json:"dir"` // abs path of the object
|
||||||
CacheModTime int64 `json:"modTime"` // modification or creation time - IsZero for unknown
|
CacheModTime int64 `json:"modTime"` // modification or creation time - IsZero for unknown
|
||||||
CacheSize int64 `json:"size"` // size of directory and contents or -1 if unknown
|
CacheSize int64 `json:"size"` // size of directory and contents or -1 if unknown
|
||||||
CacheStorable bool `json:"storable"` // says whether this object can be stored
|
CacheStorable bool `json:"storable"` // says whether this object can be stored
|
||||||
CacheType string `json:"cacheType"`
|
CacheType string `json:"cacheType"`
|
||||||
CacheTs time.Time `json:"cacheTs"`
|
CacheTs time.Time `json:"cacheTs"`
|
||||||
|
cacheHashesMu sync.Mutex
|
||||||
CacheHashes map[hash.Type]string // all supported hashes cached
|
CacheHashes map[hash.Type]string // all supported hashes cached
|
||||||
|
|
||||||
refreshMutex sync.Mutex
|
refreshMutex sync.Mutex
|
||||||
@@ -103,7 +104,9 @@ func (o *Object) updateData(ctx context.Context, source fs.Object) {
|
|||||||
o.CacheSize = source.Size()
|
o.CacheSize = source.Size()
|
||||||
o.CacheStorable = source.Storable()
|
o.CacheStorable = source.Storable()
|
||||||
o.CacheTs = time.Now()
|
o.CacheTs = time.Now()
|
||||||
|
o.cacheHashesMu.Lock()
|
||||||
o.CacheHashes = make(map[hash.Type]string)
|
o.CacheHashes = make(map[hash.Type]string)
|
||||||
|
o.cacheHashesMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs returns its FS info
|
// Fs returns its FS info
|
||||||
@@ -268,7 +271,9 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
|
|
||||||
o.CacheModTime = src.ModTime(ctx).UnixNano()
|
o.CacheModTime = src.ModTime(ctx).UnixNano()
|
||||||
o.CacheSize = src.Size()
|
o.CacheSize = src.Size()
|
||||||
|
o.cacheHashesMu.Lock()
|
||||||
o.CacheHashes = make(map[hash.Type]string)
|
o.CacheHashes = make(map[hash.Type]string)
|
||||||
|
o.cacheHashesMu.Unlock()
|
||||||
o.CacheTs = time.Now()
|
o.CacheTs = time.Now()
|
||||||
o.persist()
|
o.persist()
|
||||||
|
|
||||||
@@ -309,11 +314,12 @@ func (o *Object) Remove(ctx context.Context) error {
|
|||||||
// since it might or might not be called, this is lazy loaded
|
// since it might or might not be called, this is lazy loaded
|
||||||
func (o *Object) Hash(ctx context.Context, ht hash.Type) (string, error) {
|
func (o *Object) Hash(ctx context.Context, ht hash.Type) (string, error) {
|
||||||
_ = o.refresh(ctx)
|
_ = o.refresh(ctx)
|
||||||
|
o.cacheHashesMu.Lock()
|
||||||
if o.CacheHashes == nil {
|
if o.CacheHashes == nil {
|
||||||
o.CacheHashes = make(map[hash.Type]string)
|
o.CacheHashes = make(map[hash.Type]string)
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedHash, found := o.CacheHashes[ht]
|
cachedHash, found := o.CacheHashes[ht]
|
||||||
|
o.cacheHashesMu.Unlock()
|
||||||
if found {
|
if found {
|
||||||
return cachedHash, nil
|
return cachedHash, nil
|
||||||
}
|
}
|
||||||
@@ -324,7 +330,9 @@ func (o *Object) Hash(ctx context.Context, ht hash.Type) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
o.cacheHashesMu.Lock()
|
||||||
o.CacheHashes[ht] = liveHash
|
o.CacheHashes[ht] = liveHash
|
||||||
|
o.cacheHashesMu.Unlock()
|
||||||
|
|
||||||
o.persist()
|
o.persist()
|
||||||
fs.Debugf(o, "object hash cached: %v", liveHash)
|
fs.Debugf(o, "object hash cached: %v", liveHash)
|
||||||
|
|||||||
Vendored
-25
@@ -767,31 +767,6 @@ func (b *Persistent) iterateBuckets(buk *bolt.Bucket, bucketFn func(name string)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Persistent) dumpRoot() string {
|
|
||||||
var itBuckets func(buk *bolt.Bucket) map[string]interface{}
|
|
||||||
|
|
||||||
itBuckets = func(buk *bolt.Bucket) map[string]interface{} {
|
|
||||||
m := make(map[string]interface{})
|
|
||||||
c := buk.Cursor()
|
|
||||||
for k, v := c.First(); k != nil; k, v = c.Next() {
|
|
||||||
if v == nil {
|
|
||||||
buk2 := buk.Bucket(k)
|
|
||||||
m[string(k)] = itBuckets(buk2)
|
|
||||||
} else {
|
|
||||||
m[string(k)] = "-"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
var mm map[string]interface{}
|
|
||||||
_ = b.db.View(func(tx *bolt.Tx) error {
|
|
||||||
mm = itBuckets(tx.Bucket([]byte(RootBucket)))
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
raw, _ := json.MarshalIndent(mm, "", " ")
|
|
||||||
return string(raw)
|
|
||||||
}
|
|
||||||
|
|
||||||
// addPendingUpload adds a new file to the pending queue of uploads
|
// addPendingUpload adds a new file to the pending queue of uploads
|
||||||
func (b *Persistent) addPendingUpload(destPath string, started bool) error {
|
func (b *Persistent) addPendingUpload(destPath string, started bool) error {
|
||||||
return b.db.Update(func(tx *bolt.Tx) error {
|
return b.db.Update(func(tx *bolt.Tx) error {
|
||||||
|
|||||||
+12
-5
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -35,19 +36,21 @@ func init() {
|
|||||||
Default: "standard",
|
Default: "standard",
|
||||||
Examples: []fs.OptionExample{
|
Examples: []fs.OptionExample{
|
||||||
{
|
{
|
||||||
Value: "off",
|
|
||||||
Help: "Don't encrypt the file names. Adds a \".bin\" extension only.",
|
|
||||||
}, {
|
|
||||||
Value: "standard",
|
Value: "standard",
|
||||||
Help: "Encrypt the filenames see the docs for the details.",
|
Help: "Encrypt the filenames see the docs for the details.",
|
||||||
}, {
|
}, {
|
||||||
Value: "obfuscate",
|
Value: "obfuscate",
|
||||||
Help: "Very simple filename obfuscation.",
|
Help: "Very simple filename obfuscation.",
|
||||||
|
}, {
|
||||||
|
Value: "off",
|
||||||
|
Help: "Don't encrypt the file names. Adds a \".bin\" extension only.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
Name: "directory_name_encryption",
|
Name: "directory_name_encryption",
|
||||||
Help: "Option to either encrypt directory names or leave them intact.",
|
Help: `Option to either encrypt directory names or leave them intact.
|
||||||
|
|
||||||
|
NB If filename_encryption is "off" then this option will do nothing.`,
|
||||||
Default: true,
|
Default: true,
|
||||||
Examples: []fs.OptionExample{
|
Examples: []fs.OptionExample{
|
||||||
{
|
{
|
||||||
@@ -144,6 +147,10 @@ func NewFs(name, rpath string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to parse remote %q to wrap", remote)
|
return nil, errors.Wrapf(err, "failed to parse remote %q to wrap", remote)
|
||||||
}
|
}
|
||||||
|
// Make sure to remove trailing . reffering to the current dir
|
||||||
|
if path.Base(rpath) == "." {
|
||||||
|
rpath = strings.TrimSuffix(rpath, ".")
|
||||||
|
}
|
||||||
// Look for a file first
|
// Look for a file first
|
||||||
remotePath := fspath.JoinRootPath(wPath, cipher.EncryptFileName(rpath))
|
remotePath := fspath.JoinRootPath(wPath, cipher.EncryptFileName(rpath))
|
||||||
wrappedFs, err := wInfo.NewFs(wName, remotePath, wConfig)
|
wrappedFs, err := wInfo.NewFs(wName, remotePath, wConfig)
|
||||||
|
|||||||
+113
-68
@@ -33,12 +33,12 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
@@ -49,8 +49,6 @@ import (
|
|||||||
"google.golang.org/api/googleapi"
|
"google.golang.org/api/googleapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Drive
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "202264815644.apps.googleusercontent.com"
|
rcloneClientID = "202264815644.apps.googleusercontent.com"
|
||||||
@@ -326,6 +324,7 @@ Photos folder" option in your google drive settings. You can then copy
|
|||||||
or move the photos locally and use the date the image was taken
|
or move the photos locally and use the date the image was taken
|
||||||
(created) set as the modification date.`,
|
(created) set as the modification date.`,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
Hide: fs.OptionHideConfigurator,
|
||||||
}, {
|
}, {
|
||||||
Name: "use_shared_date",
|
Name: "use_shared_date",
|
||||||
Default: false,
|
Default: false,
|
||||||
@@ -337,6 +336,7 @@ unexpected consequences when uploading/downloading files.
|
|||||||
If both this flag and "--drive-use-created-date" are set, the created
|
If both this flag and "--drive-use-created-date" are set, the created
|
||||||
date is used.`,
|
date is used.`,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
Hide: fs.OptionHideConfigurator,
|
||||||
}, {
|
}, {
|
||||||
Name: "list_chunk",
|
Name: "list_chunk",
|
||||||
Default: 1000,
|
Default: 1000,
|
||||||
@@ -395,11 +395,22 @@ will download it anyway.`,
|
|||||||
}, {
|
}, {
|
||||||
Name: "size_as_quota",
|
Name: "size_as_quota",
|
||||||
Default: false,
|
Default: false,
|
||||||
Help: `Show storage quota usage for file size.
|
Help: `Show sizes as storage quota usage, not actual size.
|
||||||
|
|
||||||
The storage used by a file is the size of the current version plus any
|
Show the size of a file as the the storage quota used. This is the
|
||||||
older versions that have been set to keep forever.`,
|
current version plus any older versions that have been set to keep
|
||||||
|
forever.
|
||||||
|
|
||||||
|
**WARNING**: This flag may have some unexpected consequences.
|
||||||
|
|
||||||
|
It is not recommended to set this flag in your config - the
|
||||||
|
recommended usage is using the flag form --drive-size-as-quota when
|
||||||
|
doing rclone ls/lsl/lsf/lsjson/etc only.
|
||||||
|
|
||||||
|
If you do use this flag for syncing (not recommended) then you will
|
||||||
|
need to use --ignore size also.`,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
Hide: fs.OptionHideConfigurator,
|
||||||
}, {
|
}, {
|
||||||
Name: "v2_download_min_size",
|
Name: "v2_download_min_size",
|
||||||
Default: fs.SizeSuffix(-1),
|
Default: fs.SizeSuffix(-1),
|
||||||
@@ -439,6 +450,30 @@ See: https://github.com/rclone/rclone/issues/3631
|
|||||||
|
|
||||||
`,
|
`,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: "stop_on_upload_limit",
|
||||||
|
Default: false,
|
||||||
|
Help: `Make upload limit errors be fatal
|
||||||
|
|
||||||
|
At the time of writing it is only possible to upload 750GB of data to
|
||||||
|
Google Drive a day (this is an undocumented limit). When this limit is
|
||||||
|
reached Google Drive produces a slightly different error message. When
|
||||||
|
this flag is set it causes these errors to be fatal. These will stop
|
||||||
|
the in-progress sync.
|
||||||
|
|
||||||
|
Note that this detection is relying on error message strings which
|
||||||
|
Google don't document so it may break in the future.
|
||||||
|
|
||||||
|
See: https://github.com/rclone/rclone/issues/3857
|
||||||
|
`,
|
||||||
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
// Don't encode / as it's a valid name character in drive.
|
||||||
|
Default: encoder.EncodeInvalidUtf8,
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -458,36 +493,38 @@ See: https://github.com/rclone/rclone/issues/3631
|
|||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Scope string `config:"scope"`
|
Scope string `config:"scope"`
|
||||||
RootFolderID string `config:"root_folder_id"`
|
RootFolderID string `config:"root_folder_id"`
|
||||||
ServiceAccountFile string `config:"service_account_file"`
|
ServiceAccountFile string `config:"service_account_file"`
|
||||||
ServiceAccountCredentials string `config:"service_account_credentials"`
|
ServiceAccountCredentials string `config:"service_account_credentials"`
|
||||||
TeamDriveID string `config:"team_drive"`
|
TeamDriveID string `config:"team_drive"`
|
||||||
AuthOwnerOnly bool `config:"auth_owner_only"`
|
AuthOwnerOnly bool `config:"auth_owner_only"`
|
||||||
UseTrash bool `config:"use_trash"`
|
UseTrash bool `config:"use_trash"`
|
||||||
SkipGdocs bool `config:"skip_gdocs"`
|
SkipGdocs bool `config:"skip_gdocs"`
|
||||||
SkipChecksumGphotos bool `config:"skip_checksum_gphotos"`
|
SkipChecksumGphotos bool `config:"skip_checksum_gphotos"`
|
||||||
SharedWithMe bool `config:"shared_with_me"`
|
SharedWithMe bool `config:"shared_with_me"`
|
||||||
TrashedOnly bool `config:"trashed_only"`
|
TrashedOnly bool `config:"trashed_only"`
|
||||||
Extensions string `config:"formats"`
|
Extensions string `config:"formats"`
|
||||||
ExportExtensions string `config:"export_formats"`
|
ExportExtensions string `config:"export_formats"`
|
||||||
ImportExtensions string `config:"import_formats"`
|
ImportExtensions string `config:"import_formats"`
|
||||||
AllowImportNameChange bool `config:"allow_import_name_change"`
|
AllowImportNameChange bool `config:"allow_import_name_change"`
|
||||||
UseCreatedDate bool `config:"use_created_date"`
|
UseCreatedDate bool `config:"use_created_date"`
|
||||||
UseSharedDate bool `config:"use_shared_date"`
|
UseSharedDate bool `config:"use_shared_date"`
|
||||||
ListChunk int64 `config:"list_chunk"`
|
ListChunk int64 `config:"list_chunk"`
|
||||||
Impersonate string `config:"impersonate"`
|
Impersonate string `config:"impersonate"`
|
||||||
AlternateExport bool `config:"alternate_export"`
|
AlternateExport bool `config:"alternate_export"`
|
||||||
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
AcknowledgeAbuse bool `config:"acknowledge_abuse"`
|
AcknowledgeAbuse bool `config:"acknowledge_abuse"`
|
||||||
KeepRevisionForever bool `config:"keep_revision_forever"`
|
KeepRevisionForever bool `config:"keep_revision_forever"`
|
||||||
SizeAsQuota bool `config:"size_as_quota"`
|
SizeAsQuota bool `config:"size_as_quota"`
|
||||||
V2DownloadMinSize fs.SizeSuffix `config:"v2_download_min_size"`
|
V2DownloadMinSize fs.SizeSuffix `config:"v2_download_min_size"`
|
||||||
PacerMinSleep fs.Duration `config:"pacer_min_sleep"`
|
PacerMinSleep fs.Duration `config:"pacer_min_sleep"`
|
||||||
PacerBurst int `config:"pacer_burst"`
|
PacerBurst int `config:"pacer_burst"`
|
||||||
ServerSideAcrossConfigs bool `config:"server_side_across_configs"`
|
ServerSideAcrossConfigs bool `config:"server_side_across_configs"`
|
||||||
DisableHTTP2 bool `config:"disable_http2"`
|
DisableHTTP2 bool `config:"disable_http2"`
|
||||||
|
StopOnUploadLimit bool `config:"stop_on_upload_limit"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote drive server
|
// Fs represents a remote drive server
|
||||||
@@ -558,7 +595,7 @@ func (f *Fs) Features() *fs.Features {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// shouldRetry determines whether a given err rates being retried
|
// shouldRetry determines whether a given err rates being retried
|
||||||
func shouldRetry(err error) (bool, error) {
|
func (f *Fs) shouldRetry(err error) (bool, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
@@ -574,6 +611,10 @@ func shouldRetry(err error) (bool, error) {
|
|||||||
if len(gerr.Errors) > 0 {
|
if len(gerr.Errors) > 0 {
|
||||||
reason := gerr.Errors[0].Reason
|
reason := gerr.Errors[0].Reason
|
||||||
if reason == "rateLimitExceeded" || reason == "userRateLimitExceeded" {
|
if reason == "rateLimitExceeded" || reason == "userRateLimitExceeded" {
|
||||||
|
if f.opt.StopOnUploadLimit && gerr.Errors[0].Message == "User rate limit exceeded." {
|
||||||
|
fs.Errorf(f, "Received upload limit error: %v", err)
|
||||||
|
return false, fserrors.FatalError(err)
|
||||||
|
}
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -610,7 +651,7 @@ func (f *Fs) getRootID() (string, error) {
|
|||||||
Fields("id").
|
Fields("id").
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "couldn't find root directory ID")
|
return "", errors.Wrap(err, "couldn't find root directory ID")
|
||||||
@@ -655,7 +696,7 @@ func (f *Fs) list(ctx context.Context, dirIDs []string, title string, directorie
|
|||||||
}
|
}
|
||||||
var stems []string
|
var stems []string
|
||||||
if title != "" {
|
if title != "" {
|
||||||
searchTitle := enc.FromStandardName(title)
|
searchTitle := f.opt.Enc.FromStandardName(title)
|
||||||
// Escaping the backslash isn't documented but seems to work
|
// Escaping the backslash isn't documented but seems to work
|
||||||
searchTitle = strings.Replace(searchTitle, `\`, `\\`, -1)
|
searchTitle = strings.Replace(searchTitle, `\`, `\\`, -1)
|
||||||
searchTitle = strings.Replace(searchTitle, `'`, `\'`, -1)
|
searchTitle = strings.Replace(searchTitle, `'`, `\'`, -1)
|
||||||
@@ -716,20 +757,23 @@ func (f *Fs) list(ctx context.Context, dirIDs []string, title string, directorie
|
|||||||
fields += ",quotaBytesUsed"
|
fields += ",quotaBytesUsed"
|
||||||
}
|
}
|
||||||
|
|
||||||
fields = fmt.Sprintf("files(%s),nextPageToken", fields)
|
fields = fmt.Sprintf("files(%s),nextPageToken,incompleteSearch", fields)
|
||||||
|
|
||||||
OUTER:
|
OUTER:
|
||||||
for {
|
for {
|
||||||
var files *drive.FileList
|
var files *drive.FileList
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
files, err = list.Fields(googleapi.Field(fields)).Context(ctx).Do()
|
files, err = list.Fields(googleapi.Field(fields)).Context(ctx).Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "couldn't list directory")
|
return false, errors.Wrap(err, "couldn't list directory")
|
||||||
}
|
}
|
||||||
|
if files.IncompleteSearch {
|
||||||
|
fs.Errorf(f, "search result INCOMPLETE")
|
||||||
|
}
|
||||||
for _, item := range files.Files {
|
for _, item := range files.Files {
|
||||||
item.Name = enc.ToStandardName(item.Name)
|
item.Name = f.opt.Enc.ToStandardName(item.Name)
|
||||||
// Check the case of items is correct since
|
// Check the case of items is correct since
|
||||||
// the `=` operator is case insensitive.
|
// the `=` operator is case insensitive.
|
||||||
if title != "" && title != item.Name {
|
if title != "" && title != item.Name {
|
||||||
@@ -860,11 +904,12 @@ func configTeamDrive(ctx context.Context, opt *Options, m configmap.Mapper, name
|
|||||||
var driveIDs, driveNames []string
|
var driveIDs, driveNames []string
|
||||||
listTeamDrives := svc.Teamdrives.List().PageSize(100)
|
listTeamDrives := svc.Teamdrives.List().PageSize(100)
|
||||||
listFailed := false
|
listFailed := false
|
||||||
|
var defaultFs Fs // default Fs with default Options
|
||||||
for {
|
for {
|
||||||
var teamDrives *drive.TeamDriveList
|
var teamDrives *drive.TeamDriveList
|
||||||
err = newPacer(opt).Call(func() (bool, error) {
|
err = newPacer(opt).Call(func() (bool, error) {
|
||||||
teamDrives, err = listTeamDrives.Context(ctx).Do()
|
teamDrives, err = listTeamDrives.Context(ctx).Do()
|
||||||
return shouldRetry(err)
|
return defaultFs.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Listing team drives failed: %v\n", err)
|
fmt.Printf("Listing team drives failed: %v\n", err)
|
||||||
@@ -1290,7 +1335,7 @@ func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut strin
|
|||||||
|
|
||||||
// CreateDir makes a directory with pathID as parent and name leaf
|
// CreateDir makes a directory with pathID as parent and name leaf
|
||||||
func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string, err error) {
|
func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string, err error) {
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = f.opt.Enc.FromStandardName(leaf)
|
||||||
// fmt.Println("Making", path)
|
// fmt.Println("Making", path)
|
||||||
// Define the metadata for the directory we are going to create.
|
// Define the metadata for the directory we are going to create.
|
||||||
createInfo := &drive.File{
|
createInfo := &drive.File{
|
||||||
@@ -1305,7 +1350,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
Fields("id").
|
Fields("id").
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -1348,7 +1393,7 @@ func (f *Fs) fetchFormats() {
|
|||||||
about, err = f.svc.About.Get().
|
about, err = f.svc.About.Get().
|
||||||
Fields("exportFormats,importFormats").
|
Fields("exportFormats,importFormats").
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Errorf(f, "Failed to get Drive exportFormats and importFormats: %v", err)
|
fs.Errorf(f, "Failed to get Drive exportFormats and importFormats: %v", err)
|
||||||
@@ -1748,7 +1793,7 @@ func (f *Fs) createFileInfo(ctx context.Context, remote string, modTime time.Tim
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = f.opt.Enc.FromStandardName(leaf)
|
||||||
// Define the metadata for the file we are going to create.
|
// Define the metadata for the file we are going to create.
|
||||||
createInfo := &drive.File{
|
createInfo := &drive.File{
|
||||||
Name: leaf,
|
Name: leaf,
|
||||||
@@ -1822,7 +1867,7 @@ func (f *Fs) PutUnchecked(ctx context.Context, in io.Reader, src fs.ObjectInfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var info *drive.File
|
var info *drive.File
|
||||||
if size == 0 || size < int64(f.opt.UploadCutoff) {
|
if size >= 0 && size < int64(f.opt.UploadCutoff) {
|
||||||
// Make the API request to upload metadata and file data.
|
// Make the API request to upload metadata and file data.
|
||||||
// Don't retry, return a retry error instead
|
// Don't retry, return a retry error instead
|
||||||
err = f.pacer.CallNoRetry(func() (bool, error) {
|
err = f.pacer.CallNoRetry(func() (bool, error) {
|
||||||
@@ -1832,7 +1877,7 @@ func (f *Fs) PutUnchecked(ctx context.Context, in io.Reader, src fs.ObjectInfo,
|
|||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
KeepRevisionForever(f.opt.KeepRevisionForever).
|
KeepRevisionForever(f.opt.KeepRevisionForever).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1875,7 +1920,7 @@ func (f *Fs) MergeDirs(ctx context.Context, dirs []fs.Directory) error {
|
|||||||
Fields("").
|
Fields("").
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "MergeDirs move failed on %q in %v", info.Name, srcDir)
|
return errors.Wrapf(err, "MergeDirs move failed on %q in %v", info.Name, srcDir)
|
||||||
@@ -1921,7 +1966,7 @@ func (f *Fs) rmdir(ctx context.Context, directoryID string, useTrash bool) error
|
|||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
}
|
}
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2019,7 +2064,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
KeepRevisionForever(f.opt.KeepRevisionForever).
|
KeepRevisionForever(f.opt.KeepRevisionForever).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -2068,7 +2113,7 @@ func (f *Fs) Purge(ctx context.Context) error {
|
|||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
}
|
}
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
f.dirCache.ResetRoot()
|
f.dirCache.ResetRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2081,7 +2126,7 @@ func (f *Fs) Purge(ctx context.Context) error {
|
|||||||
func (f *Fs) CleanUp(ctx context.Context) error {
|
func (f *Fs) CleanUp(ctx context.Context) error {
|
||||||
err := f.pacer.Call(func() (bool, error) {
|
err := f.pacer.Call(func() (bool, error) {
|
||||||
err := f.svc.Files.EmptyTrash().Context(ctx).Do()
|
err := f.svc.Files.EmptyTrash().Context(ctx).Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2098,7 +2143,7 @@ func (f *Fs) teamDriveOK(ctx context.Context) (err error) {
|
|||||||
var td *drive.Drive
|
var td *drive.Drive
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
td, err = f.svc.Drives.Get(f.opt.TeamDriveID).Fields("name,id,capabilities,createdTime,restrictions").Context(ctx).Do()
|
td, err = f.svc.Drives.Get(f.opt.TeamDriveID).Fields("name,id,capabilities,createdTime,restrictions").Context(ctx).Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to get Team/Shared Drive info")
|
return errors.Wrap(err, "failed to get Team/Shared Drive info")
|
||||||
@@ -2121,7 +2166,7 @@ func (f *Fs) About(ctx context.Context) (*fs.Usage, error) {
|
|||||||
var err error
|
var err error
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
about, err = f.svc.About.Get().Fields("storageQuota").Context(ctx).Do()
|
about, err = f.svc.About.Get().Fields("storageQuota").Context(ctx).Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to get Drive storageQuota")
|
return nil, errors.Wrap(err, "failed to get Drive storageQuota")
|
||||||
@@ -2193,7 +2238,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
Fields(partialFields).
|
Fields(partialFields).
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -2229,7 +2274,7 @@ func (f *Fs) PublicLink(ctx context.Context, remote string) (link string, err er
|
|||||||
Fields("").
|
Fields("").
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -2329,7 +2374,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
Fields("").
|
Fields("").
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -2395,7 +2440,7 @@ func (f *Fs) changeNotifyStartPageToken() (pageToken string, err error) {
|
|||||||
changes.DriveId(f.opt.TeamDriveID)
|
changes.DriveId(f.opt.TeamDriveID)
|
||||||
}
|
}
|
||||||
startPageToken, err = changes.Do()
|
startPageToken, err = changes.Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -2424,7 +2469,7 @@ func (f *Fs) changeNotifyRunner(ctx context.Context, notifyFunc func(string, fs.
|
|||||||
changesCall.Spaces("appDataFolder")
|
changesCall.Spaces("appDataFolder")
|
||||||
}
|
}
|
||||||
changeList, err = changesCall.Context(ctx).Do()
|
changeList, err = changesCall.Context(ctx).Do()
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -2447,7 +2492,7 @@ func (f *Fs) changeNotifyRunner(ctx context.Context, notifyFunc func(string, fs.
|
|||||||
|
|
||||||
// find the new path
|
// find the new path
|
||||||
if change.File != nil {
|
if change.File != nil {
|
||||||
change.File.Name = enc.ToStandardName(change.File.Name)
|
change.File.Name = f.opt.Enc.ToStandardName(change.File.Name)
|
||||||
changeType := fs.EntryDirectory
|
changeType := fs.EntryDirectory
|
||||||
if change.File.MimeType != driveFolderType {
|
if change.File.MimeType != driveFolderType {
|
||||||
changeType = fs.EntryObject
|
changeType = fs.EntryObject
|
||||||
@@ -2615,7 +2660,7 @@ func (o *baseObject) SetModTime(ctx context.Context, modTime time.Time) error {
|
|||||||
Fields(partialFields).
|
Fields(partialFields).
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return o.fs.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -2654,7 +2699,7 @@ func (o *baseObject) httpResponse(ctx context.Context, url, method string, optio
|
|||||||
_ = res.Body.Close() // ignore error
|
_ = res.Body.Close() // ignore error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shouldRetry(err)
|
return o.fs.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return req, nil, err
|
return req, nil, err
|
||||||
@@ -2744,7 +2789,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
|||||||
Fields("downloadUrl").
|
Fields("downloadUrl").
|
||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return o.fs.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fs.Debugf(o, "Using v2 download: %v", v2File.DownloadUrl)
|
fs.Debugf(o, "Using v2 download: %v", v2File.DownloadUrl)
|
||||||
@@ -2816,7 +2861,7 @@ func (o *baseObject) update(ctx context.Context, updateInfo *drive.File, uploadM
|
|||||||
src fs.ObjectInfo) (info *drive.File, err error) {
|
src fs.ObjectInfo) (info *drive.File, err error) {
|
||||||
// Make the API request to upload metadata and file data.
|
// Make the API request to upload metadata and file data.
|
||||||
size := src.Size()
|
size := src.Size()
|
||||||
if size == 0 || size < int64(o.fs.opt.UploadCutoff) {
|
if size >= 0 && size < int64(o.fs.opt.UploadCutoff) {
|
||||||
// Don't retry, return a retry error instead
|
// Don't retry, return a retry error instead
|
||||||
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
||||||
info, err = o.fs.svc.Files.Update(o.id, updateInfo).
|
info, err = o.fs.svc.Files.Update(o.id, updateInfo).
|
||||||
@@ -2825,7 +2870,7 @@ func (o *baseObject) update(ctx context.Context, updateInfo *drive.File, uploadM
|
|||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
KeepRevisionForever(o.fs.opt.KeepRevisionForever).
|
KeepRevisionForever(o.fs.opt.KeepRevisionForever).
|
||||||
Do()
|
Do()
|
||||||
return shouldRetry(err)
|
return o.fs.shouldRetry(err)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -2925,7 +2970,7 @@ func (o *baseObject) Remove(ctx context.Context) error {
|
|||||||
SupportsAllDrives(true).
|
SupportsAllDrives(true).
|
||||||
Do()
|
Do()
|
||||||
}
|
}
|
||||||
return shouldRetry(err)
|
return o.fs.shouldRetry(err)
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+39
-46
@@ -11,16 +11,15 @@
|
|||||||
package drive
|
package drive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
@@ -88,13 +87,15 @@ func (f *Fs) Upload(ctx context.Context, in io.Reader, size int64, contentType,
|
|||||||
})
|
})
|
||||||
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
|
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
req.Header.Set("X-Upload-Content-Type", contentType)
|
req.Header.Set("X-Upload-Content-Type", contentType)
|
||||||
req.Header.Set("X-Upload-Content-Length", fmt.Sprintf("%v", size))
|
if size >= 0 {
|
||||||
|
req.Header.Set("X-Upload-Content-Length", fmt.Sprintf("%v", size))
|
||||||
|
}
|
||||||
res, err = f.client.Do(req)
|
res, err = f.client.Do(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer googleapi.CloseBody(res)
|
defer googleapi.CloseBody(res)
|
||||||
err = googleapi.CheckResponse(res)
|
err = googleapi.CheckResponse(res)
|
||||||
}
|
}
|
||||||
return shouldRetry(err)
|
return f.shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -116,49 +117,19 @@ func (rx *resumableUpload) makeRequest(ctx context.Context, start int64, body io
|
|||||||
req, _ := http.NewRequest("POST", rx.URI, body)
|
req, _ := http.NewRequest("POST", rx.URI, body)
|
||||||
req = req.WithContext(ctx) // go1.13 can use NewRequestWithContext
|
req = req.WithContext(ctx) // go1.13 can use NewRequestWithContext
|
||||||
req.ContentLength = reqSize
|
req.ContentLength = reqSize
|
||||||
|
totalSize := "*"
|
||||||
|
if rx.ContentLength >= 0 {
|
||||||
|
totalSize = strconv.FormatInt(rx.ContentLength, 10)
|
||||||
|
}
|
||||||
if reqSize != 0 {
|
if reqSize != 0 {
|
||||||
req.Header.Set("Content-Range", fmt.Sprintf("bytes %v-%v/%v", start, start+reqSize-1, rx.ContentLength))
|
req.Header.Set("Content-Range", fmt.Sprintf("bytes %v-%v/%v", start, start+reqSize-1, totalSize))
|
||||||
} else {
|
} else {
|
||||||
req.Header.Set("Content-Range", fmt.Sprintf("bytes */%v", rx.ContentLength))
|
req.Header.Set("Content-Range", fmt.Sprintf("bytes */%v", totalSize))
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", rx.MediaType)
|
req.Header.Set("Content-Type", rx.MediaType)
|
||||||
return req
|
return req
|
||||||
}
|
}
|
||||||
|
|
||||||
// rangeRE matches the transfer status response from the server. $1 is
|
|
||||||
// the last byte index uploaded.
|
|
||||||
var rangeRE = regexp.MustCompile(`^0\-(\d+)$`)
|
|
||||||
|
|
||||||
// Query drive for the amount transferred so far
|
|
||||||
//
|
|
||||||
// If error is nil, then start should be valid
|
|
||||||
func (rx *resumableUpload) transferStatus(ctx context.Context) (start int64, err error) {
|
|
||||||
req := rx.makeRequest(ctx, 0, nil, 0)
|
|
||||||
res, err := rx.f.client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
defer googleapi.CloseBody(res)
|
|
||||||
if res.StatusCode == http.StatusCreated || res.StatusCode == http.StatusOK {
|
|
||||||
return rx.ContentLength, nil
|
|
||||||
}
|
|
||||||
if res.StatusCode != statusResumeIncomplete {
|
|
||||||
err = googleapi.CheckResponse(res)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return 0, errors.Errorf("unexpected http return code %v", res.StatusCode)
|
|
||||||
}
|
|
||||||
Range := res.Header.Get("Range")
|
|
||||||
if m := rangeRE.FindStringSubmatch(Range); len(m) == 2 {
|
|
||||||
start, err = strconv.ParseInt(m[1], 10, 64)
|
|
||||||
if err == nil {
|
|
||||||
return start, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0, errors.Errorf("unable to parse range %q", Range)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transfer a chunk - caller must call googleapi.CloseBody(res) if err == nil || res != nil
|
// Transfer a chunk - caller must call googleapi.CloseBody(res) if err == nil || res != nil
|
||||||
func (rx *resumableUpload) transferChunk(ctx context.Context, start int64, chunk io.ReadSeeker, chunkSize int64) (int, error) {
|
func (rx *resumableUpload) transferChunk(ctx context.Context, start int64, chunk io.ReadSeeker, chunkSize int64) (int, error) {
|
||||||
_, _ = chunk.Seek(0, io.SeekStart)
|
_, _ = chunk.Seek(0, io.SeekStart)
|
||||||
@@ -200,18 +171,40 @@ func (rx *resumableUpload) Upload(ctx context.Context) (*drive.File, error) {
|
|||||||
var StatusCode int
|
var StatusCode int
|
||||||
var err error
|
var err error
|
||||||
buf := make([]byte, int(rx.f.opt.ChunkSize))
|
buf := make([]byte, int(rx.f.opt.ChunkSize))
|
||||||
for start < rx.ContentLength {
|
for finished := false; !finished; {
|
||||||
reqSize := rx.ContentLength - start
|
var reqSize int64
|
||||||
if reqSize >= int64(rx.f.opt.ChunkSize) {
|
var chunk io.ReadSeeker
|
||||||
reqSize = int64(rx.f.opt.ChunkSize)
|
if rx.ContentLength >= 0 {
|
||||||
|
// If size known use repeatable reader for smoother bwlimit
|
||||||
|
if start >= rx.ContentLength {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
reqSize = rx.ContentLength - start
|
||||||
|
if reqSize >= int64(rx.f.opt.ChunkSize) {
|
||||||
|
reqSize = int64(rx.f.opt.ChunkSize)
|
||||||
|
}
|
||||||
|
chunk = readers.NewRepeatableLimitReaderBuffer(rx.Media, buf, reqSize)
|
||||||
|
} else {
|
||||||
|
// If size unknown read into buffer
|
||||||
|
var n int
|
||||||
|
n, err = readers.ReadFill(rx.Media, buf)
|
||||||
|
if err == io.EOF {
|
||||||
|
// Send the last chunk with the correct ContentLength
|
||||||
|
// otherwise Google doesn't know we've finished
|
||||||
|
rx.ContentLength = start + int64(n)
|
||||||
|
finished = true
|
||||||
|
} else if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
reqSize = int64(n)
|
||||||
|
chunk = bytes.NewReader(buf[:reqSize])
|
||||||
}
|
}
|
||||||
chunk := readers.NewRepeatableLimitReaderBuffer(rx.Media, buf, reqSize)
|
|
||||||
|
|
||||||
// Transfer the chunk
|
// Transfer the chunk
|
||||||
err = rx.f.pacer.Call(func() (bool, error) {
|
err = rx.f.pacer.Call(func() (bool, error) {
|
||||||
fs.Debugf(rx.remote, "Sending chunk %d length %d", start, reqSize)
|
fs.Debugf(rx.remote, "Sending chunk %d length %d", start, reqSize)
|
||||||
StatusCode, err = rx.transferChunk(ctx, start, chunk, reqSize)
|
StatusCode, err = rx.transferChunk(ctx, start, chunk, reqSize)
|
||||||
again, err := shouldRetry(err)
|
again, err := rx.f.shouldRetry(err)
|
||||||
if StatusCode == statusResumeIncomplete || StatusCode == http.StatusCreated || StatusCode == http.StatusOK {
|
if StatusCode == statusResumeIncomplete || StatusCode == http.StatusCreated || StatusCode == http.StatusOK {
|
||||||
again = false
|
again = false
|
||||||
err = nil
|
err = nil
|
||||||
|
|||||||
+40
-21
@@ -45,17 +45,15 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Dropbox
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "5jcck7diasz0rqy"
|
rcloneClientID = "5jcck7diasz0rqy"
|
||||||
@@ -147,14 +145,28 @@ memory. It can be set smaller if you are tight on memory.`, maxChunkSize),
|
|||||||
Help: "Impersonate this user when using a business account.",
|
Help: "Impersonate this user when using a business account.",
|
||||||
Default: "",
|
Default: "",
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// 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.
|
||||||
|
Default: (encoder.Base |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeDel |
|
||||||
|
encoder.EncodeRightSpace |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
Impersonate string `config:"impersonate"`
|
Impersonate string `config:"impersonate"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote dropbox server
|
// Fs represents a remote dropbox server
|
||||||
@@ -381,7 +393,7 @@ func (f *Fs) setRoot(root string) {
|
|||||||
func (f *Fs) getMetadata(objPath string) (entry files.IsMetadata, notFound bool, err error) {
|
func (f *Fs) getMetadata(objPath string) (entry files.IsMetadata, notFound bool, err error) {
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
entry, err = f.srv.GetMetadata(&files.GetMetadataArg{
|
entry, err = f.srv.GetMetadata(&files.GetMetadataArg{
|
||||||
Path: enc.FromStandardPath(objPath),
|
Path: f.opt.Enc.FromStandardPath(objPath),
|
||||||
})
|
})
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
@@ -475,7 +487,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
for {
|
for {
|
||||||
if !started {
|
if !started {
|
||||||
arg := files.ListFolderArg{
|
arg := files.ListFolderArg{
|
||||||
Path: enc.FromStandardPath(root),
|
Path: f.opt.Enc.FromStandardPath(root),
|
||||||
Recursive: false,
|
Recursive: false,
|
||||||
}
|
}
|
||||||
if root == "/" {
|
if root == "/" {
|
||||||
@@ -525,7 +537,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
|
|
||||||
// Only the last element is reliably cased in PathDisplay
|
// Only the last element is reliably cased in PathDisplay
|
||||||
entryPath := metadata.PathDisplay
|
entryPath := metadata.PathDisplay
|
||||||
leaf := enc.ToStandardName(path.Base(entryPath))
|
leaf := f.opt.Enc.ToStandardName(path.Base(entryPath))
|
||||||
remote := path.Join(dir, leaf)
|
remote := path.Join(dir, leaf)
|
||||||
if folderInfo != nil {
|
if folderInfo != nil {
|
||||||
d := fs.NewDir(remote, time.Now())
|
d := fs.NewDir(remote, time.Now())
|
||||||
@@ -583,7 +595,7 @@ func (f *Fs) Mkdir(ctx context.Context, dir string) error {
|
|||||||
|
|
||||||
// create it
|
// create it
|
||||||
arg2 := files.CreateFolderArg{
|
arg2 := files.CreateFolderArg{
|
||||||
Path: enc.FromStandardPath(root),
|
Path: f.opt.Enc.FromStandardPath(root),
|
||||||
}
|
}
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
_, err = f.srv.CreateFolderV2(&arg2)
|
_, err = f.srv.CreateFolderV2(&arg2)
|
||||||
@@ -609,7 +621,7 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error {
|
|||||||
return errors.Wrap(err, "Rmdir")
|
return errors.Wrap(err, "Rmdir")
|
||||||
}
|
}
|
||||||
|
|
||||||
root = enc.FromStandardPath(root)
|
root = f.opt.Enc.FromStandardPath(root)
|
||||||
// check directory empty
|
// check directory empty
|
||||||
arg := files.ListFolderArg{
|
arg := files.ListFolderArg{
|
||||||
Path: root,
|
Path: root,
|
||||||
@@ -668,8 +680,8 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
// Copy
|
// Copy
|
||||||
arg := files.RelocationArg{
|
arg := files.RelocationArg{
|
||||||
RelocationPath: files.RelocationPath{
|
RelocationPath: files.RelocationPath{
|
||||||
FromPath: enc.FromStandardPath(srcObj.remotePath()),
|
FromPath: f.opt.Enc.FromStandardPath(srcObj.remotePath()),
|
||||||
ToPath: enc.FromStandardPath(dstObj.remotePath()),
|
ToPath: f.opt.Enc.FromStandardPath(dstObj.remotePath()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
@@ -704,7 +716,7 @@ func (f *Fs) Purge(ctx context.Context) (err error) {
|
|||||||
// Let dropbox delete the filesystem tree
|
// Let dropbox delete the filesystem tree
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
_, err = f.srv.DeleteV2(&files.DeleteArg{
|
_, err = f.srv.DeleteV2(&files.DeleteArg{
|
||||||
Path: enc.FromStandardPath(f.slashRoot),
|
Path: f.opt.Enc.FromStandardPath(f.slashRoot),
|
||||||
})
|
})
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
@@ -736,8 +748,8 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
// Do the move
|
// Do the move
|
||||||
arg := files.RelocationArg{
|
arg := files.RelocationArg{
|
||||||
RelocationPath: files.RelocationPath{
|
RelocationPath: files.RelocationPath{
|
||||||
FromPath: enc.FromStandardPath(srcObj.remotePath()),
|
FromPath: f.opt.Enc.FromStandardPath(srcObj.remotePath()),
|
||||||
ToPath: enc.FromStandardPath(dstObj.remotePath()),
|
ToPath: f.opt.Enc.FromStandardPath(dstObj.remotePath()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
@@ -764,7 +776,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
|
|
||||||
// PublicLink adds a "readable by anyone with link" permission on the given file or folder.
|
// PublicLink adds a "readable by anyone with link" permission on the given file or folder.
|
||||||
func (f *Fs) PublicLink(ctx context.Context, remote string) (link string, err error) {
|
func (f *Fs) PublicLink(ctx context.Context, remote string) (link string, err error) {
|
||||||
absPath := enc.FromStandardPath(path.Join(f.slashRoot, remote))
|
absPath := f.opt.Enc.FromStandardPath(path.Join(f.slashRoot, remote))
|
||||||
fs.Debugf(f, "attempting to share '%s' (absolute path: %s)", remote, absPath)
|
fs.Debugf(f, "attempting to share '%s' (absolute path: %s)", remote, absPath)
|
||||||
createArg := sharing.CreateSharedLinkWithSettingsArg{
|
createArg := sharing.CreateSharedLinkWithSettingsArg{
|
||||||
Path: absPath,
|
Path: absPath,
|
||||||
@@ -840,8 +852,8 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
// Do the move
|
// Do the move
|
||||||
arg := files.RelocationArg{
|
arg := files.RelocationArg{
|
||||||
RelocationPath: files.RelocationPath{
|
RelocationPath: files.RelocationPath{
|
||||||
FromPath: enc.FromStandardPath(srcPath),
|
FromPath: f.opt.Enc.FromStandardPath(srcPath),
|
||||||
ToPath: enc.FromStandardPath(dstPath),
|
ToPath: f.opt.Enc.FromStandardPath(dstPath),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@@ -999,7 +1011,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
|||||||
fs.FixRangeOption(options, o.bytes)
|
fs.FixRangeOption(options, o.bytes)
|
||||||
headers := fs.OpenOptionHeaders(options)
|
headers := fs.OpenOptionHeaders(options)
|
||||||
arg := files.DownloadArg{
|
arg := files.DownloadArg{
|
||||||
Path: enc.FromStandardPath(o.remotePath()),
|
Path: o.fs.opt.Enc.FromStandardPath(o.remotePath()),
|
||||||
ExtraHeaders: headers,
|
ExtraHeaders: headers,
|
||||||
}
|
}
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
@@ -1111,6 +1123,13 @@ func (o *Object) uploadChunked(in0 io.Reader, commitInfo *files.CommitInfo, size
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
entry, err = o.fs.srv.UploadSessionFinish(args, chunk)
|
entry, err = o.fs.srv.UploadSessionFinish(args, chunk)
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
// after the first chunk is uploaded, we retry everything
|
// after the first chunk is uploaded, we retry everything
|
||||||
return err != nil, err
|
return err != nil, err
|
||||||
})
|
})
|
||||||
@@ -1130,7 +1149,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
if ignoredFiles.MatchString(remote) {
|
if ignoredFiles.MatchString(remote) {
|
||||||
return fserrors.NoRetryError(errors.Errorf("file name %q is disallowed - not uploading", path.Base(remote)))
|
return fserrors.NoRetryError(errors.Errorf("file name %q is disallowed - not uploading", path.Base(remote)))
|
||||||
}
|
}
|
||||||
commitInfo := files.NewCommitInfo(enc.FromStandardPath(o.remotePath()))
|
commitInfo := files.NewCommitInfo(o.fs.opt.Enc.FromStandardPath(o.remotePath()))
|
||||||
commitInfo.Mode.Tag = "overwrite"
|
commitInfo.Mode.Tag = "overwrite"
|
||||||
// The Dropbox API only accepts timestamps in UTC with second precision.
|
// The Dropbox API only accepts timestamps in UTC with second precision.
|
||||||
commitInfo.ClientModified = src.ModTime(ctx).UTC().Round(time.Second)
|
commitInfo.ClientModified = src.ModTime(ctx).UTC().Round(time.Second)
|
||||||
@@ -1156,7 +1175,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
func (o *Object) Remove(ctx context.Context) (err error) {
|
func (o *Object) Remove(ctx context.Context) (err error) {
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
_, err = o.fs.srv.DeleteV2(&files.DeleteArg{
|
_, err = o.fs.srv.DeleteV2(&files.DeleteArg{
|
||||||
Path: enc.FromStandardPath(o.remotePath()),
|
Path: o.fs.opt.Enc.FromStandardPath(o.remotePath()),
|
||||||
})
|
})
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func (f *Fs) listFiles(ctx context.Context, directoryID int) (filesList *FilesLi
|
|||||||
}
|
}
|
||||||
for i := range filesList.Items {
|
for i := range filesList.Items {
|
||||||
item := &filesList.Items[i]
|
item := &filesList.Items[i]
|
||||||
item.Filename = enc.ToStandardName(item.Filename)
|
item.Filename = f.opt.Enc.ToStandardName(item.Filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
return filesList, nil
|
return filesList, nil
|
||||||
@@ -135,10 +135,10 @@ func (f *Fs) listFolders(ctx context.Context, directoryID int) (foldersList *Fol
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "couldn't list folders")
|
return nil, errors.Wrap(err, "couldn't list folders")
|
||||||
}
|
}
|
||||||
foldersList.Name = enc.ToStandardName(foldersList.Name)
|
foldersList.Name = f.opt.Enc.ToStandardName(foldersList.Name)
|
||||||
for i := range foldersList.SubFolders {
|
for i := range foldersList.SubFolders {
|
||||||
folder := &foldersList.SubFolders[i]
|
folder := &foldersList.SubFolders[i]
|
||||||
folder.Name = enc.ToStandardName(folder.Name)
|
folder.Name = f.opt.Enc.ToStandardName(folder.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fs.Debugf(f, "Got FoldersList for id `%s`", directoryID)
|
// fs.Debugf(f, "Got FoldersList for id `%s`", directoryID)
|
||||||
@@ -213,7 +213,7 @@ func getRemote(dir, fileName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) makeFolder(ctx context.Context, leaf string, folderID int) (response *MakeFolderResponse, err error) {
|
func (f *Fs) makeFolder(ctx context.Context, leaf string, folderID int) (response *MakeFolderResponse, err error) {
|
||||||
name := enc.FromStandardName(leaf)
|
name := f.opt.Enc.FromStandardName(leaf)
|
||||||
// fs.Debugf(f, "Creating folder `%s` in id `%s`", name, directoryID)
|
// fs.Debugf(f, "Creating folder `%s` in id `%s`", name, directoryID)
|
||||||
|
|
||||||
request := MakeFolderRequest{
|
request := MakeFolderRequest{
|
||||||
@@ -323,7 +323,7 @@ func (f *Fs) getUploadNode(ctx context.Context) (response *GetUploadNodeResponse
|
|||||||
func (f *Fs) uploadFile(ctx context.Context, in io.Reader, size int64, fileName, folderID, uploadID, node string) (response *http.Response, err error) {
|
func (f *Fs) uploadFile(ctx context.Context, in io.Reader, size int64, fileName, folderID, uploadID, node string) (response *http.Response, err error) {
|
||||||
// fs.Debugf(f, "Uploading File `%s`", fileName)
|
// fs.Debugf(f, "Uploading File `%s`", fileName)
|
||||||
|
|
||||||
fileName = enc.FromStandardName(fileName)
|
fileName = f.opt.Enc.FromStandardName(fileName)
|
||||||
|
|
||||||
if len(uploadID) > 10 || !isAlphaNumeric(uploadID) {
|
if len(uploadID) > 10 || !isAlphaNumeric(uploadID) {
|
||||||
return nil, errors.New("Invalid UploadID")
|
return nil, errors.New("Invalid UploadID")
|
||||||
|
|||||||
+44
-22
@@ -11,12 +11,13 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
)
|
)
|
||||||
@@ -29,8 +30,6 @@ const (
|
|||||||
decayConstant = 2 // bigger for slower decay, exponential
|
decayConstant = 2 // bigger for slower decay, exponential
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Fichier
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
Name: "fichier",
|
Name: "fichier",
|
||||||
@@ -38,25 +37,48 @@ func init() {
|
|||||||
Config: func(name string, config configmap.Mapper) {
|
Config: func(name string, config configmap.Mapper) {
|
||||||
},
|
},
|
||||||
NewFs: NewFs,
|
NewFs: NewFs,
|
||||||
Options: []fs.Option{
|
Options: []fs.Option{{
|
||||||
{
|
Help: "Your API Key, get it from https://1fichier.com/console/params.pl",
|
||||||
Help: "Your API Key, get it from https://1fichier.com/console/params.pl",
|
Name: "api_key",
|
||||||
Name: "api_key",
|
}, {
|
||||||
},
|
Help: "If you want to download a shared folder, add this parameter",
|
||||||
{
|
Name: "shared_folder",
|
||||||
Help: "If you want to download a shared folder, add this parameter",
|
Required: false,
|
||||||
Name: "shared_folder",
|
Advanced: true,
|
||||||
Required: false,
|
}, {
|
||||||
Advanced: true,
|
Name: config.ConfigEncoding,
|
||||||
},
|
Help: config.ConfigEncodingHelp,
|
||||||
},
|
Advanced: true,
|
||||||
|
// Characters that need escaping
|
||||||
|
//
|
||||||
|
// '\\': '\', // FULLWIDTH REVERSE SOLIDUS
|
||||||
|
// '<': '<', // FULLWIDTH LESS-THAN SIGN
|
||||||
|
// '>': '>', // FULLWIDTH GREATER-THAN SIGN
|
||||||
|
// '"': '"', // FULLWIDTH QUOTATION MARK - not on the list but seems to be reserved
|
||||||
|
// '\'': ''', // FULLWIDTH APOSTROPHE
|
||||||
|
// '$': '$', // FULLWIDTH DOLLAR SIGN
|
||||||
|
// '`': '`', // FULLWIDTH GRAVE ACCENT
|
||||||
|
//
|
||||||
|
// Leading space and trailing space
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeSingleQuote |
|
||||||
|
encoder.EncodeBackQuote |
|
||||||
|
encoder.EncodeDoubleQuote |
|
||||||
|
encoder.EncodeLtGt |
|
||||||
|
encoder.EncodeDollar |
|
||||||
|
encoder.EncodeLeftSpace |
|
||||||
|
encoder.EncodeRightSpace |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
APIKey string `config:"api_key"`
|
APIKey string `config:"api_key"`
|
||||||
SharedFolder string `config:"shared_folder"`
|
SharedFolder string `config:"shared_folder"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs is the interface a cloud storage system must provide
|
// Fs is the interface a cloud storage system must provide
|
||||||
@@ -64,9 +86,9 @@ type Fs struct {
|
|||||||
root string
|
root string
|
||||||
name string
|
name string
|
||||||
features *fs.Features
|
features *fs.Features
|
||||||
|
opt Options
|
||||||
dirCache *dircache.DirCache
|
dirCache *dircache.DirCache
|
||||||
baseClient *http.Client
|
baseClient *http.Client
|
||||||
options *Options
|
|
||||||
pacer *fs.Pacer
|
pacer *fs.Pacer
|
||||||
rest *rest.Client
|
rest *rest.Client
|
||||||
}
|
}
|
||||||
@@ -162,7 +184,7 @@ func NewFs(name string, root string, config configmap.Mapper) (fs.Fs, error) {
|
|||||||
f := &Fs{
|
f := &Fs{
|
||||||
name: name,
|
name: name,
|
||||||
root: root,
|
root: root,
|
||||||
options: opt,
|
opt: *opt,
|
||||||
pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))),
|
pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))),
|
||||||
baseClient: &http.Client{},
|
baseClient: &http.Client{},
|
||||||
}
|
}
|
||||||
@@ -176,7 +198,7 @@ func NewFs(name string, root string, config configmap.Mapper) (fs.Fs, error) {
|
|||||||
|
|
||||||
f.rest = rest.NewClient(client).SetRoot(apiBaseURL)
|
f.rest = rest.NewClient(client).SetRoot(apiBaseURL)
|
||||||
|
|
||||||
f.rest.SetHeader("Authorization", "Bearer "+f.options.APIKey)
|
f.rest.SetHeader("Authorization", "Bearer "+f.opt.APIKey)
|
||||||
|
|
||||||
f.dirCache = dircache.New(root, rootID, f)
|
f.dirCache = dircache.New(root, rootID, f)
|
||||||
|
|
||||||
@@ -226,8 +248,8 @@ func NewFs(name string, root string, config configmap.Mapper) (fs.Fs, error) {
|
|||||||
// This should return ErrDirNotFound if the directory isn't
|
// This should return ErrDirNotFound if the directory isn't
|
||||||
// found.
|
// found.
|
||||||
func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) {
|
func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) {
|
||||||
if f.options.SharedFolder != "" {
|
if f.opt.SharedFolder != "" {
|
||||||
return f.listSharedFiles(ctx, f.options.SharedFolder)
|
return f.listSharedFiles(ctx, f.opt.SharedFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
dirContent, err := f.listDir(ctx, dir)
|
dirContent, err := f.listDir(ctx, dir)
|
||||||
|
|||||||
+95
-73
@@ -14,77 +14,86 @@ import (
|
|||||||
"github.com/jlaffaye/ftp"
|
"github.com/jlaffaye/ftp"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.FTP
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
Name: "ftp",
|
Name: "ftp",
|
||||||
Description: "FTP Connection",
|
Description: "FTP Connection",
|
||||||
NewFs: NewFs,
|
NewFs: NewFs,
|
||||||
Options: []fs.Option{
|
Options: []fs.Option{{
|
||||||
{
|
Name: "host",
|
||||||
Name: "host",
|
Help: "FTP host to connect to",
|
||||||
Help: "FTP host to connect to",
|
Required: true,
|
||||||
Required: true,
|
Examples: []fs.OptionExample{{
|
||||||
Examples: []fs.OptionExample{{
|
Value: "ftp.example.com",
|
||||||
Value: "ftp.example.com",
|
Help: "Connect to ftp.example.com",
|
||||||
Help: "Connect to ftp.example.com",
|
}},
|
||||||
}},
|
}, {
|
||||||
}, {
|
Name: "user",
|
||||||
Name: "user",
|
Help: "FTP username, leave blank for current username, " + os.Getenv("USER"),
|
||||||
Help: "FTP username, leave blank for current username, " + os.Getenv("USER"),
|
}, {
|
||||||
}, {
|
Name: "port",
|
||||||
Name: "port",
|
Help: "FTP port, leave blank to use default (21)",
|
||||||
Help: "FTP port, leave blank to use default (21)",
|
}, {
|
||||||
}, {
|
Name: "pass",
|
||||||
Name: "pass",
|
Help: "FTP password",
|
||||||
Help: "FTP password",
|
IsPassword: true,
|
||||||
IsPassword: true,
|
Required: true,
|
||||||
Required: true,
|
}, {
|
||||||
}, {
|
Name: "tls",
|
||||||
Name: "tls",
|
Help: "Use FTP over TLS (Implicit)",
|
||||||
Help: "Use FTP over TLS (Implicit)",
|
Default: false,
|
||||||
Default: false,
|
}, {
|
||||||
}, {
|
Name: "concurrency",
|
||||||
Name: "concurrency",
|
Help: "Maximum number of FTP simultaneous connections, 0 for unlimited",
|
||||||
Help: "Maximum number of FTP simultaneous connections, 0 for unlimited",
|
Default: 0,
|
||||||
Default: 0,
|
Advanced: true,
|
||||||
Advanced: true,
|
}, {
|
||||||
}, {
|
Name: "no_check_certificate",
|
||||||
Name: "no_check_certificate",
|
Help: "Do not verify the TLS certificate of the server",
|
||||||
Help: "Do not verify the TLS certificate of the server",
|
Default: false,
|
||||||
Default: false,
|
Advanced: true,
|
||||||
Advanced: true,
|
}, {
|
||||||
}, {
|
Name: "disable_epsv",
|
||||||
Name: "disable_epsv",
|
Help: "Disable using EPSV even if server advertises support",
|
||||||
Help: "Disable using EPSV even if server advertises support",
|
Default: false,
|
||||||
Default: false,
|
Advanced: true,
|
||||||
Advanced: true,
|
}, {
|
||||||
},
|
Name: config.ConfigEncoding,
|
||||||
},
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// The FTP protocal can't handle trailing spaces (for instance
|
||||||
|
// pureftpd turns them into _)
|
||||||
|
//
|
||||||
|
// proftpd can't handle '*' in file names
|
||||||
|
// pureftpd can't handle '[', ']' or '*'
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeRightSpace),
|
||||||
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Host string `config:"host"`
|
Host string `config:"host"`
|
||||||
User string `config:"user"`
|
User string `config:"user"`
|
||||||
Pass string `config:"pass"`
|
Pass string `config:"pass"`
|
||||||
Port string `config:"port"`
|
Port string `config:"port"`
|
||||||
TLS bool `config:"tls"`
|
TLS bool `config:"tls"`
|
||||||
Concurrency int `config:"concurrency"`
|
Concurrency int `config:"concurrency"`
|
||||||
SkipVerifyTLSCert bool `config:"no_check_certificate"`
|
SkipVerifyTLSCert bool `config:"no_check_certificate"`
|
||||||
DisableEPSV bool `config:"disable_epsv"`
|
DisableEPSV bool `config:"disable_epsv"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote FTP server
|
// Fs represents a remote FTP server
|
||||||
@@ -181,7 +190,11 @@ func (f *Fs) getFtpConnection() (c *ftp.ServerConn, err error) {
|
|||||||
if c != nil {
|
if c != nil {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
return f.ftpConnection()
|
c, err = f.ftpConnection()
|
||||||
|
if err != nil && f.opt.Concurrency > 0 {
|
||||||
|
f.tokens.Put()
|
||||||
|
}
|
||||||
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an FTP connection to the pool
|
// Return an FTP connection to the pool
|
||||||
@@ -194,7 +207,13 @@ func (f *Fs) putFtpConnection(pc **ftp.ServerConn, err error) {
|
|||||||
if f.opt.Concurrency > 0 {
|
if f.opt.Concurrency > 0 {
|
||||||
defer f.tokens.Put()
|
defer f.tokens.Put()
|
||||||
}
|
}
|
||||||
|
if pc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
c := *pc
|
c := *pc
|
||||||
|
if c == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
*pc = nil
|
*pc = nil
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If not a regular FTP error code then check the connection
|
// If not a regular FTP error code then check the connection
|
||||||
@@ -308,22 +327,22 @@ func translateErrorDir(err error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// entryToStandard converts an incoming ftp.Entry to Standard encoding
|
// entryToStandard converts an incoming ftp.Entry to Standard encoding
|
||||||
func entryToStandard(entry *ftp.Entry) {
|
func (f *Fs) entryToStandard(entry *ftp.Entry) {
|
||||||
// Skip . and .. as we don't want these encoded
|
// Skip . and .. as we don't want these encoded
|
||||||
if entry.Name == "." || entry.Name == ".." {
|
if entry.Name == "." || entry.Name == ".." {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entry.Name = enc.ToStandardName(entry.Name)
|
entry.Name = f.opt.Enc.ToStandardName(entry.Name)
|
||||||
entry.Target = enc.ToStandardPath(entry.Target)
|
entry.Target = f.opt.Enc.ToStandardPath(entry.Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
// dirFromStandardPath returns dir in encoded form.
|
// dirFromStandardPath returns dir in encoded form.
|
||||||
func dirFromStandardPath(dir string) string {
|
func (f *Fs) dirFromStandardPath(dir string) string {
|
||||||
// Skip . and .. as we don't want these encoded
|
// Skip . and .. as we don't want these encoded
|
||||||
if dir == "." || dir == ".." {
|
if dir == "." || dir == ".." {
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
return enc.FromStandardPath(dir)
|
return f.opt.Enc.FromStandardPath(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// findItem finds a directory entry for the name in its parent directory
|
// findItem finds a directory entry for the name in its parent directory
|
||||||
@@ -345,13 +364,13 @@ func (f *Fs) findItem(remote string) (entry *ftp.Entry, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "findItem")
|
return nil, errors.Wrap(err, "findItem")
|
||||||
}
|
}
|
||||||
files, err := c.List(dirFromStandardPath(dir))
|
files, err := c.List(f.dirFromStandardPath(dir))
|
||||||
f.putFtpConnection(&c, err)
|
f.putFtpConnection(&c, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, translateErrorFile(err)
|
return nil, translateErrorFile(err)
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
entryToStandard(file)
|
f.entryToStandard(file)
|
||||||
if file.Name == base {
|
if file.Name == base {
|
||||||
return file, nil
|
return file, nil
|
||||||
}
|
}
|
||||||
@@ -418,7 +437,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
resultchan := make(chan []*ftp.Entry, 1)
|
resultchan := make(chan []*ftp.Entry, 1)
|
||||||
errchan := make(chan error, 1)
|
errchan := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
result, err := c.List(dirFromStandardPath(path.Join(f.root, dir)))
|
result, err := c.List(f.dirFromStandardPath(path.Join(f.root, dir)))
|
||||||
f.putFtpConnection(&c, err)
|
f.putFtpConnection(&c, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errchan <- err
|
errchan <- err
|
||||||
@@ -455,7 +474,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
}
|
}
|
||||||
for i := range files {
|
for i := range files {
|
||||||
object := files[i]
|
object := files[i]
|
||||||
entryToStandard(object)
|
f.entryToStandard(object)
|
||||||
newremote := path.Join(dir, object.Name)
|
newremote := path.Join(dir, object.Name)
|
||||||
switch object.Type {
|
switch object.Type {
|
||||||
case ftp.EntryTypeFolder:
|
case ftp.EntryTypeFolder:
|
||||||
@@ -525,7 +544,7 @@ func (f *Fs) getInfo(remote string) (fi *FileInfo, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "getInfo")
|
return nil, errors.Wrap(err, "getInfo")
|
||||||
}
|
}
|
||||||
files, err := c.List(dirFromStandardPath(dir))
|
files, err := c.List(f.dirFromStandardPath(dir))
|
||||||
f.putFtpConnection(&c, err)
|
f.putFtpConnection(&c, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, translateErrorFile(err)
|
return nil, translateErrorFile(err)
|
||||||
@@ -533,7 +552,7 @@ func (f *Fs) getInfo(remote string) (fi *FileInfo, err error) {
|
|||||||
|
|
||||||
for i := range files {
|
for i := range files {
|
||||||
file := files[i]
|
file := files[i]
|
||||||
entryToStandard(file)
|
f.entryToStandard(file)
|
||||||
if file.Name == base {
|
if file.Name == base {
|
||||||
info := &FileInfo{
|
info := &FileInfo{
|
||||||
Name: remote,
|
Name: remote,
|
||||||
@@ -571,7 +590,7 @@ func (f *Fs) mkdir(abspath string) error {
|
|||||||
if connErr != nil {
|
if connErr != nil {
|
||||||
return errors.Wrap(connErr, "mkdir")
|
return errors.Wrap(connErr, "mkdir")
|
||||||
}
|
}
|
||||||
err = c.MakeDir(dirFromStandardPath(abspath))
|
err = c.MakeDir(f.dirFromStandardPath(abspath))
|
||||||
f.putFtpConnection(&c, err)
|
f.putFtpConnection(&c, err)
|
||||||
switch errX := err.(type) {
|
switch errX := err.(type) {
|
||||||
case *textproto.Error:
|
case *textproto.Error:
|
||||||
@@ -607,7 +626,7 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(translateErrorFile(err), "Rmdir")
|
return errors.Wrap(translateErrorFile(err), "Rmdir")
|
||||||
}
|
}
|
||||||
err = c.RemoveDir(dirFromStandardPath(path.Join(f.root, dir)))
|
err = c.RemoveDir(f.dirFromStandardPath(path.Join(f.root, dir)))
|
||||||
f.putFtpConnection(&c, err)
|
f.putFtpConnection(&c, err)
|
||||||
return translateErrorDir(err)
|
return translateErrorDir(err)
|
||||||
}
|
}
|
||||||
@@ -628,8 +647,8 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
return nil, errors.Wrap(err, "Move")
|
return nil, errors.Wrap(err, "Move")
|
||||||
}
|
}
|
||||||
err = c.Rename(
|
err = c.Rename(
|
||||||
enc.FromStandardPath(path.Join(srcObj.fs.root, srcObj.remote)),
|
f.opt.Enc.FromStandardPath(path.Join(srcObj.fs.root, srcObj.remote)),
|
||||||
enc.FromStandardPath(path.Join(f.root, remote)),
|
f.opt.Enc.FromStandardPath(path.Join(f.root, remote)),
|
||||||
)
|
)
|
||||||
f.putFtpConnection(&c, err)
|
f.putFtpConnection(&c, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -682,8 +701,8 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
return errors.Wrap(err, "DirMove")
|
return errors.Wrap(err, "DirMove")
|
||||||
}
|
}
|
||||||
err = c.Rename(
|
err = c.Rename(
|
||||||
dirFromStandardPath(srcPath),
|
f.dirFromStandardPath(srcPath),
|
||||||
dirFromStandardPath(dstPath),
|
f.dirFromStandardPath(dstPath),
|
||||||
)
|
)
|
||||||
f.putFtpConnection(&c, err)
|
f.putFtpConnection(&c, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -769,11 +788,13 @@ func (f *ftpReadCloser) Close() error {
|
|||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
// if timer fired assume no error but connection dead
|
// if timer fired assume no error but connection dead
|
||||||
fs.Errorf(f.f, "Timeout when waiting for connection Close")
|
fs.Errorf(f.f, "Timeout when waiting for connection Close")
|
||||||
|
f.f.putFtpConnection(nil, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// if errors while reading or closing, dump the connection
|
// if errors while reading or closing, dump the connection
|
||||||
if err != nil || f.err != nil {
|
if err != nil || f.err != nil {
|
||||||
_ = f.c.Quit()
|
_ = f.c.Quit()
|
||||||
|
f.f.putFtpConnection(nil, nil)
|
||||||
} else {
|
} else {
|
||||||
f.f.putFtpConnection(&f.c, nil)
|
f.f.putFtpConnection(&f.c, nil)
|
||||||
}
|
}
|
||||||
@@ -809,7 +830,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (rc io.Read
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "open")
|
return nil, errors.Wrap(err, "open")
|
||||||
}
|
}
|
||||||
fd, err := c.RetrFrom(enc.FromStandardPath(path), uint64(offset))
|
fd, err := c.RetrFrom(o.fs.opt.Enc.FromStandardPath(path), uint64(offset))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
o.fs.putFtpConnection(&c, err)
|
o.fs.putFtpConnection(&c, err)
|
||||||
return nil, errors.Wrap(err, "open")
|
return nil, errors.Wrap(err, "open")
|
||||||
@@ -844,10 +865,11 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Update")
|
return errors.Wrap(err, "Update")
|
||||||
}
|
}
|
||||||
err = c.Stor(enc.FromStandardPath(path), in)
|
err = c.Stor(o.fs.opt.Enc.FromStandardPath(path), in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = c.Quit() // toss this connection to avoid sync errors
|
_ = c.Quit() // toss this connection to avoid sync errors
|
||||||
remove()
|
remove()
|
||||||
|
o.fs.putFtpConnection(nil, err)
|
||||||
return errors.Wrap(err, "update stor")
|
return errors.Wrap(err, "update stor")
|
||||||
}
|
}
|
||||||
o.fs.putFtpConnection(&c, nil)
|
o.fs.putFtpConnection(&c, nil)
|
||||||
@@ -874,7 +896,7 @@ func (o *Object) Remove(ctx context.Context) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Remove")
|
return errors.Wrap(err, "Remove")
|
||||||
}
|
}
|
||||||
err = c.Delete(enc.FromStandardPath(path))
|
err = c.Delete(o.fs.opt.Enc.FromStandardPath(path))
|
||||||
o.fs.putFtpConnection(&c, err)
|
o.fs.putFtpConnection(&c, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
+32
-1
@@ -5,13 +5,44 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rclone/rclone/backend/ftp"
|
"github.com/rclone/rclone/backend/ftp"
|
||||||
|
"github.com/rclone/rclone/fstest"
|
||||||
"github.com/rclone/rclone/fstest/fstests"
|
"github.com/rclone/rclone/fstest/fstests"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestIntegration runs integration tests against the remote
|
// TestIntegration runs integration tests against the remote
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
fstests.Run(t, &fstests.Opt{
|
fstests.Run(t, &fstests.Opt{
|
||||||
RemoteName: "TestFTP:",
|
RemoteName: "TestFTPProftpd:",
|
||||||
NilObject: (*ftp.Object)(nil),
|
NilObject: (*ftp.Object)(nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIntegration2(t *testing.T) {
|
||||||
|
if *fstest.RemoteName != "" {
|
||||||
|
t.Skip("skipping as -remote is set")
|
||||||
|
}
|
||||||
|
fstests.Run(t, &fstests.Opt{
|
||||||
|
RemoteName: "TestFTPRclone:",
|
||||||
|
NilObject: (*ftp.Object)(nil),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIntegration3(t *testing.T) {
|
||||||
|
if *fstest.RemoteName != "" {
|
||||||
|
t.Skip("skipping as -remote is set")
|
||||||
|
}
|
||||||
|
fstests.Run(t, &fstests.Opt{
|
||||||
|
RemoteName: "TestFTPPureftpd:",
|
||||||
|
NilObject: (*ftp.Object)(nil),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// func TestIntegration4(t *testing.T) {
|
||||||
|
// if *fstest.RemoteName != "" {
|
||||||
|
// t.Skip("skipping as -remote is set")
|
||||||
|
// }
|
||||||
|
// fstests.Run(t, &fstests.Opt{
|
||||||
|
// RemoteName: "TestFTPVsftpd:",
|
||||||
|
// NilObject: (*ftp.Object)(nil),
|
||||||
|
// })
|
||||||
|
// }
|
||||||
@@ -32,12 +32,12 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
"github.com/rclone/rclone/lib/bucket"
|
"github.com/rclone/rclone/lib/bucket"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@@ -69,8 +69,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.GoogleCloudStorage
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
@@ -248,20 +246,28 @@ Docs: https://cloud.google.com/storage/docs/bucket-policy-only
|
|||||||
Value: "DURABLE_REDUCED_AVAILABILITY",
|
Value: "DURABLE_REDUCED_AVAILABILITY",
|
||||||
Help: "Durable reduced availability storage class",
|
Help: "Durable reduced availability storage class",
|
||||||
}},
|
}},
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
Default: (encoder.Base |
|
||||||
|
encoder.EncodeCrLf |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
ProjectNumber string `config:"project_number"`
|
ProjectNumber string `config:"project_number"`
|
||||||
ServiceAccountFile string `config:"service_account_file"`
|
ServiceAccountFile string `config:"service_account_file"`
|
||||||
ServiceAccountCredentials string `config:"service_account_credentials"`
|
ServiceAccountCredentials string `config:"service_account_credentials"`
|
||||||
ObjectACL string `config:"object_acl"`
|
ObjectACL string `config:"object_acl"`
|
||||||
BucketACL string `config:"bucket_acl"`
|
BucketACL string `config:"bucket_acl"`
|
||||||
BucketPolicyOnly bool `config:"bucket_policy_only"`
|
BucketPolicyOnly bool `config:"bucket_policy_only"`
|
||||||
Location string `config:"location"`
|
Location string `config:"location"`
|
||||||
StorageClass string `config:"storage_class"`
|
StorageClass string `config:"storage_class"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote storage server
|
// Fs represents a remote storage server
|
||||||
@@ -353,7 +359,7 @@ func parsePath(path string) (root string) {
|
|||||||
// relative to f.root
|
// relative to f.root
|
||||||
func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) {
|
func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) {
|
||||||
bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
||||||
return enc.FromStandardName(bucketName), enc.FromStandardPath(bucketPath)
|
return f.opt.Enc.FromStandardName(bucketName), f.opt.Enc.FromStandardPath(bucketPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// split returns bucket and bucketPath from the object
|
// split returns bucket and bucketPath from the object
|
||||||
@@ -442,7 +448,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
|
|
||||||
if f.rootBucket != "" && f.rootDirectory != "" {
|
if f.rootBucket != "" && f.rootDirectory != "" {
|
||||||
// Check to see if the object exists
|
// Check to see if the object exists
|
||||||
encodedDirectory := enc.FromStandardPath(f.rootDirectory)
|
encodedDirectory := f.opt.Enc.FromStandardPath(f.rootDirectory)
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
_, err = f.svc.Objects.Get(f.rootBucket, encodedDirectory).Context(ctx).Do()
|
_, err = f.svc.Objects.Get(f.rootBucket, encodedDirectory).Context(ctx).Do()
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
@@ -527,7 +533,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
if !strings.HasSuffix(remote, "/") {
|
if !strings.HasSuffix(remote, "/") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
remote = enc.ToStandardPath(remote)
|
remote = f.opt.Enc.ToStandardPath(remote)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Logf(f, "Odd name received %q", remote)
|
fs.Logf(f, "Odd name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -543,7 +549,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, object := range objects.Items {
|
for _, object := range objects.Items {
|
||||||
remote := enc.ToStandardPath(object.Name)
|
remote := f.opt.Enc.ToStandardPath(object.Name)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Logf(f, "Odd name received %q", object.Name)
|
fs.Logf(f, "Odd name received %q", object.Name)
|
||||||
continue
|
continue
|
||||||
@@ -620,7 +626,7 @@ func (f *Fs) listBuckets(ctx context.Context) (entries fs.DirEntries, err error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, bucket := range buckets.Items {
|
for _, bucket := range buckets.Items {
|
||||||
d := fs.NewDir(enc.ToStandardName(bucket.Name), time.Time{})
|
d := fs.NewDir(f.opt.Enc.ToStandardName(bucket.Name), time.Time{})
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
}
|
}
|
||||||
if buckets.NextPageToken == "" {
|
if buckets.NextPageToken == "" {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
_ "github.com/rclone/rclone/backend/local"
|
_ "github.com/rclone/rclone/backend/local"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/fs/operations"
|
||||||
"github.com/rclone/rclone/fstest"
|
"github.com/rclone/rclone/fstest"
|
||||||
"github.com/rclone/rclone/lib/random"
|
"github.com/rclone/rclone/lib/random"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -26,17 +27,6 @@ const (
|
|||||||
fileNameUpload = "rclone-test-image2.jpg"
|
fileNameUpload = "rclone-test-image2.jpg"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Wrapper to override the remote for an object
|
|
||||||
type overrideRemoteObject struct {
|
|
||||||
fs.Object
|
|
||||||
remote string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remote returns the overridden remote name
|
|
||||||
func (o *overrideRemoteObject) Remote() string {
|
|
||||||
return o.remote
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
fstest.Initialise()
|
fstest.Initialise()
|
||||||
@@ -66,7 +56,7 @@ func TestIntegration(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
in, err := srcObj.Open(ctx)
|
in, err := srcObj.Open(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dstObj, err := f.Put(ctx, in, &overrideRemoteObject{srcObj, remote})
|
dstObj, err := f.Put(ctx, in, operations.NewOverrideRemote(srcObj, remote))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, remote, dstObj.Remote())
|
assert.Equal(t, remote, dstObj.Remote())
|
||||||
_ = in.Close()
|
_ = in.Close()
|
||||||
@@ -231,7 +221,7 @@ func TestIntegration(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
in, err := srcObj.Open(ctx)
|
in, err := srcObj.Open(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
dstObj, err := f.Put(ctx, in, &overrideRemoteObject{srcObj, remote})
|
dstObj, err := f.Put(ctx, in, operations.NewOverrideRemote(srcObj, remote))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, remote, dstObj.Remote())
|
assert.Equal(t, remote, dstObj.Remote())
|
||||||
_ = in.Close()
|
_ = in.Close()
|
||||||
|
|||||||
@@ -26,19 +26,17 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config"
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.JottaCloud
|
|
||||||
|
|
||||||
// Globals
|
// Globals
|
||||||
const (
|
const (
|
||||||
minSleep = 10 * time.Millisecond
|
minSleep = 10 * time.Millisecond
|
||||||
@@ -157,18 +155,29 @@ func init() {
|
|||||||
Help: "Files bigger than this can be resumed if the upload fail's.",
|
Help: "Files bigger than this can be resumed if the upload fail's.",
|
||||||
Default: fs.SizeSuffix(10 * 1024 * 1024),
|
Default: fs.SizeSuffix(10 * 1024 * 1024),
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as xml doesn't handle them properly.
|
||||||
|
//
|
||||||
|
// Also: '*', '/', ':', '<', '>', '?', '\"', '\x00', '|'
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeWin | // :?"*<>|
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Device string `config:"device"`
|
Device string `config:"device"`
|
||||||
Mountpoint string `config:"mountpoint"`
|
Mountpoint string `config:"mountpoint"`
|
||||||
MD5MemoryThreshold fs.SizeSuffix `config:"md5_memory_limit"`
|
MD5MemoryThreshold fs.SizeSuffix `config:"md5_memory_limit"`
|
||||||
HardDelete bool `config:"hard_delete"`
|
HardDelete bool `config:"hard_delete"`
|
||||||
Unlink bool `config:"unlink"`
|
Unlink bool `config:"unlink"`
|
||||||
UploadThreshold fs.SizeSuffix `config:"upload_resume_limit"`
|
UploadThreshold fs.SizeSuffix `config:"upload_resume_limit"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote jottacloud
|
// Fs represents a remote jottacloud
|
||||||
@@ -244,7 +253,7 @@ func shouldRetry(resp *http.Response, err error) (bool, error) {
|
|||||||
|
|
||||||
// doAuth runs the actual token request
|
// doAuth runs the actual token request
|
||||||
func doAuth(ctx context.Context, srv *rest.Client, loginTokenBase64 string, m configmap.Mapper) (token oauth2.Token, err error) {
|
func doAuth(ctx context.Context, srv *rest.Client, loginTokenBase64 string, m configmap.Mapper) (token oauth2.Token, err error) {
|
||||||
loginTokenBytes, err := base64.StdEncoding.DecodeString(loginTokenBase64)
|
loginTokenBytes, err := base64.RawURLEncoding.DecodeString(loginTokenBase64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return token, err
|
return token, err
|
||||||
}
|
}
|
||||||
@@ -446,7 +455,7 @@ func urlPathEscape(in string) string {
|
|||||||
|
|
||||||
// filePathRaw returns an unescaped file path (f.root, file)
|
// filePathRaw returns an unescaped file path (f.root, file)
|
||||||
func (f *Fs) filePathRaw(file string) string {
|
func (f *Fs) filePathRaw(file string) string {
|
||||||
return path.Join(f.endpointURL, enc.FromStandardPath(path.Join(f.root, file)))
|
return path.Join(f.endpointURL, f.opt.Enc.FromStandardPath(path.Join(f.root, file)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// filePath returns a escaped file path (f.root, file)
|
// filePath returns a escaped file path (f.root, file)
|
||||||
@@ -638,7 +647,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
if item.Deleted {
|
if item.Deleted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
remote := path.Join(dir, enc.ToStandardName(item.Name))
|
remote := path.Join(dir, f.opt.Enc.ToStandardName(item.Name))
|
||||||
d := fs.NewDir(remote, time.Time(item.ModifiedAt))
|
d := fs.NewDir(remote, time.Time(item.ModifiedAt))
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
}
|
}
|
||||||
@@ -648,7 +657,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
if item.Deleted || item.State != "COMPLETED" {
|
if item.Deleted || item.State != "COMPLETED" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
remote := path.Join(dir, enc.ToStandardName(item.Name))
|
remote := path.Join(dir, f.opt.Enc.ToStandardName(item.Name))
|
||||||
o, err := f.newObjectWithInfo(ctx, remote, item)
|
o, err := f.newObjectWithInfo(ctx, remote, item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@@ -673,7 +682,7 @@ func (f *Fs) listFileDir(ctx context.Context, remoteStartPath string, startFolde
|
|||||||
if folder.Deleted {
|
if folder.Deleted {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
folderPath := enc.ToStandardPath(path.Join(folder.Path, folder.Name))
|
folderPath := f.opt.Enc.ToStandardPath(path.Join(folder.Path, folder.Name))
|
||||||
folderPathLength := len(folderPath)
|
folderPathLength := len(folderPath)
|
||||||
var remoteDir string
|
var remoteDir string
|
||||||
if folderPathLength > pathPrefixLength {
|
if folderPathLength > pathPrefixLength {
|
||||||
@@ -691,7 +700,7 @@ func (f *Fs) listFileDir(ctx context.Context, remoteStartPath string, startFolde
|
|||||||
if file.Deleted || file.State != "COMPLETED" {
|
if file.Deleted || file.State != "COMPLETED" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
remoteFile := path.Join(remoteDir, enc.ToStandardName(file.Name))
|
remoteFile := path.Join(remoteDir, f.opt.Enc.ToStandardName(file.Name))
|
||||||
o, err := f.newObjectWithInfo(ctx, remoteFile, file)
|
o, err := f.newObjectWithInfo(ctx, remoteFile, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -862,7 +871,7 @@ func (f *Fs) copyOrMove(ctx context.Context, method, src, dest string) (info *ap
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set(method, "/"+path.Join(f.endpointURL, enc.FromStandardPath(path.Join(f.root, dest))))
|
opts.Parameters.Set(method, "/"+path.Join(f.endpointURL, f.opt.Enc.FromStandardPath(path.Join(f.root, dest))))
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@@ -969,7 +978,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
return fs.ErrorDirExists
|
return fs.ErrorDirExists
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = f.copyOrMove(ctx, "mvDir", path.Join(f.endpointURL, enc.FromStandardPath(srcPath))+"/", dstRemote)
|
_, err = f.copyOrMove(ctx, "mvDir", path.Join(f.endpointURL, f.opt.Enc.FromStandardPath(srcPath))+"/", dstRemote)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "couldn't move directory")
|
return errors.Wrap(err, "couldn't move directory")
|
||||||
@@ -1260,7 +1269,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
Created: fileDate,
|
Created: fileDate,
|
||||||
Modified: fileDate,
|
Modified: fileDate,
|
||||||
Md5: md5String,
|
Md5: md5String,
|
||||||
Path: path.Join(o.fs.opt.Mountpoint, enc.FromStandardPath(path.Join(o.fs.root, o.remote))),
|
Path: path.Join(o.fs.opt.Mountpoint, o.fs.opt.Enc.FromStandardPath(path.Join(o.fs.root, o.remote))),
|
||||||
}
|
}
|
||||||
|
|
||||||
// send it
|
// send it
|
||||||
|
|||||||
+47
-41
@@ -12,65 +12,71 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
|
|
||||||
httpclient "github.com/koofr/go-httpclient"
|
httpclient "github.com/koofr/go-httpclient"
|
||||||
koofrclient "github.com/koofr/go-koofrclient"
|
koofrclient "github.com/koofr/go-koofrclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Koofr
|
|
||||||
|
|
||||||
// Register Fs with rclone
|
// Register Fs with rclone
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
Name: "koofr",
|
Name: "koofr",
|
||||||
Description: "Koofr",
|
Description: "Koofr",
|
||||||
NewFs: NewFs,
|
NewFs: NewFs,
|
||||||
Options: []fs.Option{
|
Options: []fs.Option{{
|
||||||
{
|
Name: "endpoint",
|
||||||
Name: "endpoint",
|
Help: "The Koofr API endpoint to use",
|
||||||
Help: "The Koofr API endpoint to use",
|
Default: "https://app.koofr.net",
|
||||||
Default: "https://app.koofr.net",
|
Required: true,
|
||||||
Required: true,
|
Advanced: true,
|
||||||
Advanced: true,
|
}, {
|
||||||
}, {
|
Name: "mountid",
|
||||||
Name: "mountid",
|
Help: "Mount ID of the mount to use. If omitted, the primary mount is used.",
|
||||||
Help: "Mount ID of the mount to use. If omitted, the primary mount is used.",
|
Required: false,
|
||||||
Required: false,
|
Default: "",
|
||||||
Default: "",
|
Advanced: true,
|
||||||
Advanced: true,
|
}, {
|
||||||
}, {
|
Name: "setmtime",
|
||||||
Name: "setmtime",
|
Help: "Does the backend support setting modification time. Set this to false if you use a mount ID that points to a Dropbox or Amazon Drive backend.",
|
||||||
Help: "Does the backend support setting modification time. Set this to false if you use a mount ID that points to a Dropbox or Amazon Drive backend.",
|
Default: true,
|
||||||
Default: true,
|
Required: true,
|
||||||
Required: true,
|
Advanced: true,
|
||||||
Advanced: true,
|
}, {
|
||||||
}, {
|
Name: "user",
|
||||||
Name: "user",
|
Help: "Your Koofr user name",
|
||||||
Help: "Your Koofr user name",
|
Required: true,
|
||||||
Required: true,
|
}, {
|
||||||
}, {
|
Name: "password",
|
||||||
Name: "password",
|
Help: "Your Koofr password for rclone (generate one at https://app.koofr.net/app/admin/preferences/password)",
|
||||||
Help: "Your Koofr password for rclone (generate one at https://app.koofr.net/app/admin/preferences/password)",
|
IsPassword: true,
|
||||||
IsPassword: true,
|
Required: true,
|
||||||
Required: true,
|
}, {
|
||||||
},
|
Name: config.ConfigEncoding,
|
||||||
},
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options represent the configuration of the Koofr backend
|
// Options represent the configuration of the Koofr backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Endpoint string `config:"endpoint"`
|
Endpoint string `config:"endpoint"`
|
||||||
MountID string `config:"mountid"`
|
MountID string `config:"mountid"`
|
||||||
User string `config:"user"`
|
User string `config:"user"`
|
||||||
Password string `config:"password"`
|
Password string `config:"password"`
|
||||||
SetMTime bool `config:"setmtime"`
|
SetMTime bool `config:"setmtime"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Fs is a representation of a remote Koofr Fs
|
// A Fs is a representation of a remote Koofr Fs
|
||||||
@@ -246,7 +252,7 @@ func (f *Fs) Hashes() hash.Set {
|
|||||||
|
|
||||||
// fullPath constructs a full, absolute path from a Fs root relative path,
|
// fullPath constructs a full, absolute path from a Fs root relative path,
|
||||||
func (f *Fs) fullPath(part string) string {
|
func (f *Fs) fullPath(part string) string {
|
||||||
return enc.FromStandardPath(path.Join("/", f.root, part))
|
return f.opt.Enc.FromStandardPath(path.Join("/", f.root, part))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFs constructs a new filesystem given a root path and configuration options
|
// NewFs constructs a new filesystem given a root path and configuration options
|
||||||
@@ -299,7 +305,7 @@ func NewFs(name, root string, m configmap.Mapper) (ff fs.Fs, err error) {
|
|||||||
}
|
}
|
||||||
return nil, errors.New("Failed to find mount " + opt.MountID)
|
return nil, errors.New("Failed to find mount " + opt.MountID)
|
||||||
}
|
}
|
||||||
rootFile, err := f.client.FilesInfo(f.mountID, enc.FromStandardPath("/"+f.root))
|
rootFile, err := f.client.FilesInfo(f.mountID, f.opt.Enc.FromStandardPath("/"+f.root))
|
||||||
if err == nil && rootFile.Type != "dir" {
|
if err == nil && rootFile.Type != "dir" {
|
||||||
f.root = dir(f.root)
|
f.root = dir(f.root)
|
||||||
err = fs.ErrorIsFile
|
err = fs.ErrorIsFile
|
||||||
@@ -317,7 +323,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
}
|
}
|
||||||
entries = make([]fs.DirEntry, len(files))
|
entries = make([]fs.DirEntry, len(files))
|
||||||
for i, file := range files {
|
for i, file := range files {
|
||||||
remote := path.Join(dir, enc.ToStandardName(file.Name))
|
remote := path.Join(dir, f.opt.Enc.ToStandardName(file.Name))
|
||||||
if file.Type == "dir" {
|
if file.Type == "dir" {
|
||||||
entries[i] = fs.NewDir(remote, time.Unix(0, 0))
|
entries[i] = fs.NewDir(remote, time.Unix(0, 0))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import (
|
import "github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const enc = encodings.LocalMacOS
|
// This is the encoding used by the local backend for macOS
|
||||||
|
//
|
||||||
|
// macOS can't store invalid UTF-8, it converts them into %XX encoding
|
||||||
|
const defaultEnc = (encoder.Base |
|
||||||
|
encoder.EncodeInvalidUtf8)
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import (
|
import "github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const enc = encodings.LocalUnix
|
// This is the encoding used by the local backend for non windows platforms
|
||||||
|
const defaultEnc = encoder.Base
|
||||||
@@ -2,8 +2,32 @@
|
|||||||
|
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import (
|
import "github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const enc = encodings.LocalWindows
|
// This is the encoding used by the local backend for windows platforms
|
||||||
|
//
|
||||||
|
// List of replaced characters:
|
||||||
|
// < (less than) -> '<' // FULLWIDTH LESS-THAN SIGN
|
||||||
|
// > (greater than) -> '>' // FULLWIDTH GREATER-THAN SIGN
|
||||||
|
// : (colon) -> ':' // FULLWIDTH COLON
|
||||||
|
// " (double quote) -> '"' // FULLWIDTH QUOTATION MARK
|
||||||
|
// \ (backslash) -> '\' // FULLWIDTH REVERSE SOLIDUS
|
||||||
|
// | (vertical line) -> '|' // FULLWIDTH VERTICAL LINE
|
||||||
|
// ? (question mark) -> '?' // FULLWIDTH QUESTION MARK
|
||||||
|
// * (asterisk) -> '*' // FULLWIDTH ASTERISK
|
||||||
|
//
|
||||||
|
// Additionally names can't end with a period (.) or space ( ).
|
||||||
|
// List of replaced characters:
|
||||||
|
// . (period) -> '.' // FULLWIDTH FULL STOP
|
||||||
|
// (space) -> '␠' // SYMBOL FOR SPACE
|
||||||
|
//
|
||||||
|
// Also encode invalid UTF-8 bytes as Go can't convert them to UTF-16.
|
||||||
|
//
|
||||||
|
// https://docs.microsoft.com/de-de/windows/desktop/FileIO/naming-a-file#naming-conventions
|
||||||
|
const defaultEnc = (encoder.Base |
|
||||||
|
encoder.EncodeWin |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeCtl |
|
||||||
|
encoder.EncodeRightSpace |
|
||||||
|
encoder.EncodeRightPeriod |
|
||||||
|
encoder.EncodeInvalidUtf8)
|
||||||
+22
-14
@@ -20,10 +20,12 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/accounting"
|
"github.com/rclone/rclone/fs/accounting"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/file"
|
"github.com/rclone/rclone/lib/file"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
)
|
)
|
||||||
@@ -115,6 +117,11 @@ Windows/macOS and case sensitive for everything else. Use this flag
|
|||||||
to override the default choice.`,
|
to override the default choice.`,
|
||||||
Default: false,
|
Default: false,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
Default: defaultEnc,
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
fs.Register(fsi)
|
fs.Register(fsi)
|
||||||
@@ -122,15 +129,16 @@ to override the default choice.`,
|
|||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
FollowSymlinks bool `config:"copy_links"`
|
FollowSymlinks bool `config:"copy_links"`
|
||||||
TranslateSymlinks bool `config:"links"`
|
TranslateSymlinks bool `config:"links"`
|
||||||
SkipSymlinks bool `config:"skip_links"`
|
SkipSymlinks bool `config:"skip_links"`
|
||||||
NoUTFNorm bool `config:"no_unicode_normalization"`
|
NoUTFNorm bool `config:"no_unicode_normalization"`
|
||||||
NoCheckUpdated bool `config:"no_check_updated"`
|
NoCheckUpdated bool `config:"no_check_updated"`
|
||||||
NoUNC bool `config:"nounc"`
|
NoUNC bool `config:"nounc"`
|
||||||
OneFileSystem bool `config:"one_file_system"`
|
OneFileSystem bool `config:"one_file_system"`
|
||||||
CaseSensitive bool `config:"case_sensitive"`
|
CaseSensitive bool `config:"case_sensitive"`
|
||||||
CaseInsensitive bool `config:"case_insensitive"`
|
CaseInsensitive bool `config:"case_insensitive"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a local filesystem rooted at root
|
// Fs represents a local filesystem rooted at root
|
||||||
@@ -189,7 +197,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
dev: devUnset,
|
dev: devUnset,
|
||||||
lstat: os.Lstat,
|
lstat: os.Lstat,
|
||||||
}
|
}
|
||||||
f.root = cleanRootPath(root, f.opt.NoUNC)
|
f.root = cleanRootPath(root, f.opt.NoUNC, f.opt.Enc)
|
||||||
f.features = (&fs.Features{
|
f.features = (&fs.Features{
|
||||||
CaseInsensitive: f.caseInsensitive(),
|
CaseInsensitive: f.caseInsensitive(),
|
||||||
CanHaveEmptyDirectories: true,
|
CanHaveEmptyDirectories: true,
|
||||||
@@ -234,7 +242,7 @@ func (f *Fs) Name() string {
|
|||||||
|
|
||||||
// Root of the remote (as passed into NewFs)
|
// Root of the remote (as passed into NewFs)
|
||||||
func (f *Fs) Root() string {
|
func (f *Fs) Root() string {
|
||||||
return enc.ToStandardPath(filepath.ToSlash(f.root))
|
return f.opt.Enc.ToStandardPath(filepath.ToSlash(f.root))
|
||||||
}
|
}
|
||||||
|
|
||||||
// String converts this Fs to a string
|
// String converts this Fs to a string
|
||||||
@@ -443,7 +451,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) cleanRemote(dir, filename string) (remote string) {
|
func (f *Fs) cleanRemote(dir, filename string) (remote string) {
|
||||||
remote = path.Join(dir, enc.ToStandardName(filename))
|
remote = path.Join(dir, f.opt.Enc.ToStandardName(filename))
|
||||||
|
|
||||||
if !utf8.ValidString(filename) {
|
if !utf8.ValidString(filename) {
|
||||||
f.warnedMu.Lock()
|
f.warnedMu.Lock()
|
||||||
@@ -457,7 +465,7 @@ func (f *Fs) cleanRemote(dir, filename string) (remote string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) localPath(name string) string {
|
func (f *Fs) localPath(name string) string {
|
||||||
return filepath.Join(f.root, filepath.FromSlash(enc.FromStandardPath(name)))
|
return filepath.Join(f.root, filepath.FromSlash(f.opt.Enc.FromStandardPath(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put the Object to the local filesystem
|
// Put the Object to the local filesystem
|
||||||
@@ -1092,7 +1100,7 @@ func (o *Object) Remove(ctx context.Context) error {
|
|||||||
return remove(o.path)
|
return remove(o.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanRootPath(s string, noUNC bool) string {
|
func cleanRootPath(s string, noUNC bool, enc encoder.MultiEncoder) string {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
if !filepath.IsAbs(s) && !strings.HasPrefix(s, "\\") {
|
if !filepath.IsAbs(s) && !strings.HasPrefix(s, "\\") {
|
||||||
s2, err := filepath.Abs(s)
|
s2, err := filepath.Abs(s)
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func TestCleanWindows(t *testing.T) {
|
|||||||
t.Skipf("windows only")
|
t.Skipf("windows only")
|
||||||
}
|
}
|
||||||
for _, test := range testsWindows {
|
for _, test := range testsWindows {
|
||||||
got := cleanRootPath(test[0], true)
|
got := cleanRootPath(test[0], true, defaultEnc)
|
||||||
expect := test[1]
|
expect := test[1]
|
||||||
if got != expect {
|
if got != expect {
|
||||||
t.Fatalf("got %q, expected %q", got, expect)
|
t.Fatalf("got %q, expected %q", got, expect)
|
||||||
|
|||||||
+36
-27
@@ -24,16 +24,17 @@ import (
|
|||||||
"github.com/rclone/rclone/backend/mailru/mrhash"
|
"github.com/rclone/rclone/backend/mailru/mrhash"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/object"
|
"github.com/rclone/rclone/fs/object"
|
||||||
"github.com/rclone/rclone/fs/operations"
|
"github.com/rclone/rclone/fs/operations"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
@@ -42,8 +43,6 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Mailru
|
|
||||||
|
|
||||||
// Global constants
|
// Global constants
|
||||||
const (
|
const (
|
||||||
minSleepPacer = 10 * time.Millisecond
|
minSleepPacer = 10 * time.Millisecond
|
||||||
@@ -193,21 +192,31 @@ facilitate remote troubleshooting of backend issues. Strict meaning of
|
|||||||
flags is not documented and not guaranteed to persist between releases.
|
flags is not documented and not guaranteed to persist between releases.
|
||||||
Quirks will be removed when the backend grows stable.
|
Quirks will be removed when the backend grows stable.
|
||||||
Supported quirks: atomicmkdir binlist gzip insecure retry400`,
|
Supported quirks: atomicmkdir binlist gzip insecure retry400`,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeWin | // :?"*<>|
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Username string `config:"user"`
|
Username string `config:"user"`
|
||||||
Password string `config:"pass"`
|
Password string `config:"pass"`
|
||||||
UserAgent string `config:"user_agent"`
|
UserAgent string `config:"user_agent"`
|
||||||
CheckHash bool `config:"check_hash"`
|
CheckHash bool `config:"check_hash"`
|
||||||
SpeedupEnable bool `config:"speedup_enable"`
|
SpeedupEnable bool `config:"speedup_enable"`
|
||||||
SpeedupPatterns string `config:"speedup_file_patterns"`
|
SpeedupPatterns string `config:"speedup_file_patterns"`
|
||||||
SpeedupMaxDisk fs.SizeSuffix `config:"speedup_max_disk"`
|
SpeedupMaxDisk fs.SizeSuffix `config:"speedup_max_disk"`
|
||||||
SpeedupMaxMem fs.SizeSuffix `config:"speedup_max_memory"`
|
SpeedupMaxMem fs.SizeSuffix `config:"speedup_max_memory"`
|
||||||
Quirks string `config:"quirks"`
|
Quirks string `config:"quirks"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// retryErrorCodes is a slice of error codes that we will retry
|
// retryErrorCodes is a slice of error codes that we will retry
|
||||||
@@ -607,7 +616,7 @@ func (f *Fs) readItemMetaData(ctx context.Context, path string) (entry fs.DirEnt
|
|||||||
Path: "/api/m1/file",
|
Path: "/api/m1/file",
|
||||||
Parameters: url.Values{
|
Parameters: url.Values{
|
||||||
"access_token": {token},
|
"access_token": {token},
|
||||||
"home": {enc.FromStandardPath(path)},
|
"home": {f.opt.Enc.FromStandardPath(path)},
|
||||||
"offset": {"0"},
|
"offset": {"0"},
|
||||||
"limit": {strconv.Itoa(maxInt32)},
|
"limit": {strconv.Itoa(maxInt32)},
|
||||||
},
|
},
|
||||||
@@ -642,7 +651,7 @@ func (f *Fs) readItemMetaData(ctx context.Context, path string) (entry fs.DirEnt
|
|||||||
// =0 - for an empty directory
|
// =0 - for an empty directory
|
||||||
// >0 - for a non-empty directory
|
// >0 - for a non-empty directory
|
||||||
func (f *Fs) itemToDirEntry(ctx context.Context, item *api.ListItem) (entry fs.DirEntry, dirSize int, err error) {
|
func (f *Fs) itemToDirEntry(ctx context.Context, item *api.ListItem) (entry fs.DirEntry, dirSize int, err error) {
|
||||||
remote, err := f.relPath(enc.ToStandardPath(item.Home))
|
remote, err := f.relPath(f.opt.Enc.ToStandardPath(item.Home))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
@@ -708,7 +717,7 @@ func (f *Fs) listM1(ctx context.Context, dirPath string, offset int, limit int)
|
|||||||
params.Set("limit", strconv.Itoa(limit))
|
params.Set("limit", strconv.Itoa(limit))
|
||||||
|
|
||||||
data := url.Values{}
|
data := url.Values{}
|
||||||
data.Set("home", enc.FromStandardPath(dirPath))
|
data.Set("home", f.opt.Enc.FromStandardPath(dirPath))
|
||||||
|
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
@@ -756,7 +765,7 @@ func (f *Fs) listBin(ctx context.Context, dirPath string, depth int) (entries fs
|
|||||||
|
|
||||||
req := api.NewBinWriter()
|
req := api.NewBinWriter()
|
||||||
req.WritePu16(api.OperationFolderList)
|
req.WritePu16(api.OperationFolderList)
|
||||||
req.WriteString(enc.FromStandardPath(dirPath))
|
req.WriteString(f.opt.Enc.FromStandardPath(dirPath))
|
||||||
req.WritePu32(int64(depth))
|
req.WritePu32(int64(depth))
|
||||||
req.WritePu32(int64(options))
|
req.WritePu32(int64(options))
|
||||||
req.WritePu32(0)
|
req.WritePu32(0)
|
||||||
@@ -892,7 +901,7 @@ func (t *treeState) NextRecord() (fs.DirEntry, error) {
|
|||||||
if (head & 4096) != 0 {
|
if (head & 4096) != 0 {
|
||||||
t.dunnoNodeID = r.ReadNBytes(api.DunnoNodeIDLength)
|
t.dunnoNodeID = r.ReadNBytes(api.DunnoNodeIDLength)
|
||||||
}
|
}
|
||||||
name := enc.FromStandardPath(string(r.ReadBytesByLength()))
|
name := t.f.opt.Enc.FromStandardPath(string(r.ReadBytesByLength()))
|
||||||
t.dunno1 = int(r.ReadULong())
|
t.dunno1 = int(r.ReadULong())
|
||||||
t.dunno2 = 0
|
t.dunno2 = 0
|
||||||
t.dunno3 = 0
|
t.dunno3 = 0
|
||||||
@@ -1031,7 +1040,7 @@ func (f *Fs) CreateDir(ctx context.Context, path string) error {
|
|||||||
req := api.NewBinWriter()
|
req := api.NewBinWriter()
|
||||||
req.WritePu16(api.OperationCreateFolder)
|
req.WritePu16(api.OperationCreateFolder)
|
||||||
req.WritePu16(0) // revision
|
req.WritePu16(0) // revision
|
||||||
req.WriteString(enc.FromStandardPath(path))
|
req.WriteString(f.opt.Enc.FromStandardPath(path))
|
||||||
req.WritePu32(0)
|
req.WritePu32(0)
|
||||||
|
|
||||||
token, err := f.accessToken()
|
token, err := f.accessToken()
|
||||||
@@ -1186,7 +1195,7 @@ func (f *Fs) delete(ctx context.Context, path string, hardDelete bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{"home": {enc.FromStandardPath(path)}}
|
data := url.Values{"home": {f.opt.Enc.FromStandardPath(path)}}
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
Path: "/api/m1/file/remove",
|
Path: "/api/m1/file/remove",
|
||||||
@@ -1243,8 +1252,8 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
data := url.Values{}
|
||||||
data.Set("home", enc.FromStandardPath(srcPath))
|
data.Set("home", f.opt.Enc.FromStandardPath(srcPath))
|
||||||
data.Set("folder", enc.FromStandardPath(parentDir(dstPath)))
|
data.Set("folder", f.opt.Enc.FromStandardPath(parentDir(dstPath)))
|
||||||
data.Set("email", f.opt.Username)
|
data.Set("email", f.opt.Username)
|
||||||
data.Set("x-email", f.opt.Username)
|
data.Set("x-email", f.opt.Username)
|
||||||
|
|
||||||
@@ -1282,7 +1291,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
return nil, fmt.Errorf("copy failed with code %d", response.Status)
|
return nil, fmt.Errorf("copy failed with code %d", response.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpPath := enc.ToStandardPath(response.Body)
|
tmpPath := f.opt.Enc.ToStandardPath(response.Body)
|
||||||
if tmpPath != dstPath {
|
if tmpPath != dstPath {
|
||||||
// fs.Debugf(f, "rename temporary file %q -> %q\n", tmpPath, dstPath)
|
// fs.Debugf(f, "rename temporary file %q -> %q\n", tmpPath, dstPath)
|
||||||
err = f.moveItemBin(ctx, tmpPath, dstPath, "rename temporary file")
|
err = f.moveItemBin(ctx, tmpPath, dstPath, "rename temporary file")
|
||||||
@@ -1357,9 +1366,9 @@ func (f *Fs) moveItemBin(ctx context.Context, srcPath, dstPath, opName string) e
|
|||||||
req := api.NewBinWriter()
|
req := api.NewBinWriter()
|
||||||
req.WritePu16(api.OperationRename)
|
req.WritePu16(api.OperationRename)
|
||||||
req.WritePu32(0) // old revision
|
req.WritePu32(0) // old revision
|
||||||
req.WriteString(enc.FromStandardPath(srcPath))
|
req.WriteString(f.opt.Enc.FromStandardPath(srcPath))
|
||||||
req.WritePu32(0) // new revision
|
req.WritePu32(0) // new revision
|
||||||
req.WriteString(enc.FromStandardPath(dstPath))
|
req.WriteString(f.opt.Enc.FromStandardPath(dstPath))
|
||||||
req.WritePu32(0) // dunno
|
req.WritePu32(0) // dunno
|
||||||
|
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
@@ -1450,7 +1459,7 @@ func (f *Fs) PublicLink(ctx context.Context, remote string) (link string, err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
data := url.Values{}
|
||||||
data.Set("home", enc.FromStandardPath(f.absPath(remote)))
|
data.Set("home", f.opt.Enc.FromStandardPath(f.absPath(remote)))
|
||||||
data.Set("email", f.opt.Username)
|
data.Set("email", f.opt.Username)
|
||||||
data.Set("x-email", f.opt.Username)
|
data.Set("x-email", f.opt.Username)
|
||||||
|
|
||||||
@@ -2015,7 +2024,7 @@ func (o *Object) addFileMetaData(ctx context.Context, overwrite bool) error {
|
|||||||
req := api.NewBinWriter()
|
req := api.NewBinWriter()
|
||||||
req.WritePu16(api.OperationAddFile)
|
req.WritePu16(api.OperationAddFile)
|
||||||
req.WritePu16(0) // revision
|
req.WritePu16(0) // revision
|
||||||
req.WriteString(enc.FromStandardPath(o.absPath()))
|
req.WriteString(o.fs.opt.Enc.FromStandardPath(o.absPath()))
|
||||||
req.WritePu64(o.size)
|
req.WritePu64(o.size)
|
||||||
req.WritePu64(o.modTime.Unix())
|
req.WritePu64(o.modTime.Unix())
|
||||||
req.WritePu32(0)
|
req.WritePu32(0)
|
||||||
@@ -2113,7 +2122,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
|||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Options: options,
|
Options: options,
|
||||||
Path: url.PathEscape(strings.TrimLeft(enc.FromStandardPath(o.absPath()), "/")),
|
Path: url.PathEscape(strings.TrimLeft(o.fs.opt.Enc.FromStandardPath(o.absPath()), "/")),
|
||||||
Parameters: url.Values{
|
Parameters: url.Values{
|
||||||
"client_id": {api.OAuthClientID},
|
"client_id": {api.OAuthClientID},
|
||||||
"token": {token},
|
"token": {token},
|
||||||
|
|||||||
+24
-17
@@ -26,19 +26,18 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
mega "github.com/t3rm1n4l/go-mega"
|
mega "github.com/t3rm1n4l/go-mega"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Mega
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
minSleep = 10 * time.Millisecond
|
minSleep = 10 * time.Millisecond
|
||||||
maxSleep = 2 * time.Second
|
maxSleep = 2 * time.Second
|
||||||
@@ -83,16 +82,24 @@ than permanently deleting them. If you specify this then rclone will
|
|||||||
permanently delete objects instead.`,
|
permanently delete objects instead.`,
|
||||||
Default: false,
|
Default: false,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
Default: (encoder.Base |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
User string `config:"user"`
|
User string `config:"user"`
|
||||||
Pass string `config:"pass"`
|
Pass string `config:"pass"`
|
||||||
Debug bool `config:"debug"`
|
Debug bool `config:"debug"`
|
||||||
HardDelete bool `config:"hard_delete"`
|
HardDelete bool `config:"hard_delete"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote mega
|
// Fs represents a remote mega
|
||||||
@@ -250,12 +257,12 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
// splitNodePath splits nodePath into / separated parts, returning nil if it
|
// splitNodePath splits nodePath into / separated parts, returning nil if it
|
||||||
// should refer to the root.
|
// should refer to the root.
|
||||||
// It also encodes the parts into backend specific encoding
|
// It also encodes the parts into backend specific encoding
|
||||||
func splitNodePath(nodePath string) (parts []string) {
|
func (f *Fs) splitNodePath(nodePath string) (parts []string) {
|
||||||
nodePath = path.Clean(nodePath)
|
nodePath = path.Clean(nodePath)
|
||||||
if nodePath == "." || nodePath == "/" {
|
if nodePath == "." || nodePath == "/" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
nodePath = enc.FromStandardPath(nodePath)
|
nodePath = f.opt.Enc.FromStandardPath(nodePath)
|
||||||
return strings.Split(nodePath, "/")
|
return strings.Split(nodePath, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +270,7 @@ func splitNodePath(nodePath string) (parts []string) {
|
|||||||
//
|
//
|
||||||
// It returns mega.ENOENT if it wasn't found
|
// It returns mega.ENOENT if it wasn't found
|
||||||
func (f *Fs) findNode(rootNode *mega.Node, nodePath string) (*mega.Node, error) {
|
func (f *Fs) findNode(rootNode *mega.Node, nodePath string) (*mega.Node, error) {
|
||||||
parts := splitNodePath(nodePath)
|
parts := f.splitNodePath(nodePath)
|
||||||
if parts == nil {
|
if parts == nil {
|
||||||
return rootNode, nil
|
return rootNode, nil
|
||||||
}
|
}
|
||||||
@@ -320,7 +327,7 @@ func (f *Fs) mkdir(rootNode *mega.Node, dir string) (node *mega.Node, err error)
|
|||||||
f.mkdirMu.Lock()
|
f.mkdirMu.Lock()
|
||||||
defer f.mkdirMu.Unlock()
|
defer f.mkdirMu.Unlock()
|
||||||
|
|
||||||
parts := splitNodePath(dir)
|
parts := f.splitNodePath(dir)
|
||||||
if parts == nil {
|
if parts == nil {
|
||||||
return rootNode, nil
|
return rootNode, nil
|
||||||
}
|
}
|
||||||
@@ -422,7 +429,7 @@ func (f *Fs) CleanUp(ctx context.Context) (err error) {
|
|||||||
errors := 0
|
errors := 0
|
||||||
// similar to f.deleteNode(trash) but with HardDelete as true
|
// similar to f.deleteNode(trash) but with HardDelete as true
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
fs.Debugf(f, "Deleting trash %q", enc.ToStandardName(item.GetName()))
|
fs.Debugf(f, "Deleting trash %q", f.opt.Enc.ToStandardName(item.GetName()))
|
||||||
deleteErr := f.pacer.Call(func() (bool, error) {
|
deleteErr := f.pacer.Call(func() (bool, error) {
|
||||||
err := f.srv.Delete(item, true)
|
err := f.srv.Delete(item, true)
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
@@ -504,7 +511,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
}
|
}
|
||||||
var iErr error
|
var iErr error
|
||||||
_, err = f.list(ctx, dirNode, func(info *mega.Node) bool {
|
_, err = f.list(ctx, dirNode, func(info *mega.Node) bool {
|
||||||
remote := path.Join(dir, enc.ToStandardName(info.GetName()))
|
remote := path.Join(dir, f.opt.Enc.ToStandardName(info.GetName()))
|
||||||
switch info.GetType() {
|
switch info.GetType() {
|
||||||
case mega.FOLDER, mega.ROOT, mega.INBOX, mega.TRASH:
|
case mega.FOLDER, mega.ROOT, mega.INBOX, mega.TRASH:
|
||||||
d := fs.NewDir(remote, info.GetTimeStamp()).SetID(info.GetHash())
|
d := fs.NewDir(remote, info.GetTimeStamp()).SetID(info.GetHash())
|
||||||
@@ -726,7 +733,7 @@ func (f *Fs) move(dstRemote string, srcFs *Fs, srcRemote string, info *mega.Node
|
|||||||
if srcLeaf != dstLeaf {
|
if srcLeaf != dstLeaf {
|
||||||
//log.Printf("rename %q to %q", srcLeaf, dstLeaf)
|
//log.Printf("rename %q to %q", srcLeaf, dstLeaf)
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
err = f.srv.Rename(info, enc.FromStandardName(dstLeaf))
|
err = f.srv.Rename(info, f.opt.Enc.FromStandardName(dstLeaf))
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -875,13 +882,13 @@ func (f *Fs) MergeDirs(ctx context.Context, dirs []fs.Directory) error {
|
|||||||
}
|
}
|
||||||
// move them into place
|
// move them into place
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
fs.Infof(srcDir, "merging %q", enc.ToStandardName(info.GetName()))
|
fs.Infof(srcDir, "merging %q", f.opt.Enc.ToStandardName(info.GetName()))
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
err = f.srv.Move(info, dstDirNode)
|
err = f.srv.Move(info, dstDirNode)
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "MergeDirs move failed on %q in %v", enc.ToStandardName(info.GetName()), srcDir)
|
return errors.Wrapf(err, "MergeDirs move failed on %q in %v", f.opt.Enc.ToStandardName(info.GetName()), srcDir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// rmdir (into trash) the now empty source directory
|
// rmdir (into trash) the now empty source directory
|
||||||
@@ -1124,7 +1131,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
|
|
||||||
var u *mega.Upload
|
var u *mega.Upload
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
u, err = o.fs.srv.NewUpload(dirNode, enc.FromStandardName(leaf), size)
|
u, err = o.fs.srv.NewUpload(dirNode, o.fs.opt.Enc.FromStandardName(leaf), size)
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,624 @@
|
|||||||
|
// Package memory provides an interface to an in memory object storage system
|
||||||
|
package memory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/fs/walk"
|
||||||
|
"github.com/rclone/rclone/lib/bucket"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
hashType = hash.MD5
|
||||||
|
// the object storage is persistent
|
||||||
|
buckets = newBucketsInfo()
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register with Fs
|
||||||
|
func init() {
|
||||||
|
fs.Register(&fs.RegInfo{
|
||||||
|
Name: "memory",
|
||||||
|
Description: "In memory object storage system.",
|
||||||
|
NewFs: NewFs,
|
||||||
|
Options: []fs.Option{},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Options defines the configuration for this backend
|
||||||
|
type Options struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fs represents a remote memory server
|
||||||
|
type Fs struct {
|
||||||
|
name string // name of this remote
|
||||||
|
root string // the path we are working on if any
|
||||||
|
opt Options // parsed config options
|
||||||
|
rootBucket string // bucket part of root (if any)
|
||||||
|
rootDirectory string // directory part of root (if any)
|
||||||
|
features *fs.Features // optional features
|
||||||
|
}
|
||||||
|
|
||||||
|
// bucketsInfo holds info about all the buckets
|
||||||
|
type bucketsInfo struct {
|
||||||
|
mu sync.RWMutex
|
||||||
|
buckets map[string]*bucketInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBucketsInfo() *bucketsInfo {
|
||||||
|
return &bucketsInfo{
|
||||||
|
buckets: make(map[string]*bucketInfo, 16),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getBucket gets a names bucket or nil
|
||||||
|
func (bi *bucketsInfo) getBucket(name string) (b *bucketInfo) {
|
||||||
|
bi.mu.RLock()
|
||||||
|
b = bi.buckets[name]
|
||||||
|
bi.mu.RUnlock()
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// makeBucket returns the bucket or makes it
|
||||||
|
func (bi *bucketsInfo) makeBucket(name string) (b *bucketInfo) {
|
||||||
|
bi.mu.Lock()
|
||||||
|
defer bi.mu.Unlock()
|
||||||
|
b = bi.buckets[name]
|
||||||
|
if b != nil {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
b = newBucketInfo()
|
||||||
|
bi.buckets[name] = b
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// deleteBucket deleted the bucket or returns an error
|
||||||
|
func (bi *bucketsInfo) deleteBucket(name string) error {
|
||||||
|
bi.mu.Lock()
|
||||||
|
defer bi.mu.Unlock()
|
||||||
|
b := bi.buckets[name]
|
||||||
|
if b == nil {
|
||||||
|
return fs.ErrorDirNotFound
|
||||||
|
}
|
||||||
|
if !b.isEmpty() {
|
||||||
|
return fs.ErrorDirectoryNotEmpty
|
||||||
|
}
|
||||||
|
delete(bi.buckets, name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getObjectData gets an object from (bucketName, bucketPath) or nil
|
||||||
|
func (bi *bucketsInfo) getObjectData(bucketName, bucketPath string) (od *objectData) {
|
||||||
|
b := bi.getBucket(bucketName)
|
||||||
|
if b == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return b.getObjectData(bucketPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateObjectData updates an object from (bucketName, bucketPath)
|
||||||
|
func (bi *bucketsInfo) updateObjectData(bucketName, bucketPath string, od *objectData) {
|
||||||
|
b := bi.makeBucket(bucketName)
|
||||||
|
b.mu.Lock()
|
||||||
|
b.objects[bucketPath] = od
|
||||||
|
b.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// removeObjectData removes an object from (bucketName, bucketPath) returning true if removed
|
||||||
|
func (bi *bucketsInfo) removeObjectData(bucketName, bucketPath string) (removed bool) {
|
||||||
|
b := bi.getBucket(bucketName)
|
||||||
|
if b != nil {
|
||||||
|
b.mu.Lock()
|
||||||
|
od := b.objects[bucketPath]
|
||||||
|
if od != nil {
|
||||||
|
delete(b.objects, bucketPath)
|
||||||
|
removed = true
|
||||||
|
}
|
||||||
|
b.mu.Unlock()
|
||||||
|
}
|
||||||
|
return removed
|
||||||
|
}
|
||||||
|
|
||||||
|
// bucketInfo holds info about a single bucket
|
||||||
|
type bucketInfo struct {
|
||||||
|
mu sync.RWMutex
|
||||||
|
objects map[string]*objectData
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBucketInfo() *bucketInfo {
|
||||||
|
return &bucketInfo{
|
||||||
|
objects: make(map[string]*objectData, 16),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getBucket gets a names bucket or nil
|
||||||
|
func (bi *bucketInfo) getObjectData(name string) (od *objectData) {
|
||||||
|
bi.mu.RLock()
|
||||||
|
od = bi.objects[name]
|
||||||
|
bi.mu.RUnlock()
|
||||||
|
return od
|
||||||
|
}
|
||||||
|
|
||||||
|
// getBucket gets a names bucket or nil
|
||||||
|
func (bi *bucketInfo) isEmpty() (empty bool) {
|
||||||
|
bi.mu.RLock()
|
||||||
|
empty = len(bi.objects) == 0
|
||||||
|
bi.mu.RUnlock()
|
||||||
|
return empty
|
||||||
|
}
|
||||||
|
|
||||||
|
// the object data and metadata
|
||||||
|
type objectData struct {
|
||||||
|
modTime time.Time
|
||||||
|
hash string
|
||||||
|
mimeType string
|
||||||
|
data []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Object describes a memory object
|
||||||
|
type Object struct {
|
||||||
|
fs *Fs // what this object is part of
|
||||||
|
remote string // The remote path
|
||||||
|
od *objectData // the object data
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Name of the remote (as passed into NewFs)
|
||||||
|
func (f *Fs) Name() string {
|
||||||
|
return f.name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root of the remote (as passed into NewFs)
|
||||||
|
func (f *Fs) Root() string {
|
||||||
|
return f.root
|
||||||
|
}
|
||||||
|
|
||||||
|
// String converts this Fs to a string
|
||||||
|
func (f *Fs) String() string {
|
||||||
|
return fmt.Sprintf("Memory root '%s'", f.root)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Features returns the optional features of this Fs
|
||||||
|
func (f *Fs) Features() *fs.Features {
|
||||||
|
return f.features
|
||||||
|
}
|
||||||
|
|
||||||
|
// parsePath parses a remote 'url'
|
||||||
|
func parsePath(path string) (root string) {
|
||||||
|
root = strings.Trim(path, "/")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// split returns bucket and bucketPath from the rootRelativePath
|
||||||
|
// relative to f.root
|
||||||
|
func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) {
|
||||||
|
return bucket.Split(path.Join(f.root, rootRelativePath))
|
||||||
|
}
|
||||||
|
|
||||||
|
// split returns bucket and bucketPath from the object
|
||||||
|
func (o *Object) split() (bucket, bucketPath string) {
|
||||||
|
return o.fs.split(o.remote)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setRoot changes the root of the Fs
|
||||||
|
func (f *Fs) setRoot(root string) {
|
||||||
|
f.root = parsePath(root)
|
||||||
|
f.rootBucket, f.rootDirectory = bucket.Split(f.root)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFs contstructs an Fs from the path, bucket:path
|
||||||
|
func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
||||||
|
// Parse config into Options struct
|
||||||
|
opt := new(Options)
|
||||||
|
err := configstruct.Set(m, opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
root = strings.Trim(root, "/")
|
||||||
|
f := &Fs{
|
||||||
|
name: name,
|
||||||
|
root: root,
|
||||||
|
opt: *opt,
|
||||||
|
}
|
||||||
|
f.setRoot(root)
|
||||||
|
f.features = (&fs.Features{
|
||||||
|
ReadMimeType: true,
|
||||||
|
WriteMimeType: true,
|
||||||
|
BucketBased: true,
|
||||||
|
BucketBasedRootOK: true,
|
||||||
|
}).Fill(f)
|
||||||
|
if f.rootBucket != "" && f.rootDirectory != "" {
|
||||||
|
od := buckets.getObjectData(f.rootBucket, f.rootDirectory)
|
||||||
|
if od != nil {
|
||||||
|
newRoot := path.Dir(f.root)
|
||||||
|
if newRoot == "." {
|
||||||
|
newRoot = ""
|
||||||
|
}
|
||||||
|
f.setRoot(newRoot)
|
||||||
|
// return an error with an fs which points to the parent
|
||||||
|
err = fs.ErrorIsFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// newObject makes an object from a remote and an objectData
|
||||||
|
func (f *Fs) newObject(remote string, od *objectData) *Object {
|
||||||
|
return &Object{fs: f, remote: remote, od: od}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewObject finds the Object at remote. If it can't be found
|
||||||
|
// it returns the error fs.ErrorObjectNotFound.
|
||||||
|
func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
|
||||||
|
bucket, bucketPath := f.split(remote)
|
||||||
|
od := buckets.getObjectData(bucket, bucketPath)
|
||||||
|
if od == nil {
|
||||||
|
return nil, fs.ErrorObjectNotFound
|
||||||
|
}
|
||||||
|
return f.newObject(remote, od), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// listFn is called from list to handle an object.
|
||||||
|
type listFn func(remote string, entry fs.DirEntry, isDirectory bool) error
|
||||||
|
|
||||||
|
// list the buckets to fn
|
||||||
|
func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBucket bool, recurse bool, fn listFn) (err error) {
|
||||||
|
if prefix != "" {
|
||||||
|
prefix += "/"
|
||||||
|
}
|
||||||
|
if directory != "" {
|
||||||
|
directory += "/"
|
||||||
|
}
|
||||||
|
b := buckets.getBucket(bucket)
|
||||||
|
if b == nil {
|
||||||
|
return fs.ErrorDirNotFound
|
||||||
|
}
|
||||||
|
b.mu.RLock()
|
||||||
|
defer b.mu.RUnlock()
|
||||||
|
dirs := make(map[string]struct{})
|
||||||
|
for absPath, od := range b.objects {
|
||||||
|
if strings.HasPrefix(absPath, directory) {
|
||||||
|
remote := absPath[len(prefix):]
|
||||||
|
if !recurse {
|
||||||
|
localPath := absPath[len(directory):]
|
||||||
|
slash := strings.IndexRune(localPath, '/')
|
||||||
|
if slash >= 0 {
|
||||||
|
// send a directory if have a slash
|
||||||
|
dir := directory + localPath[:slash]
|
||||||
|
if addBucket {
|
||||||
|
dir = path.Join(bucket, dir)
|
||||||
|
}
|
||||||
|
_, found := dirs[dir]
|
||||||
|
if !found {
|
||||||
|
err = fn(dir, fs.NewDir(dir, time.Time{}), true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
dirs[dir] = struct{}{}
|
||||||
|
}
|
||||||
|
continue // don't send this file if not recursing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// send an object
|
||||||
|
if addBucket {
|
||||||
|
remote = path.Join(bucket, remote)
|
||||||
|
}
|
||||||
|
err = fn(remote, f.newObject(remote, od), false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// listDir lists the bucket to the entries
|
||||||
|
func (f *Fs) listDir(ctx context.Context, bucket, directory, prefix string, addBucket bool) (entries fs.DirEntries, err error) {
|
||||||
|
// List the objects and directories
|
||||||
|
err = f.list(ctx, bucket, directory, prefix, addBucket, false, func(remote string, entry fs.DirEntry, isDirectory bool) error {
|
||||||
|
entries = append(entries, entry)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return entries, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// listBuckets lists the buckets to entries
|
||||||
|
func (f *Fs) listBuckets(ctx context.Context) (entries fs.DirEntries, err error) {
|
||||||
|
buckets.mu.RLock()
|
||||||
|
defer buckets.mu.RUnlock()
|
||||||
|
for name := range buckets.buckets {
|
||||||
|
entries = append(entries, fs.NewDir(name, time.Time{}))
|
||||||
|
}
|
||||||
|
return entries, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error) {
|
||||||
|
// defer fslog.Trace(dir, "")("entries = %q, err = %v", &entries, &err)
|
||||||
|
bucket, directory := f.split(dir)
|
||||||
|
if bucket == "" {
|
||||||
|
if directory != "" {
|
||||||
|
return nil, fs.ErrorListBucketRequired
|
||||||
|
}
|
||||||
|
return f.listBuckets(ctx)
|
||||||
|
}
|
||||||
|
return f.listDir(ctx, bucket, directory, f.rootDirectory, f.rootBucket == "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListR lists the objects and directories of the Fs starting
|
||||||
|
// from dir recursively into out.
|
||||||
|
//
|
||||||
|
// dir should be "" to start from the root, and should not
|
||||||
|
// have trailing slashes.
|
||||||
|
//
|
||||||
|
// This should return ErrDirNotFound if the directory isn't
|
||||||
|
// found.
|
||||||
|
//
|
||||||
|
// It should call callback for each tranche of entries read.
|
||||||
|
// These need not be returned in any particular order. If
|
||||||
|
// callback returns an error then the listing will stop
|
||||||
|
// immediately.
|
||||||
|
//
|
||||||
|
// Don't implement this unless you have a more efficient way
|
||||||
|
// of listing recursively that doing a directory traversal.
|
||||||
|
func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) (err error) {
|
||||||
|
bucket, directory := f.split(dir)
|
||||||
|
list := walk.NewListRHelper(callback)
|
||||||
|
listR := func(bucket, directory, prefix string, addBucket bool) error {
|
||||||
|
return f.list(ctx, bucket, directory, prefix, addBucket, true, func(remote string, entry fs.DirEntry, isDirectory bool) error {
|
||||||
|
return list.Add(entry)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if bucket == "" {
|
||||||
|
entries, err := f.listBuckets(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
err = list.Add(entry)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bucket := entry.Remote()
|
||||||
|
err = listR(bucket, "", f.rootDirectory, true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = listR(bucket, directory, f.rootDirectory, f.rootBucket == "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put the object into the bucket
|
||||||
|
//
|
||||||
|
// Copy the reader in to the new object which is returned
|
||||||
|
//
|
||||||
|
// The new object may have been created if an error is returned
|
||||||
|
func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error) {
|
||||||
|
// Temporary Object under construction
|
||||||
|
fs := &Object{
|
||||||
|
fs: f,
|
||||||
|
remote: src.Remote(),
|
||||||
|
od: &objectData{
|
||||||
|
modTime: src.ModTime(ctx),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return fs, fs.Update(ctx, in, src, options...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PutStream uploads to the remote path with the modTime given of indeterminate size
|
||||||
|
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...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mkdir creates the bucket if it doesn't exist
|
||||||
|
func (f *Fs) Mkdir(ctx context.Context, dir string) error {
|
||||||
|
bucket, _ := f.split(dir)
|
||||||
|
buckets.makeBucket(bucket)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rmdir deletes the bucket if the fs is at the root
|
||||||
|
//
|
||||||
|
// Returns an error if it isn't empty
|
||||||
|
func (f *Fs) Rmdir(ctx context.Context, dir string) error {
|
||||||
|
bucket, directory := f.split(dir)
|
||||||
|
if bucket == "" || directory != "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return buckets.deleteBucket(bucket)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Precision of the remote
|
||||||
|
func (f *Fs) Precision() time.Duration {
|
||||||
|
return time.Nanosecond
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy src to this remote using server side copy operations.
|
||||||
|
//
|
||||||
|
// This is stored with the remote path given
|
||||||
|
//
|
||||||
|
// It returns the destination Object and a possible error
|
||||||
|
//
|
||||||
|
// Will only be called if src.Fs().Name() == f.Name()
|
||||||
|
//
|
||||||
|
// If it isn't possible then return fs.ErrorCantCopy
|
||||||
|
func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) {
|
||||||
|
dstBucket, dstPath := f.split(remote)
|
||||||
|
_ = buckets.makeBucket(dstBucket)
|
||||||
|
srcObj, ok := src.(*Object)
|
||||||
|
if !ok {
|
||||||
|
fs.Debugf(src, "Can't copy - not same remote type")
|
||||||
|
return nil, fs.ErrorCantCopy
|
||||||
|
}
|
||||||
|
srcBucket, srcPath := srcObj.split()
|
||||||
|
od := buckets.getObjectData(srcBucket, srcPath)
|
||||||
|
if od == nil {
|
||||||
|
return nil, fs.ErrorObjectNotFound
|
||||||
|
}
|
||||||
|
buckets.updateObjectData(dstBucket, dstPath, od)
|
||||||
|
return f.NewObject(ctx, remote)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hashes returns the supported hash sets.
|
||||||
|
func (f *Fs) Hashes() hash.Set {
|
||||||
|
return hash.Set(hashType)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Fs returns the parent Fs
|
||||||
|
func (o *Object) Fs() fs.Info {
|
||||||
|
return o.fs
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a string version
|
||||||
|
func (o *Object) String() string {
|
||||||
|
if o == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
|
return o.Remote()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remote returns the remote path
|
||||||
|
func (o *Object) Remote() string {
|
||||||
|
return o.remote
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hash returns the hash of an object returning a lowercase hex string
|
||||||
|
func (o *Object) Hash(ctx context.Context, t hash.Type) (string, error) {
|
||||||
|
if t != hashType {
|
||||||
|
return "", hash.ErrUnsupported
|
||||||
|
}
|
||||||
|
if o.od.hash == "" {
|
||||||
|
sum := md5.Sum(o.od.data)
|
||||||
|
o.od.hash = hex.EncodeToString(sum[:])
|
||||||
|
}
|
||||||
|
return o.od.hash, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size returns the size of an object in bytes
|
||||||
|
func (o *Object) Size() int64 {
|
||||||
|
return int64(len(o.od.data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
// SHA-1 will also be updated once the request has completed.
|
||||||
|
func (o *Object) ModTime(ctx context.Context) (result time.Time) {
|
||||||
|
return o.od.modTime
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModTime sets the modification time of the local fs object
|
||||||
|
func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error {
|
||||||
|
o.od.modTime = modTime
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Storable returns if this object is storable
|
||||||
|
func (o *Object) Storable() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open an object for read
|
||||||
|
func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
||||||
|
var offset, limit int64 = 0, -1
|
||||||
|
for _, option := range options {
|
||||||
|
switch x := option.(type) {
|
||||||
|
case *fs.RangeOption:
|
||||||
|
offset, limit = x.Decode(int64(len(o.od.data)))
|
||||||
|
case *fs.SeekOption:
|
||||||
|
offset = x.Offset
|
||||||
|
default:
|
||||||
|
if option.Mandatory() {
|
||||||
|
fs.Logf(o, "Unsupported mandatory option: %v", option)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if offset > int64(len(o.od.data)) {
|
||||||
|
offset = int64(len(o.od.data))
|
||||||
|
}
|
||||||
|
data := o.od.data[offset:]
|
||||||
|
if limit >= 0 {
|
||||||
|
if limit > int64(len(data)) {
|
||||||
|
limit = int64(len(data))
|
||||||
|
}
|
||||||
|
data = data[:limit]
|
||||||
|
}
|
||||||
|
return ioutil.NopCloser(bytes.NewBuffer(data)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the object with the contents of the io.Reader, modTime and size
|
||||||
|
//
|
||||||
|
// The new object may have been created if an error is returned
|
||||||
|
func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (err error) {
|
||||||
|
bucket, bucketPath := o.split()
|
||||||
|
data, err := ioutil.ReadAll(in)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to update memory object")
|
||||||
|
}
|
||||||
|
o.od = &objectData{
|
||||||
|
data: data,
|
||||||
|
hash: "",
|
||||||
|
modTime: src.ModTime(ctx),
|
||||||
|
mimeType: fs.MimeType(ctx, o),
|
||||||
|
}
|
||||||
|
buckets.updateObjectData(bucket, bucketPath, o.od)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove an object
|
||||||
|
func (o *Object) Remove(ctx context.Context) error {
|
||||||
|
bucket, bucketPath := o.split()
|
||||||
|
removed := buckets.removeObjectData(bucket, bucketPath)
|
||||||
|
if !removed {
|
||||||
|
return fs.ErrorObjectNotFound
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MimeType of an Object if known, "" otherwise
|
||||||
|
func (o *Object) MimeType(ctx context.Context) string {
|
||||||
|
return o.od.mimeType
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the interfaces are satisfied
|
||||||
|
var (
|
||||||
|
_ fs.Fs = &Fs{}
|
||||||
|
_ fs.Copier = &Fs{}
|
||||||
|
_ fs.PutStreamer = &Fs{}
|
||||||
|
_ fs.ListRer = &Fs{}
|
||||||
|
_ fs.Object = &Object{}
|
||||||
|
_ fs.MimeTyper = &Object{}
|
||||||
|
)
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// Test memory filesystem interface
|
||||||
|
package memory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/fstest/fstests"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestIntegration runs integration tests against the remote
|
||||||
|
func TestIntegration(t *testing.T) {
|
||||||
|
fstests.Run(t, &fstests.Opt{
|
||||||
|
RemoteName: ":memory:",
|
||||||
|
NilObject: (*Object)(nil),
|
||||||
|
})
|
||||||
|
}
|
||||||
+149
-33
@@ -12,6 +12,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -23,11 +24,11 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/atexit"
|
"github.com/rclone/rclone/lib/atexit"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
@@ -35,8 +36,6 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.OneDrive
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "b15665d9-eda6-4092-8539-0eec376afd59"
|
rcloneClientID = "b15665d9-eda6-4092-8539-0eec376afd59"
|
||||||
rcloneEncryptedClientSecret = "_JUdzh3LnKNqSPcf4Wu5fgMFIQOI8glZu_akYgR8yf6egowNBg-R"
|
rcloneEncryptedClientSecret = "_JUdzh3LnKNqSPcf4Wu5fgMFIQOI8glZu_akYgR8yf6egowNBg-R"
|
||||||
@@ -61,7 +60,7 @@ var (
|
|||||||
AuthURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
|
AuthURL: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
|
||||||
TokenURL: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
|
TokenURL: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
|
||||||
},
|
},
|
||||||
Scopes: []string{"Files.Read", "Files.ReadWrite", "Files.Read.All", "Files.ReadWrite.All", "offline_access"},
|
Scopes: []string{"Files.Read", "Files.ReadWrite", "Files.Read.All", "Files.ReadWrite.All", "offline_access", "Sites.Read.All"},
|
||||||
ClientID: rcloneClientID,
|
ClientID: rcloneClientID,
|
||||||
ClientSecret: obscure.MustReveal(rcloneEncryptedClientSecret),
|
ClientSecret: obscure.MustReveal(rcloneEncryptedClientSecret),
|
||||||
RedirectURL: oauthutil.RedirectLocalhostURL,
|
RedirectURL: oauthutil.RedirectLocalhostURL,
|
||||||
@@ -252,16 +251,63 @@ delete OneNote files or otherwise want them to show up in directory
|
|||||||
listing, set this option.`,
|
listing, set this option.`,
|
||||||
Default: false,
|
Default: false,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// List of replaced characters:
|
||||||
|
// < (less than) -> '<' // FULLWIDTH LESS-THAN SIGN
|
||||||
|
// > (greater than) -> '>' // FULLWIDTH GREATER-THAN SIGN
|
||||||
|
// : (colon) -> ':' // FULLWIDTH COLON
|
||||||
|
// " (double quote) -> '"' // FULLWIDTH QUOTATION MARK
|
||||||
|
// \ (backslash) -> '\' // FULLWIDTH REVERSE SOLIDUS
|
||||||
|
// | (vertical line) -> '|' // FULLWIDTH VERTICAL LINE
|
||||||
|
// ? (question mark) -> '?' // FULLWIDTH QUESTION MARK
|
||||||
|
// * (asterisk) -> '*' // FULLWIDTH ASTERISK
|
||||||
|
// # (number sign) -> '#' // FULLWIDTH NUMBER SIGN
|
||||||
|
// % (percent sign) -> '%' // FULLWIDTH PERCENT SIGN
|
||||||
|
//
|
||||||
|
// Folder names cannot begin with a tilde ('~')
|
||||||
|
// List of replaced characters:
|
||||||
|
// ~ (tilde) -> '~' // FULLWIDTH TILDE
|
||||||
|
//
|
||||||
|
// Additionally names can't begin with a space ( ) or end with a period (.) or space ( ).
|
||||||
|
// List of replaced characters:
|
||||||
|
// . (period) -> '.' // FULLWIDTH FULL STOP
|
||||||
|
// (space) -> '␠' // SYMBOL FOR SPACE
|
||||||
|
//
|
||||||
|
// Also encode invalid UTF-8 bytes as json doesn't handle them.
|
||||||
|
//
|
||||||
|
// The OneDrive API documentation lists the set of reserved characters, but
|
||||||
|
// testing showed this list is incomplete. This are the differences:
|
||||||
|
// - " (double quote) is rejected, but missing in the documentation
|
||||||
|
// - space at the end of file and folder names is rejected, but missing in the documentation
|
||||||
|
// - period at the end of file names is rejected, but missing in the documentation
|
||||||
|
//
|
||||||
|
// Adding these restrictions to the OneDrive API documentation yields exactly
|
||||||
|
// the same rules as the Windows naming conventions.
|
||||||
|
//
|
||||||
|
// https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/addressing-driveitems?view=odsp-graph-online#path-encoding
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeHashPercent |
|
||||||
|
encoder.EncodeLeftSpace |
|
||||||
|
encoder.EncodeLeftTilde |
|
||||||
|
encoder.EncodeRightPeriod |
|
||||||
|
encoder.EncodeRightSpace |
|
||||||
|
encoder.EncodeWin |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
DriveID string `config:"drive_id"`
|
DriveID string `config:"drive_id"`
|
||||||
DriveType string `config:"drive_type"`
|
DriveType string `config:"drive_type"`
|
||||||
ExposeOneNoteFiles bool `config:"expose_onenote_files"`
|
ExposeOneNoteFiles bool `config:"expose_onenote_files"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote one drive
|
// Fs represents a remote one drive
|
||||||
@@ -335,13 +381,30 @@ var retryErrorCodes = []int{
|
|||||||
// shouldRetry returns a boolean as to whether this resp and err
|
// shouldRetry returns a boolean as to whether this resp and err
|
||||||
// deserve to be retried. It returns the err as a convenience
|
// deserve to be retried. It returns the err as a convenience
|
||||||
func shouldRetry(resp *http.Response, err error) (bool, error) {
|
func shouldRetry(resp *http.Response, err error) (bool, error) {
|
||||||
authRetry := false
|
retry := false
|
||||||
|
if resp != nil {
|
||||||
if resp != nil && resp.StatusCode == 401 && len(resp.Header["Www-Authenticate"]) == 1 && strings.Index(resp.Header["Www-Authenticate"][0], "expired_token") >= 0 {
|
switch resp.StatusCode {
|
||||||
authRetry = true
|
case 401:
|
||||||
fs.Debugf(nil, "Should retry: %v", err)
|
if len(resp.Header["Www-Authenticate"]) == 1 && strings.Index(resp.Header["Www-Authenticate"][0], "expired_token") >= 0 {
|
||||||
|
retry = true
|
||||||
|
fs.Debugf(nil, "Should retry: %v", err)
|
||||||
|
}
|
||||||
|
case 429: // Too Many Requests.
|
||||||
|
// see https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online
|
||||||
|
if values := resp.Header["Retry-After"]; len(values) == 1 && values[0] != "" {
|
||||||
|
retryAfter, parseErr := strconv.Atoi(values[0])
|
||||||
|
if parseErr != nil {
|
||||||
|
fs.Debugf(nil, "Failed to parse Retry-After: %q: %v", values[0], parseErr)
|
||||||
|
} else {
|
||||||
|
duration := time.Second * time.Duration(retryAfter)
|
||||||
|
retry = true
|
||||||
|
err = pacer.RetryAfterError(err, duration)
|
||||||
|
fs.Debugf(nil, "Too many requests. Trying again in %d seconds.", retryAfter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return authRetry || fserrors.ShouldRetry(err) || fserrors.ShouldRetryHTTP(resp, retryErrorCodes), err
|
return retry || fserrors.ShouldRetry(err) || fserrors.ShouldRetryHTTP(resp, retryErrorCodes), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// readMetaDataForPathRelativeToID reads the metadata for a path relative to an item that is addressed by its normalized ID.
|
// readMetaDataForPathRelativeToID reads the metadata for a path relative to an item that is addressed by its normalized ID.
|
||||||
@@ -355,7 +418,7 @@ func shouldRetry(resp *http.Response, err error) (bool, error) {
|
|||||||
// If `relPath` == '', do not append the slash (See #3664)
|
// If `relPath` == '', do not append the slash (See #3664)
|
||||||
func (f *Fs) readMetaDataForPathRelativeToID(ctx context.Context, normalizedID string, relPath string) (info *api.Item, resp *http.Response, err error) {
|
func (f *Fs) readMetaDataForPathRelativeToID(ctx context.Context, normalizedID string, relPath string) (info *api.Item, resp *http.Response, err error) {
|
||||||
if relPath != "" {
|
if relPath != "" {
|
||||||
relPath = "/" + withTrailingColon(rest.URLPathEscape(enc.FromStandardPath(relPath)))
|
relPath = "/" + withTrailingColon(rest.URLPathEscape(f.opt.Enc.FromStandardPath(relPath)))
|
||||||
}
|
}
|
||||||
opts := newOptsCall(normalizedID, "GET", ":"+relPath)
|
opts := newOptsCall(normalizedID, "GET", ":"+relPath)
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@@ -380,7 +443,7 @@ func (f *Fs) readMetaDataForPath(ctx context.Context, path string) (info *api.It
|
|||||||
} else {
|
} else {
|
||||||
opts = rest.Opts{
|
opts = rest.Opts{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: "/root:/" + rest.URLPathEscape(enc.FromStandardPath(path)),
|
Path: "/root:/" + rest.URLPathEscape(f.opt.Enc.FromStandardPath(path)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@@ -628,7 +691,7 @@ func (f *Fs) CreateDir(ctx context.Context, dirID, leaf string) (newID string, e
|
|||||||
var info *api.Item
|
var info *api.Item
|
||||||
opts := newOptsCall(dirID, "POST", "/children")
|
opts := newOptsCall(dirID, "POST", "/children")
|
||||||
mkdir := api.CreateItemRequest{
|
mkdir := api.CreateItemRequest{
|
||||||
Name: enc.FromStandardName(leaf),
|
Name: f.opt.Enc.FromStandardName(leaf),
|
||||||
ConflictBehavior: "fail",
|
ConflictBehavior: "fail",
|
||||||
}
|
}
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@@ -688,7 +751,7 @@ OUTER:
|
|||||||
if item.Deleted != nil {
|
if item.Deleted != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
item.Name = enc.ToStandardName(item.GetName())
|
item.Name = f.opt.Enc.ToStandardName(item.GetName())
|
||||||
if fn(item) {
|
if fn(item) {
|
||||||
found = true
|
found = true
|
||||||
break OUTER
|
break OUTER
|
||||||
@@ -944,7 +1007,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
|
|
||||||
id, dstDriveID, _ := parseNormalizedID(directoryID)
|
id, dstDriveID, _ := parseNormalizedID(directoryID)
|
||||||
|
|
||||||
replacedLeaf := enc.FromStandardName(leaf)
|
replacedLeaf := f.opt.Enc.FromStandardName(leaf)
|
||||||
copyReq := api.CopyItemRequest{
|
copyReq := api.CopyItemRequest{
|
||||||
Name: &replacedLeaf,
|
Name: &replacedLeaf,
|
||||||
ParentReference: api.ItemReference{
|
ParentReference: api.ItemReference{
|
||||||
@@ -1028,7 +1091,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
opts := newOptsCall(srcObj.id, "PATCH", "")
|
opts := newOptsCall(srcObj.id, "PATCH", "")
|
||||||
|
|
||||||
move := api.MoveItemRequest{
|
move := api.MoveItemRequest{
|
||||||
Name: enc.FromStandardName(leaf),
|
Name: f.opt.Enc.FromStandardName(leaf),
|
||||||
ParentReference: &api.ItemReference{
|
ParentReference: &api.ItemReference{
|
||||||
DriveID: dstDriveID,
|
DriveID: dstDriveID,
|
||||||
ID: id,
|
ID: id,
|
||||||
@@ -1143,7 +1206,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
// Do the move
|
// Do the move
|
||||||
opts := newOptsCall(srcID, "PATCH", "")
|
opts := newOptsCall(srcID, "PATCH", "")
|
||||||
move := api.MoveItemRequest{
|
move := api.MoveItemRequest{
|
||||||
Name: enc.FromStandardName(leaf),
|
Name: f.opt.Enc.FromStandardName(leaf),
|
||||||
ParentReference: &api.ItemReference{
|
ParentReference: &api.ItemReference{
|
||||||
DriveID: dstDriveID,
|
DriveID: dstDriveID,
|
||||||
ID: parsedDstDirID,
|
ID: parsedDstDirID,
|
||||||
@@ -1265,7 +1328,7 @@ func (o *Object) rootPath() string {
|
|||||||
|
|
||||||
// srvPath returns a path for use in server given a remote
|
// srvPath returns a path for use in server given a remote
|
||||||
func (f *Fs) srvPath(remote string) string {
|
func (f *Fs) srvPath(remote string) string {
|
||||||
return enc.FromStandardPath(f.rootSlash() + remote)
|
return f.opt.Enc.FromStandardPath(f.rootSlash() + remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
// srvPath returns a path for use in server
|
// srvPath returns a path for use in server
|
||||||
@@ -1377,7 +1440,7 @@ func (o *Object) setModTime(ctx context.Context, modTime time.Time) (*api.Item,
|
|||||||
opts = rest.Opts{
|
opts = rest.Opts{
|
||||||
Method: "PATCH",
|
Method: "PATCH",
|
||||||
RootURL: rootURL,
|
RootURL: rootURL,
|
||||||
Path: "/" + drive + "/items/" + trueDirID + ":/" + withTrailingColon(rest.URLPathEscape(enc.FromStandardName(leaf))),
|
Path: "/" + drive + "/items/" + trueDirID + ":/" + withTrailingColon(rest.URLPathEscape(o.fs.opt.Enc.FromStandardName(leaf))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
opts = rest.Opts{
|
opts = rest.Opts{
|
||||||
@@ -1452,7 +1515,7 @@ func (o *Object) createUploadSession(ctx context.Context, modTime time.Time) (re
|
|||||||
Method: "POST",
|
Method: "POST",
|
||||||
RootURL: rootURL,
|
RootURL: rootURL,
|
||||||
Path: fmt.Sprintf("/%s/items/%s:/%s:/createUploadSession",
|
Path: fmt.Sprintf("/%s/items/%s:/%s:/createUploadSession",
|
||||||
drive, id, rest.URLPathEscape(enc.FromStandardName(leaf))),
|
drive, id, rest.URLPathEscape(o.fs.opt.Enc.FromStandardName(leaf))),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
opts = rest.Opts{
|
opts = rest.Opts{
|
||||||
@@ -1477,21 +1540,74 @@ func (o *Object) createUploadSession(ctx context.Context, modTime time.Time) (re
|
|||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getPosition gets the current position in a multipart upload
|
||||||
|
func (o *Object) getPosition(ctx context.Context, url string) (pos int64, err error) {
|
||||||
|
opts := rest.Opts{
|
||||||
|
Method: "GET",
|
||||||
|
RootURL: url,
|
||||||
|
}
|
||||||
|
var info api.UploadFragmentResponse
|
||||||
|
var resp *http.Response
|
||||||
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
|
resp, err = o.fs.srv.CallJSON(ctx, &opts, nil, &info)
|
||||||
|
return shouldRetry(resp, err)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if len(info.NextExpectedRanges) != 1 {
|
||||||
|
return 0, errors.Errorf("bad number of ranges in upload position: %v", info.NextExpectedRanges)
|
||||||
|
}
|
||||||
|
position := info.NextExpectedRanges[0]
|
||||||
|
i := strings.IndexByte(position, '-')
|
||||||
|
if i < 0 {
|
||||||
|
return 0, errors.Errorf("no '-' in next expected range: %q", position)
|
||||||
|
}
|
||||||
|
position = position[:i]
|
||||||
|
pos, err = strconv.ParseInt(position, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.Wrapf(err, "bad expected range: %q", position)
|
||||||
|
}
|
||||||
|
return pos, nil
|
||||||
|
}
|
||||||
|
|
||||||
// uploadFragment uploads a part
|
// uploadFragment uploads a part
|
||||||
func (o *Object) uploadFragment(ctx context.Context, url string, start int64, totalSize int64, chunk io.ReadSeeker, chunkSize int64) (info *api.Item, err error) {
|
func (o *Object) uploadFragment(ctx context.Context, url string, start int64, totalSize int64, chunk io.ReadSeeker, chunkSize int64) (info *api.Item, err error) {
|
||||||
opts := rest.Opts{
|
|
||||||
Method: "PUT",
|
|
||||||
RootURL: url,
|
|
||||||
ContentLength: &chunkSize,
|
|
||||||
ContentRange: fmt.Sprintf("bytes %d-%d/%d", start, start+chunkSize-1, totalSize),
|
|
||||||
Body: chunk,
|
|
||||||
}
|
|
||||||
// var response api.UploadFragmentResponse
|
// var response api.UploadFragmentResponse
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var body []byte
|
var body []byte
|
||||||
|
var skip = int64(0)
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
_, _ = chunk.Seek(0, io.SeekStart)
|
toSend := chunkSize - skip
|
||||||
|
opts := rest.Opts{
|
||||||
|
Method: "PUT",
|
||||||
|
RootURL: url,
|
||||||
|
ContentLength: &toSend,
|
||||||
|
ContentRange: fmt.Sprintf("bytes %d-%d/%d", start+skip, start+chunkSize-1, totalSize),
|
||||||
|
Body: chunk,
|
||||||
|
}
|
||||||
|
_, _ = chunk.Seek(skip, io.SeekStart)
|
||||||
resp, err = o.fs.srv.Call(ctx, &opts)
|
resp, err = o.fs.srv.Call(ctx, &opts)
|
||||||
|
if err != nil && resp != nil && resp.StatusCode == http.StatusRequestedRangeNotSatisfiable {
|
||||||
|
fs.Debugf(o, "Received 416 error - reading current position from server: %v", err)
|
||||||
|
pos, posErr := o.getPosition(ctx, url)
|
||||||
|
if posErr != nil {
|
||||||
|
fs.Debugf(o, "Failed to read position: %v", posErr)
|
||||||
|
return false, posErr
|
||||||
|
}
|
||||||
|
skip = pos - start
|
||||||
|
fs.Debugf(o, "Read position %d, chunk is %d..%d, bytes to skip = %d", pos, start, start+chunkSize, skip)
|
||||||
|
switch {
|
||||||
|
case skip < 0:
|
||||||
|
return false, errors.Wrapf(err, "sent block already (skip %d < 0), can't rewind", skip)
|
||||||
|
case skip > chunkSize:
|
||||||
|
return false, errors.Wrapf(err, "position is in the future (skip %d > chunkSize %d), can't skip forward", skip, chunkSize)
|
||||||
|
case skip == chunkSize:
|
||||||
|
fs.Debugf(o, "Skipping chunk as already sent (skip %d == chunkSize %d)", skip, chunkSize)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return true, errors.Wrapf(err, "retry this chunk skipping %d bytes", skip)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return shouldRetry(resp, err)
|
return shouldRetry(resp, err)
|
||||||
}
|
}
|
||||||
@@ -1604,7 +1720,7 @@ func (o *Object) uploadSinglepart(ctx context.Context, in io.Reader, size int64,
|
|||||||
opts = rest.Opts{
|
opts = rest.Opts{
|
||||||
Method: "PUT",
|
Method: "PUT",
|
||||||
RootURL: rootURL,
|
RootURL: rootURL,
|
||||||
Path: "/" + drive + "/items/" + trueDirID + ":/" + rest.URLPathEscape(enc.FromStandardName(leaf)) + ":/content",
|
Path: "/" + drive + "/items/" + trueDirID + ":/" + rest.URLPathEscape(o.fs.opt.Enc.FromStandardName(leaf)) + ":/content",
|
||||||
ContentLength: &size,
|
ContentLength: &size,
|
||||||
Body: in,
|
Body: in,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,21 +13,20 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.OpenDrive
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultEndpoint = "https://dev.opendrive.com/api/v1"
|
defaultEndpoint = "https://dev.opendrive.com/api/v1"
|
||||||
minSleep = 10 * time.Millisecond
|
minSleep = 10 * time.Millisecond
|
||||||
@@ -50,14 +49,57 @@ func init() {
|
|||||||
Help: "Password.",
|
Help: "Password.",
|
||||||
IsPassword: true,
|
IsPassword: true,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// List of replaced characters:
|
||||||
|
// < (less than) -> '<' // FULLWIDTH LESS-THAN SIGN
|
||||||
|
// > (greater than) -> '>' // FULLWIDTH GREATER-THAN SIGN
|
||||||
|
// : (colon) -> ':' // FULLWIDTH COLON
|
||||||
|
// " (double quote) -> '"' // FULLWIDTH QUOTATION MARK
|
||||||
|
// \ (backslash) -> '\' // FULLWIDTH REVERSE SOLIDUS
|
||||||
|
// | (vertical line) -> '|' // FULLWIDTH VERTICAL LINE
|
||||||
|
// ? (question mark) -> '?' // FULLWIDTH QUESTION MARK
|
||||||
|
// * (asterisk) -> '*' // FULLWIDTH ASTERISK
|
||||||
|
//
|
||||||
|
// Additionally names can't begin or end with a ASCII whitespace.
|
||||||
|
// List of replaced characters:
|
||||||
|
// (space) -> '␠' // SYMBOL FOR SPACE
|
||||||
|
// (horizontal tab) -> '␉' // SYMBOL FOR HORIZONTAL TABULATION
|
||||||
|
// (line feed) -> '␊' // SYMBOL FOR LINE FEED
|
||||||
|
// (vertical tab) -> '␋' // SYMBOL FOR VERTICAL TABULATION
|
||||||
|
// (carriage return) -> '␍' // SYMBOL FOR CARRIAGE RETURN
|
||||||
|
//
|
||||||
|
// Also encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
//
|
||||||
|
// https://www.opendrive.com/wp-content/uploads/guides/OpenDrive_API_guide.pdf
|
||||||
|
Default: (encoder.Base |
|
||||||
|
encoder.EncodeWin |
|
||||||
|
encoder.EncodeLeftCrLfHtVt |
|
||||||
|
encoder.EncodeRightCrLfHtVt |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeLeftSpace |
|
||||||
|
encoder.EncodeRightSpace |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
|
}, {
|
||||||
|
Name: "chunk_size",
|
||||||
|
Help: `Files will be uploaded in chunks this size.
|
||||||
|
|
||||||
|
Note that these chunks are buffered in memory so increasing them will
|
||||||
|
increase memory use.`,
|
||||||
|
Default: 10 * fs.MebiByte,
|
||||||
|
Advanced: true,
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
UserName string `config:"username"`
|
UserName string `config:"username"`
|
||||||
Password string `config:"password"`
|
Password string `config:"password"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote server
|
// Fs represents a remote server
|
||||||
@@ -588,7 +630,7 @@ func (f *Fs) createObject(ctx context.Context, remote string, modTime time.Time,
|
|||||||
fs: f,
|
fs: f,
|
||||||
remote: remote,
|
remote: remote,
|
||||||
}
|
}
|
||||||
return o, enc.FromStandardName(leaf), directoryID, nil
|
return o, f.opt.Enc.FromStandardName(leaf), directoryID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readMetaDataForPath reads the metadata from the path
|
// readMetaDataForPath reads the metadata from the path
|
||||||
@@ -690,7 +732,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
createDirData := createFolder{
|
createDirData := createFolder{
|
||||||
SessionID: f.session.SessionID,
|
SessionID: f.session.SessionID,
|
||||||
FolderName: enc.FromStandardName(leaf),
|
FolderName: f.opt.Enc.FromStandardName(leaf),
|
||||||
FolderSubParent: pathID,
|
FolderSubParent: pathID,
|
||||||
FolderIsPublic: 0,
|
FolderIsPublic: 0,
|
||||||
FolderPublicUpl: 0,
|
FolderPublicUpl: 0,
|
||||||
@@ -736,7 +778,7 @@ func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut strin
|
|||||||
return "", false, errors.Wrap(err, "failed to get folder list")
|
return "", false, errors.Wrap(err, "failed to get folder list")
|
||||||
}
|
}
|
||||||
|
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = f.opt.Enc.FromStandardName(leaf)
|
||||||
for _, folder := range folderList.Folders {
|
for _, folder := range folderList.Folders {
|
||||||
// fs.Debugf(nil, "Folder: %s (%s)", folder.Name, folder.FolderID)
|
// fs.Debugf(nil, "Folder: %s (%s)", folder.Name, folder.FolderID)
|
||||||
|
|
||||||
@@ -784,7 +826,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, folder := range folderList.Folders {
|
for _, folder := range folderList.Folders {
|
||||||
folder.Name = enc.ToStandardName(folder.Name)
|
folder.Name = f.opt.Enc.ToStandardName(folder.Name)
|
||||||
// fs.Debugf(nil, "Folder: %s (%s)", folder.Name, folder.FolderID)
|
// fs.Debugf(nil, "Folder: %s (%s)", folder.Name, folder.FolderID)
|
||||||
remote := path.Join(dir, folder.Name)
|
remote := path.Join(dir, folder.Name)
|
||||||
// cache the directory ID for later lookups
|
// cache the directory ID for later lookups
|
||||||
@@ -795,7 +837,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range folderList.Files {
|
for _, file := range folderList.Files {
|
||||||
file.Name = enc.ToStandardName(file.Name)
|
file.Name = f.opt.Enc.ToStandardName(file.Name)
|
||||||
// fs.Debugf(nil, "File: %s (%s)", file.Name, file.FileID)
|
// fs.Debugf(nil, "File: %s (%s)", file.Name, file.FileID)
|
||||||
remote := path.Join(dir, file.Name)
|
remote := path.Join(dir, file.Name)
|
||||||
o, err := f.newObjectWithInfo(ctx, remote, &file)
|
o, err := f.newObjectWithInfo(ctx, remote, &file)
|
||||||
@@ -940,15 +982,13 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
// resp.Body.Close()
|
// resp.Body.Close()
|
||||||
// fs.Debugf(nil, "PostOpen: %#v", openResponse)
|
// fs.Debugf(nil, "PostOpen: %#v", openResponse)
|
||||||
|
|
||||||
// 10 MB chunks size
|
buf := make([]byte, o.fs.opt.ChunkSize)
|
||||||
chunkSize := int64(1024 * 1024 * 10)
|
|
||||||
buf := make([]byte, int(chunkSize))
|
|
||||||
chunkOffset := int64(0)
|
chunkOffset := int64(0)
|
||||||
remainingBytes := size
|
remainingBytes := size
|
||||||
chunkCounter := 0
|
chunkCounter := 0
|
||||||
|
|
||||||
for remainingBytes > 0 {
|
for remainingBytes > 0 {
|
||||||
currentChunkSize := chunkSize
|
currentChunkSize := int64(o.fs.opt.ChunkSize)
|
||||||
if currentChunkSize > remainingBytes {
|
if currentChunkSize > remainingBytes {
|
||||||
currentChunkSize = remainingBytes
|
currentChunkSize = remainingBytes
|
||||||
}
|
}
|
||||||
@@ -1050,7 +1090,7 @@ func (o *Object) readMetaData(ctx context.Context) (err error) {
|
|||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: fmt.Sprintf("/folder/itembyname.json/%s/%s?name=%s",
|
Path: fmt.Sprintf("/folder/itembyname.json/%s/%s?name=%s",
|
||||||
o.fs.session.SessionID, directoryID, url.QueryEscape(enc.FromStandardName(leaf))),
|
o.fs.session.SessionID, directoryID, url.QueryEscape(o.fs.opt.Enc.FromStandardName(leaf))),
|
||||||
}
|
}
|
||||||
resp, err = o.fs.srv.CallJSON(ctx, &opts, nil, &folderList)
|
resp, err = o.fs.srv.CallJSON(ctx, &opts, nil, &folderList)
|
||||||
return o.fs.shouldRetry(resp, err)
|
return o.fs.shouldRetry(resp, err)
|
||||||
|
|||||||
@@ -26,18 +26,16 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Pcloud
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "DnONSzyJXpm"
|
rcloneClientID = "DnONSzyJXpm"
|
||||||
rcloneEncryptedClientSecret = "ej1OIF39VOQQ0PXaSdK9ztkLw3tdLNscW2157TKNQdQKkICR4uU7aFg4eFM"
|
rcloneEncryptedClientSecret = "ej1OIF39VOQQ0PXaSdK9ztkLw3tdLNscW2157TKNQdQKkICR4uU7aFg4eFM"
|
||||||
@@ -81,12 +79,23 @@ func init() {
|
|||||||
}, {
|
}, {
|
||||||
Name: config.ConfigClientSecret,
|
Name: config.ConfigClientSecret,
|
||||||
Help: "Pcloud App Client Secret\nLeave blank normally.",
|
Help: "Pcloud App Client Secret\nLeave blank normally.",
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
//
|
||||||
|
// TODO: Investigate Unicode simplification (\ gets converted to \ server-side)
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote pcloud
|
// Fs represents a remote pcloud
|
||||||
@@ -342,7 +351,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
Path: "/createfolder",
|
Path: "/createfolder",
|
||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
opts.Parameters.Set("name", enc.FromStandardName(leaf))
|
opts.Parameters.Set("name", f.opt.Enc.FromStandardName(leaf))
|
||||||
opts.Parameters.Set("folderid", dirIDtoNumber(pathID))
|
opts.Parameters.Set("folderid", dirIDtoNumber(pathID))
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
resp, err = f.srv.CallJSON(ctx, &opts, nil, &result)
|
resp, err = f.srv.CallJSON(ctx, &opts, nil, &result)
|
||||||
@@ -418,7 +427,7 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item.Name = enc.ToStandardName(item.Name)
|
item.Name = f.opt.Enc.ToStandardName(item.Name)
|
||||||
if fn(item) {
|
if fn(item) {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@@ -610,7 +619,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
opts.Parameters.Set("fileid", fileIDtoNumber(srcObj.id))
|
opts.Parameters.Set("fileid", fileIDtoNumber(srcObj.id))
|
||||||
opts.Parameters.Set("toname", enc.FromStandardName(leaf))
|
opts.Parameters.Set("toname", f.opt.Enc.FromStandardName(leaf))
|
||||||
opts.Parameters.Set("tofolderid", dirIDtoNumber(directoryID))
|
opts.Parameters.Set("tofolderid", dirIDtoNumber(directoryID))
|
||||||
opts.Parameters.Set("mtime", fmt.Sprintf("%d", srcObj.modTime.Unix()))
|
opts.Parameters.Set("mtime", fmt.Sprintf("%d", srcObj.modTime.Unix()))
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
@@ -689,7 +698,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
opts.Parameters.Set("fileid", fileIDtoNumber(srcObj.id))
|
opts.Parameters.Set("fileid", fileIDtoNumber(srcObj.id))
|
||||||
opts.Parameters.Set("toname", enc.FromStandardName(leaf))
|
opts.Parameters.Set("toname", f.opt.Enc.FromStandardName(leaf))
|
||||||
opts.Parameters.Set("tofolderid", dirIDtoNumber(directoryID))
|
opts.Parameters.Set("tofolderid", dirIDtoNumber(directoryID))
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var result api.ItemResult
|
var result api.ItemResult
|
||||||
@@ -786,7 +795,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
opts.Parameters.Set("folderid", dirIDtoNumber(srcID))
|
opts.Parameters.Set("folderid", dirIDtoNumber(srcID))
|
||||||
opts.Parameters.Set("toname", enc.FromStandardName(leaf))
|
opts.Parameters.Set("toname", f.opt.Enc.FromStandardName(leaf))
|
||||||
opts.Parameters.Set("tofolderid", dirIDtoNumber(directoryID))
|
opts.Parameters.Set("tofolderid", dirIDtoNumber(directoryID))
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var result api.ItemResult
|
var result api.ItemResult
|
||||||
@@ -1066,7 +1075,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
TransferEncoding: []string{"identity"}, // pcloud doesn't like chunked encoding
|
TransferEncoding: []string{"identity"}, // pcloud doesn't like chunked encoding
|
||||||
}
|
}
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = o.fs.opt.Enc.FromStandardName(leaf)
|
||||||
opts.Parameters.Set("filename", leaf)
|
opts.Parameters.Set("filename", leaf)
|
||||||
opts.Parameters.Set("folderid", dirIDtoNumber(directoryID))
|
opts.Parameters.Set("folderid", dirIDtoNumber(directoryID))
|
||||||
opts.Parameters.Set("nopartial", "1")
|
opts.Parameters.Set("nopartial", "1")
|
||||||
|
|||||||
@@ -31,14 +31,15 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/backend/premiumizeme/api"
|
"github.com/rclone/rclone/backend/premiumizeme/api"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/random"
|
"github.com/rclone/rclone/lib/random"
|
||||||
@@ -46,8 +47,6 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.PremiumizeMe
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "658922194"
|
rcloneClientID = "658922194"
|
||||||
rcloneEncryptedClientSecret = "B5YIvQoRIhcpAYs8HYeyjb9gK-ftmZEbqdh_gNfc4RgO9Q"
|
rcloneEncryptedClientSecret = "B5YIvQoRIhcpAYs8HYeyjb9gK-ftmZEbqdh_gNfc4RgO9Q"
|
||||||
@@ -93,13 +92,23 @@ This is not normally used - use oauth instead.
|
|||||||
`,
|
`,
|
||||||
Hide: fs.OptionHideBoth,
|
Hide: fs.OptionHideBoth,
|
||||||
Default: "",
|
Default: "",
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeDoubleQuote |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
APIKey string `config:"api_key"`
|
APIKey string `config:"api_key"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote cloud storage system
|
// Fs represents a remote cloud storage system
|
||||||
@@ -306,14 +315,6 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// rootSlash returns root with a slash on if it is empty, otherwise empty string
|
|
||||||
func (f *Fs) rootSlash() string {
|
|
||||||
if f.root == "" {
|
|
||||||
return f.root
|
|
||||||
}
|
|
||||||
return f.root + "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return an Object from a path
|
// Return an Object from a path
|
||||||
//
|
//
|
||||||
// If it can't be found it returns the error fs.ErrorObjectNotFound.
|
// If it can't be found it returns the error fs.ErrorObjectNotFound.
|
||||||
@@ -364,7 +365,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
Path: "/folder/create",
|
Path: "/folder/create",
|
||||||
Parameters: f.baseParams(),
|
Parameters: f.baseParams(),
|
||||||
MultipartParams: url.Values{
|
MultipartParams: url.Values{
|
||||||
"name": {enc.FromStandardName(leaf)},
|
"name": {f.opt.Enc.FromStandardName(leaf)},
|
||||||
"parent_id": {pathID},
|
"parent_id": {pathID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -429,7 +430,7 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
|
|||||||
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
|
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
item.Name = enc.ToStandardName(item.Name)
|
item.Name = f.opt.Enc.ToStandardName(item.Name)
|
||||||
if fn(item) {
|
if fn(item) {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@@ -637,8 +638,8 @@ func (f *Fs) Purge(ctx context.Context) error {
|
|||||||
// between directories and a separate one to rename them. We try to
|
// between directories and a separate one to rename them. We try to
|
||||||
// call the minimum number of API calls.
|
// call the minimum number of API calls.
|
||||||
func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDirectoryID, newDirectoryID string) (err error) {
|
func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDirectoryID, newDirectoryID string) (err error) {
|
||||||
newLeaf = enc.FromStandardName(newLeaf)
|
newLeaf = f.opt.Enc.FromStandardName(newLeaf)
|
||||||
oldLeaf = enc.FromStandardName(oldLeaf)
|
oldLeaf = f.opt.Enc.FromStandardName(oldLeaf)
|
||||||
doRenameLeaf := oldLeaf != newLeaf
|
doRenameLeaf := oldLeaf != newLeaf
|
||||||
doMove := oldDirectoryID != newDirectoryID
|
doMove := oldDirectoryID != newDirectoryID
|
||||||
|
|
||||||
@@ -889,11 +890,6 @@ func (o *Object) Remote() string {
|
|||||||
return o.remote
|
return o.remote
|
||||||
}
|
}
|
||||||
|
|
||||||
// srvPath returns a path for use in server
|
|
||||||
func (o *Object) srvPath() string {
|
|
||||||
return enc.FromStandardPath(o.fs.rootSlash() + o.remote)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash returns the SHA-1 of an object returning a lowercase hex string
|
// Hash returns the SHA-1 of an object returning a lowercase hex string
|
||||||
func (o *Object) Hash(ctx context.Context, t hash.Type) (string, error) {
|
func (o *Object) Hash(ctx context.Context, t hash.Type) (string, error) {
|
||||||
return "", hash.ErrUnsupported
|
return "", hash.ErrUnsupported
|
||||||
@@ -984,14 +980,6 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
|||||||
return resp.Body, err
|
return resp.Body, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// metaHash returns a rough hash of metadata to detect if object has been updated
|
|
||||||
func (o *Object) metaHash() string {
|
|
||||||
if !o.hasMetaData {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("remote=%q, size=%d, modTime=%v, id=%q, mimeType=%q", o.remote, o.size, o.modTime, o.id, o.mimeType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the object with the contents of the io.Reader, modTime and size
|
// Update the object with the contents of the io.Reader, modTime and size
|
||||||
//
|
//
|
||||||
// If existing is set then it updates the object rather than creating a new one
|
// If existing is set then it updates the object rather than creating a new one
|
||||||
@@ -1006,7 +994,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = o.fs.opt.Enc.FromStandardName(leaf)
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var info api.FolderUploadinfoResponse
|
var info api.FolderUploadinfoResponse
|
||||||
|
|||||||
+16
-7
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/putdotio/go-putio/putio"
|
"github.com/putdotio/go-putio/putio"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
@@ -29,6 +30,7 @@ type Fs struct {
|
|||||||
name string // name of this remote
|
name string // name of this remote
|
||||||
root string // the path we are working on
|
root string // the path we are working on
|
||||||
features *fs.Features // optional features
|
features *fs.Features // optional features
|
||||||
|
opt Options // options for this Fs
|
||||||
client *putio.Client // client for making API calls to Put.io
|
client *putio.Client // client for making API calls to Put.io
|
||||||
pacer *fs.Pacer // To pace the API calls
|
pacer *fs.Pacer // To pace the API calls
|
||||||
dirCache *dircache.DirCache // Map of directory path to directory id
|
dirCache *dircache.DirCache // Map of directory path to directory id
|
||||||
@@ -60,6 +62,12 @@ func (f *Fs) Features() *fs.Features {
|
|||||||
// NewFs constructs an Fs from the path, container:path
|
// NewFs constructs an Fs from the path, container:path
|
||||||
func NewFs(name, root string, m configmap.Mapper) (f fs.Fs, err error) {
|
func NewFs(name, root string, m configmap.Mapper) (f fs.Fs, err error) {
|
||||||
// defer log.Trace(name, "root=%v", root)("f=%+v, err=%v", &f, &err)
|
// defer log.Trace(name, "root=%v", root)("f=%+v, err=%v", &f, &err)
|
||||||
|
// Parse config into Options struct
|
||||||
|
opt := new(Options)
|
||||||
|
err = configstruct.Set(m, opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
oAuthClient, _, err := oauthutil.NewClient(name, m, putioConfig)
|
oAuthClient, _, err := oauthutil.NewClient(name, m, putioConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to configure putio")
|
return nil, errors.Wrap(err, "failed to configure putio")
|
||||||
@@ -67,6 +75,7 @@ func NewFs(name, root string, m configmap.Mapper) (f fs.Fs, err error) {
|
|||||||
p := &Fs{
|
p := &Fs{
|
||||||
name: name,
|
name: name,
|
||||||
root: root,
|
root: root,
|
||||||
|
opt: *opt,
|
||||||
pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))),
|
pacer: fs.NewPacer(pacer.NewDefault(pacer.MinSleep(minSleep), pacer.MaxSleep(maxSleep), pacer.DecayConstant(decayConstant))),
|
||||||
client: putio.NewClient(oAuthClient),
|
client: putio.NewClient(oAuthClient),
|
||||||
oAuthClient: oAuthClient,
|
oAuthClient: oAuthClient,
|
||||||
@@ -127,7 +136,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
var entry putio.File
|
var entry putio.File
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
// fs.Debugf(f, "creating folder. part: %s, parentID: %d", leaf, parentID)
|
// fs.Debugf(f, "creating folder. part: %s, parentID: %d", leaf, parentID)
|
||||||
entry, err = f.client.Files.CreateFolder(ctx, enc.FromStandardName(leaf), parentID)
|
entry, err = f.client.Files.CreateFolder(ctx, f.opt.Enc.FromStandardName(leaf), parentID)
|
||||||
return shouldRetry(err)
|
return shouldRetry(err)
|
||||||
})
|
})
|
||||||
return itoa(entry.ID), err
|
return itoa(entry.ID), err
|
||||||
@@ -154,7 +163,7 @@ func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
if enc.ToStandardName(child.Name) == leaf {
|
if f.opt.Enc.ToStandardName(child.Name) == leaf {
|
||||||
found = true
|
found = true
|
||||||
pathIDOut = itoa(child.ID)
|
pathIDOut = itoa(child.ID)
|
||||||
if !child.IsDir() {
|
if !child.IsDir() {
|
||||||
@@ -196,7 +205,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
remote := path.Join(dir, enc.ToStandardName(child.Name))
|
remote := path.Join(dir, f.opt.Enc.ToStandardName(child.Name))
|
||||||
// fs.Debugf(f, "child: %s", remote)
|
// fs.Debugf(f, "child: %s", remote)
|
||||||
if child.IsDir() {
|
if child.IsDir() {
|
||||||
f.dirCache.Put(remote, itoa(child.ID))
|
f.dirCache.Put(remote, itoa(child.ID))
|
||||||
@@ -274,7 +283,7 @@ func (f *Fs) createUpload(ctx context.Context, name string, size int64, parentID
|
|||||||
req = req.WithContext(ctx) // go1.13 can use NewRequestWithContext
|
req = req.WithContext(ctx) // go1.13 can use NewRequestWithContext
|
||||||
req.Header.Set("tus-resumable", "1.0.0")
|
req.Header.Set("tus-resumable", "1.0.0")
|
||||||
req.Header.Set("upload-length", strconv.FormatInt(size, 10))
|
req.Header.Set("upload-length", strconv.FormatInt(size, 10))
|
||||||
b64name := base64.StdEncoding.EncodeToString([]byte(enc.FromStandardName(name)))
|
b64name := base64.StdEncoding.EncodeToString([]byte(f.opt.Enc.FromStandardName(name)))
|
||||||
b64true := base64.StdEncoding.EncodeToString([]byte("true"))
|
b64true := base64.StdEncoding.EncodeToString([]byte("true"))
|
||||||
b64parentID := base64.StdEncoding.EncodeToString([]byte(parentID))
|
b64parentID := base64.StdEncoding.EncodeToString([]byte(parentID))
|
||||||
b64modifiedAt := base64.StdEncoding.EncodeToString([]byte(modTime.Format(time.RFC3339)))
|
b64modifiedAt := base64.StdEncoding.EncodeToString([]byte(modTime.Format(time.RFC3339)))
|
||||||
@@ -546,7 +555,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (o fs.Objec
|
|||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("file_id", strconv.FormatInt(srcObj.file.ID, 10))
|
params.Set("file_id", strconv.FormatInt(srcObj.file.ID, 10))
|
||||||
params.Set("parent_id", directoryID)
|
params.Set("parent_id", directoryID)
|
||||||
params.Set("name", enc.FromStandardName(leaf))
|
params.Set("name", f.opt.Enc.FromStandardName(leaf))
|
||||||
req, err := f.client.NewRequest(ctx, "POST", "/v2/files/copy", strings.NewReader(params.Encode()))
|
req, err := f.client.NewRequest(ctx, "POST", "/v2/files/copy", strings.NewReader(params.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -585,7 +594,7 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (o fs.Objec
|
|||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("file_id", strconv.FormatInt(srcObj.file.ID, 10))
|
params.Set("file_id", strconv.FormatInt(srcObj.file.ID, 10))
|
||||||
params.Set("parent_id", directoryID)
|
params.Set("parent_id", directoryID)
|
||||||
params.Set("name", enc.FromStandardName(leaf))
|
params.Set("name", f.opt.Enc.FromStandardName(leaf))
|
||||||
req, err := f.client.NewRequest(ctx, "POST", "/v2/files/move", strings.NewReader(params.Encode()))
|
req, err := f.client.NewRequest(ctx, "POST", "/v2/files/move", strings.NewReader(params.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -674,7 +683,7 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("file_id", srcID)
|
params.Set("file_id", srcID)
|
||||||
params.Set("parent_id", dstDirectoryID)
|
params.Set("parent_id", dstDirectoryID)
|
||||||
params.Set("name", enc.FromStandardName(leaf))
|
params.Set("name", f.opt.Enc.FromStandardName(leaf))
|
||||||
req, err := f.client.NewRequest(ctx, "POST", "/v2/files/move", strings.NewReader(params.Encode()))
|
req, err := f.client.NewRequest(ctx, "POST", "/v2/files/move", strings.NewReader(params.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (o *Object) readEntry(ctx context.Context) (f *putio.File, err error) {
|
|||||||
}
|
}
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
// fs.Debugf(o, "requesting child. directoryID: %s, name: %s", directoryID, leaf)
|
// fs.Debugf(o, "requesting child. directoryID: %s, name: %s", directoryID, leaf)
|
||||||
req, err := o.fs.client.NewRequest(ctx, "GET", "/v2/files/"+directoryID+"/child?name="+url.QueryEscape(enc.FromStandardName(leaf)), nil)
|
req, err := o.fs.client.NewRequest(ctx, "GET", "/v2/files/"+directoryID+"/child?name="+url.QueryEscape(o.fs.opt.Enc.FromStandardName(leaf)), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-2
@@ -6,10 +6,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
@@ -25,7 +26,6 @@ canReadUnnormalized = true
|
|||||||
canReadRenormalized = true
|
canReadRenormalized = true
|
||||||
canStream = false
|
canStream = false
|
||||||
*/
|
*/
|
||||||
const enc = encodings.Putio
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const (
|
const (
|
||||||
@@ -65,9 +65,25 @@ func init() {
|
|||||||
log.Fatalf("Failed to configure token: %v", err)
|
log.Fatalf("Failed to configure token: %v", err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Options: []fs.Option{{
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Note that \ is renamed to -
|
||||||
|
//
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Options defines the configuration for this backend
|
||||||
|
type Options struct {
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
|
}
|
||||||
|
|
||||||
// Check the interfaces are satisfied
|
// Check the interfaces are satisfied
|
||||||
var (
|
var (
|
||||||
_ fs.Fs = (*Fs)(nil)
|
_ fs.Fs = (*Fs)(nil)
|
||||||
|
|||||||
@@ -18,20 +18,19 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
"github.com/rclone/rclone/lib/bucket"
|
"github.com/rclone/rclone/lib/bucket"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
qsConfig "github.com/yunify/qingstor-sdk-go/v3/config"
|
qsConfig "github.com/yunify/qingstor-sdk-go/v3/config"
|
||||||
qsErr "github.com/yunify/qingstor-sdk-go/v3/request/errors"
|
qsErr "github.com/yunify/qingstor-sdk-go/v3/request/errors"
|
||||||
qs "github.com/yunify/qingstor-sdk-go/v3/service"
|
qs "github.com/yunify/qingstor-sdk-go/v3/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.QingStor
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
@@ -113,6 +112,13 @@ and these uploads do not fully utilize your bandwidth, then increasing
|
|||||||
this may help to speed up the transfers.`,
|
this may help to speed up the transfers.`,
|
||||||
Default: 1,
|
Default: 1,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
Default: (encoder.EncodeInvalidUtf8 |
|
||||||
|
encoder.EncodeCtl |
|
||||||
|
encoder.EncodeSlash),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -136,15 +142,16 @@ func timestampToTime(tp int64) time.Time {
|
|||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
EnvAuth bool `config:"env_auth"`
|
EnvAuth bool `config:"env_auth"`
|
||||||
AccessKeyID string `config:"access_key_id"`
|
AccessKeyID string `config:"access_key_id"`
|
||||||
SecretAccessKey string `config:"secret_access_key"`
|
SecretAccessKey string `config:"secret_access_key"`
|
||||||
Endpoint string `config:"endpoint"`
|
Endpoint string `config:"endpoint"`
|
||||||
Zone string `config:"zone"`
|
Zone string `config:"zone"`
|
||||||
ConnectionRetries int `config:"connection_retries"`
|
ConnectionRetries int `config:"connection_retries"`
|
||||||
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
UploadConcurrency int `config:"upload_concurrency"`
|
UploadConcurrency int `config:"upload_concurrency"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote qingstor server
|
// Fs represents a remote qingstor server
|
||||||
@@ -188,7 +195,7 @@ func parsePath(path string) (root string) {
|
|||||||
// relative to f.root
|
// relative to f.root
|
||||||
func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) {
|
func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) {
|
||||||
bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
||||||
return enc.FromStandardName(bucketName), enc.FromStandardPath(bucketPath)
|
return f.opt.Enc.FromStandardName(bucketName), f.opt.Enc.FromStandardPath(bucketPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// split returns bucket and bucketPath from the object
|
// split returns bucket and bucketPath from the object
|
||||||
@@ -357,7 +364,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
encodedDirectory := enc.FromStandardPath(f.rootDirectory)
|
encodedDirectory := f.opt.Enc.FromStandardPath(f.rootDirectory)
|
||||||
_, err = bucketInit.HeadObject(encodedDirectory, &qs.HeadObjectInput{})
|
_, err = bucketInit.HeadObject(encodedDirectory, &qs.HeadObjectInput{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
newRoot := path.Dir(f.root)
|
newRoot := path.Dir(f.root)
|
||||||
@@ -385,7 +392,7 @@ func (f *Fs) Root() string {
|
|||||||
// String converts this Fs to a string
|
// String converts this Fs to a string
|
||||||
func (f *Fs) String() string {
|
func (f *Fs) String() string {
|
||||||
if f.rootBucket == "" {
|
if f.rootBucket == "" {
|
||||||
return fmt.Sprintf("QingStor root")
|
return "QingStor root"
|
||||||
}
|
}
|
||||||
if f.rootDirectory == "" {
|
if f.rootDirectory == "" {
|
||||||
return fmt.Sprintf("QingStor bucket %s", f.rootBucket)
|
return fmt.Sprintf("QingStor bucket %s", f.rootBucket)
|
||||||
@@ -555,7 +562,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
remote := *commonPrefix
|
remote := *commonPrefix
|
||||||
remote = enc.ToStandardPath(remote)
|
remote = f.opt.Enc.ToStandardPath(remote)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Logf(f, "Odd name received %q", remote)
|
fs.Logf(f, "Odd name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -576,7 +583,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
|
|
||||||
for _, object := range resp.Keys {
|
for _, object := range resp.Keys {
|
||||||
remote := qs.StringValue(object.Key)
|
remote := qs.StringValue(object.Key)
|
||||||
remote = enc.ToStandardPath(remote)
|
remote = f.opt.Enc.ToStandardPath(remote)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Logf(f, "Odd name received %q", remote)
|
fs.Logf(f, "Odd name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -653,7 +660,7 @@ func (f *Fs) listBuckets(ctx context.Context) (entries fs.DirEntries, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, bucket := range resp.Buckets {
|
for _, bucket := range resp.Buckets {
|
||||||
d := fs.NewDir(enc.ToStandardName(qs.StringValue(bucket.Name)), qs.TimeValue(bucket.Created))
|
d := fs.NewDir(f.opt.Enc.ToStandardName(qs.StringValue(bucket.Name)), qs.TimeValue(bucket.Created))
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
}
|
}
|
||||||
return entries, nil
|
return entries, nil
|
||||||
|
|||||||
@@ -297,21 +297,6 @@ func (mu *multiUploader) send(c chunk) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// list list the ObjectParts of an multipart upload
|
|
||||||
func (mu *multiUploader) list() error {
|
|
||||||
bucketInit, _ := mu.bucketInit()
|
|
||||||
|
|
||||||
req := qs.ListMultipartInput{
|
|
||||||
UploadID: mu.uploadID,
|
|
||||||
}
|
|
||||||
fs.Debugf(mu, "Reading multi-part details")
|
|
||||||
rsp, err := bucketInit.ListMultipart(mu.cfg.key, &req)
|
|
||||||
if err == nil {
|
|
||||||
mu.objectParts = rsp.ObjectParts
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// complete complete an multipart upload
|
// complete complete an multipart upload
|
||||||
func (mu *multiUploader) complete() error {
|
func (mu *multiUploader) complete() error {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
+145
-69
@@ -46,22 +46,22 @@ import (
|
|||||||
"github.com/ncw/swift"
|
"github.com/ncw/swift"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
"github.com/rclone/rclone/lib/bucket"
|
"github.com/rclone/rclone/lib/bucket"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
|
"github.com/rclone/rclone/lib/pool"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
"github.com/rclone/rclone/lib/rest"
|
"github.com/rclone/rclone/lib/rest"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.S3
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
@@ -95,6 +95,9 @@ func init() {
|
|||||||
}, {
|
}, {
|
||||||
Value: "Netease",
|
Value: "Netease",
|
||||||
Help: "Netease Object Storage (NOS)",
|
Help: "Netease Object Storage (NOS)",
|
||||||
|
}, {
|
||||||
|
Value: "StackPath",
|
||||||
|
Help: "StackPath Object Storage",
|
||||||
}, {
|
}, {
|
||||||
Value: "Wasabi",
|
Value: "Wasabi",
|
||||||
Help: "Wasabi Object Storage",
|
Help: "Wasabi Object Storage",
|
||||||
@@ -357,10 +360,24 @@ func init() {
|
|||||||
Value: "oss-me-east-1.aliyuncs.com",
|
Value: "oss-me-east-1.aliyuncs.com",
|
||||||
Help: "Middle East 1 (Dubai)",
|
Help: "Middle East 1 (Dubai)",
|
||||||
}},
|
}},
|
||||||
|
}, {
|
||||||
|
Name: "endpoint",
|
||||||
|
Help: "Endpoint for StackPath Object Storage.",
|
||||||
|
Provider: "StackPath",
|
||||||
|
Examples: []fs.OptionExample{{
|
||||||
|
Value: "s3.us-east-2.stackpathstorage.com",
|
||||||
|
Help: "US East Endpoint",
|
||||||
|
}, {
|
||||||
|
Value: "s3.us-west-1.stackpathstorage.com",
|
||||||
|
Help: "US West Endpoint",
|
||||||
|
}, {
|
||||||
|
Value: "s3.eu-central-1.stackpathstorage.com",
|
||||||
|
Help: "EU Endpoint",
|
||||||
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "endpoint",
|
Name: "endpoint",
|
||||||
Help: "Endpoint for S3 API.\nRequired when using an S3 clone.",
|
Help: "Endpoint for S3 API.\nRequired when using an S3 clone.",
|
||||||
Provider: "!AWS,IBMCOS,Alibaba",
|
Provider: "!AWS,IBMCOS,Alibaba,StackPath",
|
||||||
Examples: []fs.OptionExample{{
|
Examples: []fs.OptionExample{{
|
||||||
Value: "objects-us-east-1.dream.io",
|
Value: "objects-us-east-1.dream.io",
|
||||||
Help: "Dream Objects endpoint",
|
Help: "Dream Objects endpoint",
|
||||||
@@ -547,7 +564,7 @@ func init() {
|
|||||||
}, {
|
}, {
|
||||||
Name: "location_constraint",
|
Name: "location_constraint",
|
||||||
Help: "Location constraint - must be set to match the Region.\nLeave blank if not sure. Used when creating buckets only.",
|
Help: "Location constraint - must be set to match the Region.\nLeave blank if not sure. Used when creating buckets only.",
|
||||||
Provider: "!AWS,IBMCOS,Alibaba",
|
Provider: "!AWS,IBMCOS,Alibaba,StackPath",
|
||||||
}, {
|
}, {
|
||||||
Name: "acl",
|
Name: "acl",
|
||||||
Help: `Canned ACL used when creating buckets and storing or copying objects.
|
Help: `Canned ACL used when creating buckets and storing or copying objects.
|
||||||
@@ -811,63 +828,99 @@ In Ceph, this can be increased with the "rgw list buckets max chunk" option.
|
|||||||
`,
|
`,
|
||||||
Default: 1000,
|
Default: 1000,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
}},
|
}, {
|
||||||
})
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Any UTF-8 character is valid in a key, however it can't handle
|
||||||
|
// invalid UTF-8 and / have a special meaning.
|
||||||
|
//
|
||||||
|
// The SDK can't seem to handle uploading files called '.'
|
||||||
|
//
|
||||||
|
// FIXME would be nice to add
|
||||||
|
// - initial / encoding
|
||||||
|
// - doubled / encoding
|
||||||
|
// - trailing / encoding
|
||||||
|
// so that AWS keys are always valid file names
|
||||||
|
Default: encoder.EncodeInvalidUtf8 |
|
||||||
|
encoder.EncodeSlash |
|
||||||
|
encoder.EncodeDot,
|
||||||
|
}, {
|
||||||
|
Name: "memory_pool_flush_time",
|
||||||
|
Default: memoryPoolFlushTime,
|
||||||
|
Advanced: true,
|
||||||
|
Help: `How often internal memory buffer pools will be flushed.
|
||||||
|
Uploads which requires additional buffers (f.e multipart) will use memory pool for allocations.
|
||||||
|
This option controls how often unused buffers will be removed from the pool.`,
|
||||||
|
}, {
|
||||||
|
Name: "memory_pool_use_mmap",
|
||||||
|
Default: memoryPoolUseMmap,
|
||||||
|
Advanced: true,
|
||||||
|
Help: `Whether to use mmap buffers in internal memory pool.`,
|
||||||
|
},
|
||||||
|
}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const (
|
const (
|
||||||
metaMtime = "Mtime" // the meta key to store mtime in - eg X-Amz-Meta-Mtime
|
metaMtime = "Mtime" // the meta key to store mtime in - eg X-Amz-Meta-Mtime
|
||||||
metaMD5Hash = "Md5chksum" // the meta key to store md5hash in
|
metaMD5Hash = "Md5chksum" // the meta key to store md5hash in
|
||||||
maxRetries = 10 // number of retries to make of operations
|
|
||||||
maxSizeForCopy = 5 * 1024 * 1024 * 1024 // The maximum size of object we can COPY
|
maxSizeForCopy = 5 * 1024 * 1024 * 1024 // The maximum size of object we can COPY
|
||||||
maxUploadParts = 10000 // maximum allowed number of parts in a multi-part upload
|
maxUploadParts = 10000 // maximum allowed number of parts in a multi-part upload
|
||||||
minChunkSize = fs.SizeSuffix(1024 * 1024 * 5)
|
minChunkSize = fs.SizeSuffix(1024 * 1024 * 5)
|
||||||
defaultUploadCutoff = fs.SizeSuffix(200 * 1024 * 1024)
|
defaultUploadCutoff = fs.SizeSuffix(200 * 1024 * 1024)
|
||||||
maxUploadCutoff = fs.SizeSuffix(5 * 1024 * 1024 * 1024)
|
maxUploadCutoff = fs.SizeSuffix(5 * 1024 * 1024 * 1024)
|
||||||
minSleep = 10 * time.Millisecond // In case of error, start at 10ms sleep.
|
minSleep = 10 * time.Millisecond // In case of error, start at 10ms sleep.
|
||||||
|
|
||||||
|
memoryPoolFlushTime = fs.Duration(time.Minute) // flush the cached buffers after this long
|
||||||
|
memoryPoolUseMmap = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Provider string `config:"provider"`
|
Provider string `config:"provider"`
|
||||||
EnvAuth bool `config:"env_auth"`
|
EnvAuth bool `config:"env_auth"`
|
||||||
AccessKeyID string `config:"access_key_id"`
|
AccessKeyID string `config:"access_key_id"`
|
||||||
SecretAccessKey string `config:"secret_access_key"`
|
SecretAccessKey string `config:"secret_access_key"`
|
||||||
Region string `config:"region"`
|
Region string `config:"region"`
|
||||||
Endpoint string `config:"endpoint"`
|
Endpoint string `config:"endpoint"`
|
||||||
LocationConstraint string `config:"location_constraint"`
|
LocationConstraint string `config:"location_constraint"`
|
||||||
ACL string `config:"acl"`
|
ACL string `config:"acl"`
|
||||||
BucketACL string `config:"bucket_acl"`
|
BucketACL string `config:"bucket_acl"`
|
||||||
ServerSideEncryption string `config:"server_side_encryption"`
|
ServerSideEncryption string `config:"server_side_encryption"`
|
||||||
SSEKMSKeyID string `config:"sse_kms_key_id"`
|
SSEKMSKeyID string `config:"sse_kms_key_id"`
|
||||||
StorageClass string `config:"storage_class"`
|
StorageClass string `config:"storage_class"`
|
||||||
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
||||||
CopyCutoff fs.SizeSuffix `config:"copy_cutoff"`
|
CopyCutoff fs.SizeSuffix `config:"copy_cutoff"`
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
DisableChecksum bool `config:"disable_checksum"`
|
DisableChecksum bool `config:"disable_checksum"`
|
||||||
SessionToken string `config:"session_token"`
|
SessionToken string `config:"session_token"`
|
||||||
UploadConcurrency int `config:"upload_concurrency"`
|
UploadConcurrency int `config:"upload_concurrency"`
|
||||||
ForcePathStyle bool `config:"force_path_style"`
|
ForcePathStyle bool `config:"force_path_style"`
|
||||||
V2Auth bool `config:"v2_auth"`
|
V2Auth bool `config:"v2_auth"`
|
||||||
UseAccelerateEndpoint bool `config:"use_accelerate_endpoint"`
|
UseAccelerateEndpoint bool `config:"use_accelerate_endpoint"`
|
||||||
LeavePartsOnError bool `config:"leave_parts_on_error"`
|
LeavePartsOnError bool `config:"leave_parts_on_error"`
|
||||||
ListChunk int64 `config:"list_chunk"`
|
ListChunk int64 `config:"list_chunk"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
|
MemoryPoolFlushTime fs.Duration `config:"memory_pool_flush_time"`
|
||||||
|
MemoryPoolUseMmap bool `config:"memory_pool_use_mmap"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote s3 server
|
// Fs represents a remote s3 server
|
||||||
type Fs struct {
|
type Fs struct {
|
||||||
name string // the name of the remote
|
name string // the name of the remote
|
||||||
root string // root of the bucket - ignore all objects above this
|
root string // root of the bucket - ignore all objects above this
|
||||||
opt Options // parsed options
|
opt Options // parsed options
|
||||||
features *fs.Features // optional features
|
features *fs.Features // optional features
|
||||||
c *s3.S3 // the connection to the s3 server
|
c *s3.S3 // the connection to the s3 server
|
||||||
ses *session.Session // the s3 session
|
ses *session.Session // the s3 session
|
||||||
rootBucket string // bucket part of root (if any)
|
rootBucket string // bucket part of root (if any)
|
||||||
rootDirectory string // directory part of root (if any)
|
rootDirectory string // directory part of root (if any)
|
||||||
cache *bucket.Cache // cache for bucket creation status
|
cache *bucket.Cache // cache for bucket creation status
|
||||||
pacer *fs.Pacer // To pace the API calls
|
pacer *fs.Pacer // To pace the API calls
|
||||||
srv *http.Client // a plain http client
|
srv *http.Client // a plain http client
|
||||||
|
poolMu sync.Mutex // mutex protecting memory pools map
|
||||||
|
pools map[int64]*pool.Pool // memory pools
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object describes a s3 object
|
// Object describes a s3 object
|
||||||
@@ -917,7 +970,7 @@ func (f *Fs) Features() *fs.Features {
|
|||||||
// retryErrorCodes is a slice of error codes that we will retry
|
// retryErrorCodes is a slice of error codes that we will retry
|
||||||
// See: https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
|
// See: https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
|
||||||
var retryErrorCodes = []int{
|
var retryErrorCodes = []int{
|
||||||
// 409, // Conflict - various states that could be resolved on a retry
|
500, // Internal Server Error - "We encountered an internal error. Please try again."
|
||||||
503, // Service Unavailable/Slow Down - "Reduce your request rate"
|
503, // Service Unavailable/Slow Down - "Reduce your request rate"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -965,7 +1018,7 @@ func parsePath(path string) (root string) {
|
|||||||
// relative to f.root
|
// relative to f.root
|
||||||
func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) {
|
func (f *Fs) split(rootRelativePath string) (bucketName, bucketPath string) {
|
||||||
bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
bucketName, bucketPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
||||||
return enc.FromStandardName(bucketName), enc.FromStandardPath(bucketPath)
|
return f.opt.Enc.FromStandardName(bucketName), f.opt.Enc.FromStandardPath(bucketPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// split returns bucket and bucketPath from the object
|
// split returns bucket and bucketPath from the object
|
||||||
@@ -1040,7 +1093,7 @@ func s3Connection(opt *Options) (*s3.S3, *session.Session, error) {
|
|||||||
opt.ForcePathStyle = false
|
opt.ForcePathStyle = false
|
||||||
}
|
}
|
||||||
awsConfig := aws.NewConfig().
|
awsConfig := aws.NewConfig().
|
||||||
WithMaxRetries(maxRetries).
|
WithMaxRetries(fs.Config.LowLevelRetries).
|
||||||
WithCredentials(cred).
|
WithCredentials(cred).
|
||||||
WithHTTPClient(fshttp.NewClient(fs.Config)).
|
WithHTTPClient(fshttp.NewClient(fs.Config)).
|
||||||
WithS3ForcePathStyle(opt.ForcePathStyle).
|
WithS3ForcePathStyle(opt.ForcePathStyle).
|
||||||
@@ -1146,15 +1199,23 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pc := fs.NewPacer(pacer.NewS3(pacer.MinSleep(minSleep)))
|
||||||
|
// Set pacer retries to 0 because we are relying on SDK retry mechanism.
|
||||||
|
// Setting it to 1 because in context of pacer it means 1 attempt.
|
||||||
|
pc.SetRetries(1)
|
||||||
|
|
||||||
f := &Fs{
|
f := &Fs{
|
||||||
name: name,
|
name: name,
|
||||||
opt: *opt,
|
opt: *opt,
|
||||||
c: c,
|
c: c,
|
||||||
ses: ses,
|
ses: ses,
|
||||||
pacer: fs.NewPacer(pacer.NewS3(pacer.MinSleep(minSleep))),
|
pacer: pc,
|
||||||
cache: bucket.NewCache(),
|
cache: bucket.NewCache(),
|
||||||
srv: fshttp.NewClient(fs.Config),
|
srv: fshttp.NewClient(fs.Config),
|
||||||
|
pools: make(map[int64]*pool.Pool),
|
||||||
}
|
}
|
||||||
|
|
||||||
f.setRoot(root)
|
f.setRoot(root)
|
||||||
f.features = (&fs.Features{
|
f.features = (&fs.Features{
|
||||||
ReadMimeType: true,
|
ReadMimeType: true,
|
||||||
@@ -1166,7 +1227,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
}).Fill(f)
|
}).Fill(f)
|
||||||
if f.rootBucket != "" && f.rootDirectory != "" {
|
if f.rootBucket != "" && f.rootDirectory != "" {
|
||||||
// Check to see if the object exists
|
// Check to see if the object exists
|
||||||
encodedDirectory := enc.FromStandardPath(f.rootDirectory)
|
encodedDirectory := f.opt.Enc.FromStandardPath(f.rootDirectory)
|
||||||
req := s3.HeadObjectInput{
|
req := s3.HeadObjectInput{
|
||||||
Bucket: &f.rootBucket,
|
Bucket: &f.rootBucket,
|
||||||
Key: &encodedDirectory,
|
Key: &encodedDirectory,
|
||||||
@@ -1304,7 +1365,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
//
|
//
|
||||||
// So we enable only on providers we know supports it properly, all others can retry when a
|
// So we enable only on providers we know supports it properly, all others can retry when a
|
||||||
// XML Syntax error is detected.
|
// XML Syntax error is detected.
|
||||||
var urlEncodeListings = (f.opt.Provider == "AWS" || f.opt.Provider == "Wasabi" || f.opt.Provider == "Alibaba")
|
var urlEncodeListings = (f.opt.Provider == "AWS" || f.opt.Provider == "Wasabi" || f.opt.Provider == "Alibaba" || f.opt.Provider == "Minio")
|
||||||
for {
|
for {
|
||||||
// FIXME need to implement ALL loop
|
// FIXME need to implement ALL loop
|
||||||
req := s3.ListObjectsInput{
|
req := s3.ListObjectsInput{
|
||||||
@@ -1369,7 +1430,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remote = enc.ToStandardPath(remote)
|
remote = f.opt.Enc.ToStandardPath(remote)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Logf(f, "Odd name received %q", remote)
|
fs.Logf(f, "Odd name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -1396,7 +1457,7 @@ func (f *Fs) list(ctx context.Context, bucket, directory, prefix string, addBuck
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
remote = enc.ToStandardPath(remote)
|
remote = f.opt.Enc.ToStandardPath(remote)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Logf(f, "Odd name received %q", remote)
|
fs.Logf(f, "Odd name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -1487,7 +1548,7 @@ func (f *Fs) listBuckets(ctx context.Context) (entries fs.DirEntries, err error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, bucket := range resp.Buckets {
|
for _, bucket := range resp.Buckets {
|
||||||
bucketName := enc.ToStandardName(aws.StringValue(bucket.Name))
|
bucketName := f.opt.Enc.ToStandardName(aws.StringValue(bucket.Name))
|
||||||
f.cache.MarkOK(bucketName)
|
f.cache.MarkOK(bucketName)
|
||||||
d := fs.NewDir(bucketName, aws.TimeValue(bucket.CreationDate))
|
d := fs.NewDir(bucketName, aws.TimeValue(bucket.CreationDate))
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
@@ -1738,8 +1799,9 @@ func (f *Fs) copyMultipart(ctx context.Context, req *s3.CopyObjectInput, dstBuck
|
|||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We can try to abort the upload, but ignore the error.
|
// We can try to abort the upload, but ignore the error.
|
||||||
|
fs.Debugf(nil, "Cancelling multipart copy")
|
||||||
_ = f.pacer.Call(func() (bool, error) {
|
_ = f.pacer.Call(func() (bool, error) {
|
||||||
_, err := f.c.AbortMultipartUploadWithContext(ctx, &s3.AbortMultipartUploadInput{
|
_, err := f.c.AbortMultipartUploadWithContext(context.Background(), &s3.AbortMultipartUploadInput{
|
||||||
Bucket: &dstBucket,
|
Bucket: &dstBucket,
|
||||||
Key: &dstPath,
|
Key: &dstPath,
|
||||||
UploadId: uid,
|
UploadId: uid,
|
||||||
@@ -1841,6 +1903,22 @@ func (f *Fs) Hashes() hash.Set {
|
|||||||
return hash.Set(hash.MD5)
|
return hash.Set(hash.MD5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Fs) getMemoryPool(size int64) *pool.Pool {
|
||||||
|
f.poolMu.Lock()
|
||||||
|
defer f.poolMu.Unlock()
|
||||||
|
|
||||||
|
_, ok := f.pools[size]
|
||||||
|
if !ok {
|
||||||
|
f.pools[size] = pool.New(
|
||||||
|
time.Duration(f.opt.MemoryPoolFlushTime),
|
||||||
|
int(f.opt.ChunkSize),
|
||||||
|
f.opt.UploadConcurrency*fs.Config.Transfers,
|
||||||
|
f.opt.MemoryPoolUseMmap,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return f.pools[size]
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
// Fs returns the parent Fs
|
// Fs returns the parent Fs
|
||||||
@@ -2044,16 +2122,7 @@ func (o *Object) uploadMultipart(ctx context.Context, req *s3.PutObjectInput, si
|
|||||||
if concurrency < 1 {
|
if concurrency < 1 {
|
||||||
concurrency = 1
|
concurrency = 1
|
||||||
}
|
}
|
||||||
bufs := make(chan []byte, concurrency)
|
tokens := pacer.NewTokenDispenser(concurrency)
|
||||||
defer func() {
|
|
||||||
// empty the channel on exit
|
|
||||||
close(bufs)
|
|
||||||
for range bufs {
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for i := 0; i < concurrency; i++ {
|
|
||||||
bufs <- nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate size of parts
|
// calculate size of parts
|
||||||
partSize := int(f.opt.ChunkSize)
|
partSize := int(f.opt.ChunkSize)
|
||||||
@@ -2074,6 +2143,8 @@ func (o *Object) uploadMultipart(ctx context.Context, req *s3.PutObjectInput, si
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memPool := f.getMemoryPool(int64(partSize))
|
||||||
|
|
||||||
var cout *s3.CreateMultipartUploadOutput
|
var cout *s3.CreateMultipartUploadOutput
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
var err error
|
var err error
|
||||||
@@ -2102,7 +2173,7 @@ func (o *Object) uploadMultipart(ctx context.Context, req *s3.PutObjectInput, si
|
|||||||
// We can try to abort the upload, but ignore the error.
|
// We can try to abort the upload, but ignore the error.
|
||||||
fs.Debugf(o, "Cancelling multipart upload")
|
fs.Debugf(o, "Cancelling multipart upload")
|
||||||
errCancel := f.pacer.Call(func() (bool, error) {
|
errCancel := f.pacer.Call(func() (bool, error) {
|
||||||
_, err := f.c.AbortMultipartUploadWithContext(ctx, &s3.AbortMultipartUploadInput{
|
_, err := f.c.AbortMultipartUploadWithContext(context.Background(), &s3.AbortMultipartUploadInput{
|
||||||
Bucket: req.Bucket,
|
Bucket: req.Bucket,
|
||||||
Key: req.Key,
|
Key: req.Key,
|
||||||
UploadId: uid,
|
UploadId: uid,
|
||||||
@@ -2125,10 +2196,14 @@ func (o *Object) uploadMultipart(ctx context.Context, req *s3.PutObjectInput, si
|
|||||||
)
|
)
|
||||||
|
|
||||||
for partNum := int64(1); !finished; partNum++ {
|
for partNum := int64(1); !finished; partNum++ {
|
||||||
// Get a block of memory from the channel (which limits concurrency)
|
// Get a block of memory from the pool and token which limits concurrency.
|
||||||
buf := <-bufs
|
tokens.Get()
|
||||||
if buf == nil {
|
buf := memPool.Get()
|
||||||
buf = make([]byte, partSize)
|
|
||||||
|
// Fail fast, in case an errgroup managed function returns an error
|
||||||
|
// gCtx is cancelled. There is no point in uploading all the other parts.
|
||||||
|
if gCtx.Err() != nil {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the chunk
|
// Read the chunk
|
||||||
@@ -2186,8 +2261,9 @@ func (o *Object) uploadMultipart(ctx context.Context, req *s3.PutObjectInput, si
|
|||||||
return false, nil
|
return false, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// return the memory
|
// return the memory and token
|
||||||
bufs <- buf[:partSize]
|
memPool.Put(buf[:partSize])
|
||||||
|
tokens.Put()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "multipart upload failed to upload part")
|
return errors.Wrap(err, "multipart upload failed to upload part")
|
||||||
|
|||||||
@@ -439,7 +439,12 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signer, err := ssh.ParsePrivateKeyWithPassphrase(key, []byte(clearpass))
|
var signer ssh.Signer
|
||||||
|
if clearpass == "" {
|
||||||
|
signer, err = ssh.ParsePrivateKey(key)
|
||||||
|
} else {
|
||||||
|
signer, err = ssh.ParsePrivateKeyWithPassphrase(key, []byte(clearpass))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to parse private key file")
|
return nil, errors.Wrap(err, "failed to parse private key file")
|
||||||
}
|
}
|
||||||
@@ -1210,7 +1215,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Update")
|
return errors.Wrap(err, "Update")
|
||||||
}
|
}
|
||||||
file, err := c.sftpClient.Create(o.path())
|
file, err := c.sftpClient.OpenFile(o.path(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC)
|
||||||
o.fs.putSftpConnection(&c, err)
|
o.fs.putSftpConnection(&c, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Update Create failed")
|
return errors.Wrap(err, "Update Create failed")
|
||||||
|
|||||||
@@ -8,13 +8,24 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rclone/rclone/backend/sftp"
|
"github.com/rclone/rclone/backend/sftp"
|
||||||
|
"github.com/rclone/rclone/fstest"
|
||||||
"github.com/rclone/rclone/fstest/fstests"
|
"github.com/rclone/rclone/fstest/fstests"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestIntegration runs integration tests against the remote
|
// TestIntegration runs integration tests against the remote
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
fstests.Run(t, &fstests.Opt{
|
fstests.Run(t, &fstests.Opt{
|
||||||
RemoteName: "TestSftp:",
|
RemoteName: "TestSFTPOpenssh:",
|
||||||
|
NilObject: (*sftp.Object)(nil),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIntegration2(t *testing.T) {
|
||||||
|
if *fstest.RemoteName != "" {
|
||||||
|
t.Skip("skipping as -remote is set")
|
||||||
|
}
|
||||||
|
fstests.Run(t, &fstests.Opt{
|
||||||
|
RemoteName: "TestSFTPRclone:",
|
||||||
NilObject: (*sftp.Object)(nil),
|
NilObject: (*sftp.Object)(nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -87,13 +87,14 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/backend/sharefile/api"
|
"github.com/rclone/rclone/backend/sharefile/api"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/lib/dircache"
|
"github.com/rclone/rclone/lib/dircache"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/random"
|
"github.com/rclone/rclone/lib/random"
|
||||||
@@ -101,8 +102,6 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Sharefile
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "djQUPlHTUM9EvayYBWuKC5IrVIoQde46"
|
rcloneClientID = "djQUPlHTUM9EvayYBWuKC5IrVIoQde46"
|
||||||
rcloneEncryptedClientSecret = "v7572bKhUindQL3yDnUAebmgP-QxiwT38JLxVPolcZBl6SSs329MtFzH73x7BeELmMVZtneUPvALSopUZ6VkhQ"
|
rcloneEncryptedClientSecret = "v7572bKhUindQL3yDnUAebmgP-QxiwT38JLxVPolcZBl6SSs329MtFzH73x7BeELmMVZtneUPvALSopUZ6VkhQ"
|
||||||
@@ -204,16 +203,30 @@ be set manually to something like: https://XXX.sharefile.com
|
|||||||
`,
|
`,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
Default: "",
|
Default: "",
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
Default: (encoder.Base |
|
||||||
|
encoder.EncodeWin | // :?"*<>|
|
||||||
|
encoder.EncodeBackSlash | // \
|
||||||
|
encoder.EncodeCtl |
|
||||||
|
encoder.EncodeRightSpace |
|
||||||
|
encoder.EncodeRightPeriod |
|
||||||
|
encoder.EncodeLeftSpace |
|
||||||
|
encoder.EncodeLeftPeriod |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
RootFolderID string `config:"root_folder_id"`
|
RootFolderID string `config:"root_folder_id"`
|
||||||
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
UploadCutoff fs.SizeSuffix `config:"upload_cutoff"`
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
Endpoint string `config:"endpoint"`
|
Endpoint string `config:"endpoint"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote cloud storage system
|
// Fs represents a remote cloud storage system
|
||||||
@@ -301,7 +314,7 @@ func (f *Fs) readMetaDataForIDPath(ctx context.Context, id, path string, directo
|
|||||||
}
|
}
|
||||||
if path != "" {
|
if path != "" {
|
||||||
opts.Path += "/ByPath"
|
opts.Path += "/ByPath"
|
||||||
opts.Parameters.Set("path", "/"+enc.FromStandardPath(path))
|
opts.Parameters.Set("path", "/"+f.opt.Enc.FromStandardPath(path))
|
||||||
}
|
}
|
||||||
var item api.Item
|
var item api.Item
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
@@ -595,7 +608,7 @@ func (f *Fs) FindLeaf(ctx context.Context, pathID, leaf string) (pathIDOut strin
|
|||||||
// CreateDir makes a directory with pathID as parent and name leaf
|
// CreateDir makes a directory with pathID as parent and name leaf
|
||||||
func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string, err error) {
|
func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string, err error) {
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = f.opt.Enc.FromStandardName(leaf)
|
||||||
var req = api.Item{
|
var req = api.Item{
|
||||||
Name: leaf,
|
Name: leaf,
|
||||||
FileName: leaf,
|
FileName: leaf,
|
||||||
@@ -664,7 +677,7 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
|
|||||||
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
|
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
item.Name = enc.ToStandardName(item.Name)
|
item.Name = f.opt.Enc.ToStandardName(item.Name)
|
||||||
if fn(item) {
|
if fn(item) {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@@ -873,7 +886,7 @@ func (f *Fs) updateItem(ctx context.Context, id, leaf, directoryID string, modTi
|
|||||||
"overwrite": {"false"},
|
"overwrite": {"false"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = f.opt.Enc.FromStandardName(leaf)
|
||||||
// FIXME this appears to be a bug in the API
|
// FIXME this appears to be a bug in the API
|
||||||
//
|
//
|
||||||
// If you set the modified time via PATCH then the server
|
// If you set the modified time via PATCH then the server
|
||||||
@@ -1119,7 +1132,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (dst fs.Obj
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
srcLeaf = enc.FromStandardName(srcLeaf)
|
srcLeaf = f.opt.Enc.FromStandardName(srcLeaf)
|
||||||
_ = srcParentID
|
_ = srcParentID
|
||||||
|
|
||||||
// Create temporary object
|
// Create temporary object
|
||||||
@@ -1127,7 +1140,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (dst fs.Obj
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dstLeaf = enc.FromStandardName(dstLeaf)
|
dstLeaf = f.opt.Enc.FromStandardName(dstLeaf)
|
||||||
|
|
||||||
sameName := strings.ToLower(srcLeaf) == strings.ToLower(dstLeaf)
|
sameName := strings.ToLower(srcLeaf) == strings.ToLower(dstLeaf)
|
||||||
if sameName && srcParentID == dstParentID {
|
if sameName && srcParentID == dstParentID {
|
||||||
@@ -1390,7 +1403,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
leaf = enc.FromStandardName(leaf)
|
leaf = o.fs.opt.Enc.FromStandardName(leaf)
|
||||||
var req = api.UploadRequest{
|
var req = api.UploadRequest{
|
||||||
Method: "standard",
|
Method: "standard",
|
||||||
Raw: true,
|
Raw: true,
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
// Package api has type definitions for sugarsync
|
||||||
|
//
|
||||||
|
// Converted from the API docs with help from https://www.onlinetool.io/xmltogo/
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AppAuthorization is used to request a refresh token
|
||||||
|
//
|
||||||
|
// The token is returned in the Location: field
|
||||||
|
type AppAuthorization struct {
|
||||||
|
XMLName xml.Name `xml:"appAuthorization"`
|
||||||
|
Username string `xml:"username"`
|
||||||
|
Password string `xml:"password"`
|
||||||
|
Application string `xml:"application"`
|
||||||
|
AccessKeyID string `xml:"accessKeyId"`
|
||||||
|
PrivateAccessKey string `xml:"privateAccessKey"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TokenAuthRequest is the request to get Authorization
|
||||||
|
type TokenAuthRequest struct {
|
||||||
|
XMLName xml.Name `xml:"tokenAuthRequest"`
|
||||||
|
AccessKeyID string `xml:"accessKeyId"`
|
||||||
|
PrivateAccessKey string `xml:"privateAccessKey"`
|
||||||
|
RefreshToken string `xml:"refreshToken"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authorization is returned from the TokenAuthRequest
|
||||||
|
type Authorization struct {
|
||||||
|
XMLName xml.Name `xml:"authorization"`
|
||||||
|
Expiration time.Time `xml:"expiration"`
|
||||||
|
User string `xml:"user"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// File represents a single file
|
||||||
|
type File struct {
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
Ref string `xml:"ref"`
|
||||||
|
DsID string `xml:"dsid"`
|
||||||
|
TimeCreated time.Time `xml:"timeCreated"`
|
||||||
|
Parent string `xml:"parent"`
|
||||||
|
Size int64 `xml:"size"`
|
||||||
|
LastModified time.Time `xml:"lastModified"`
|
||||||
|
MediaType string `xml:"mediaType"`
|
||||||
|
PresentOnServer bool `xml:"presentOnServer"`
|
||||||
|
FileData string `xml:"fileData"`
|
||||||
|
Versions string `xml:"versions"`
|
||||||
|
PublicLink PublicLink
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collection represents
|
||||||
|
// - Workspace Collection
|
||||||
|
// - Sync Folders collection
|
||||||
|
// - Folder
|
||||||
|
type Collection struct {
|
||||||
|
Type string `xml:"type,attr"`
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
Ref string `xml:"ref"` // only for Folder
|
||||||
|
DsID string `xml:"dsid"`
|
||||||
|
TimeCreated time.Time `xml:"timeCreated"`
|
||||||
|
Parent string `xml:"parent"`
|
||||||
|
Collections string `xml:"collections"`
|
||||||
|
Files string `xml:"files"`
|
||||||
|
Contents string `xml:"contents"`
|
||||||
|
// Sharing bool `xml:"sharing>enabled,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CollectionContents is the result of a list call
|
||||||
|
type CollectionContents struct {
|
||||||
|
//XMLName xml.Name `xml:"collectionContents"`
|
||||||
|
Start int `xml:"start,attr"`
|
||||||
|
HasMore bool `xml:"hasMore,attr"`
|
||||||
|
End int `xml:"end,attr"`
|
||||||
|
Collections []Collection `xml:"collection"`
|
||||||
|
Files []File `xml:"file"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// User is returned from the /user call
|
||||||
|
type User struct {
|
||||||
|
XMLName xml.Name `xml:"user"`
|
||||||
|
Username string `xml:"username"`
|
||||||
|
Nickname string `xml:"nickname"`
|
||||||
|
Quota struct {
|
||||||
|
Limit int64 `xml:"limit"`
|
||||||
|
Usage int64 `xml:"usage"`
|
||||||
|
} `xml:"quota"`
|
||||||
|
Workspaces string `xml:"workspaces"`
|
||||||
|
SyncFolders string `xml:"syncfolders"`
|
||||||
|
Deleted string `xml:"deleted"`
|
||||||
|
MagicBriefcase string `xml:"magicBriefcase"`
|
||||||
|
WebArchive string `xml:"webArchive"`
|
||||||
|
MobilePhotos string `xml:"mobilePhotos"`
|
||||||
|
Albums string `xml:"albums"`
|
||||||
|
RecentActivities string `xml:"recentActivities"`
|
||||||
|
ReceivedShares string `xml:"receivedShares"`
|
||||||
|
PublicLinks string `xml:"publicLinks"`
|
||||||
|
MaximumPublicLinkSize int `xml:"maximumPublicLinkSize"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFolder is posted to a folder URL to create a folder
|
||||||
|
type CreateFolder struct {
|
||||||
|
XMLName xml.Name `xml:"folder"`
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MoveFolder is posted to a folder URL to move a folder
|
||||||
|
type MoveFolder struct {
|
||||||
|
XMLName xml.Name `xml:"folder"`
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
Parent string `xml:"parent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateSyncFolder is posted to the root folder URL to create a sync folder
|
||||||
|
type CreateSyncFolder struct {
|
||||||
|
XMLName xml.Name `xml:"syncFolder"`
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFile is posted to a folder URL to create a file
|
||||||
|
type CreateFile struct {
|
||||||
|
XMLName xml.Name `xml:"file"`
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
MediaType string `xml:"mediaType"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MoveFile is posted to a file URL to create a file
|
||||||
|
type MoveFile struct {
|
||||||
|
XMLName xml.Name `xml:"file"`
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
Parent string `xml:"parent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CopyFile copies a file from source
|
||||||
|
type CopyFile struct {
|
||||||
|
XMLName xml.Name `xml:"fileCopy"`
|
||||||
|
Source string `xml:"source,attr"`
|
||||||
|
Name string `xml:"displayName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublicLink is the URL and enabled flag for a public link
|
||||||
|
type PublicLink struct {
|
||||||
|
XMLName xml.Name `xml:"publicLink"`
|
||||||
|
URL string `xml:",chardata"`
|
||||||
|
Enabled bool `xml:"enabled,attr"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPublicLink can be used to enable the file for sharing
|
||||||
|
type SetPublicLink struct {
|
||||||
|
XMLName xml.Name `xml:"file"`
|
||||||
|
PublicLink PublicLink
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLastModified sets the modified time for a file
|
||||||
|
type SetLastModified struct {
|
||||||
|
XMLName xml.Name `xml:"file"`
|
||||||
|
LastModified time.Time `xml:"lastModified"`
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,59 @@
|
|||||||
|
package sugarsync
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestErrorHandler(t *testing.T) {
|
||||||
|
for _, test := range []struct {
|
||||||
|
name string
|
||||||
|
body string
|
||||||
|
code int
|
||||||
|
status string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
body: "",
|
||||||
|
code: 500,
|
||||||
|
status: "internal error",
|
||||||
|
want: `HTTP error 500 (internal error) returned body: ""`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unknown",
|
||||||
|
body: "<h1>unknown</h1>",
|
||||||
|
code: 500,
|
||||||
|
status: "internal error",
|
||||||
|
want: `HTTP error 500 (internal error) returned body: "<h1>unknown</h1>"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "blank",
|
||||||
|
body: "Nothing here <h3></h3>",
|
||||||
|
code: 500,
|
||||||
|
status: "internal error",
|
||||||
|
want: `HTTP error 500 (internal error) returned body: "Nothing here <h3></h3>"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "real",
|
||||||
|
body: "<h1>an error</h1>\n<h3>Can not move sync folder.</h3>\n<p>more stuff</p>",
|
||||||
|
code: 500,
|
||||||
|
status: "internal error",
|
||||||
|
want: `HTTP error 500 (internal error): Can not move sync folder.`,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
resp := http.Response{
|
||||||
|
Body: ioutil.NopCloser(bytes.NewBufferString(test.body)),
|
||||||
|
StatusCode: test.code,
|
||||||
|
Status: test.status,
|
||||||
|
}
|
||||||
|
got := errorHandler(&resp)
|
||||||
|
assert.Equal(t, test.want, got.Error())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Test Sugarsync filesystem interface
|
||||||
|
package sugarsync_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/backend/sugarsync"
|
||||||
|
"github.com/rclone/rclone/fstest/fstests"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestIntegration runs integration tests against the remote
|
||||||
|
func TestIntegration(t *testing.T) {
|
||||||
|
fstests.Run(t, &fstests.Opt{
|
||||||
|
RemoteName: "TestSugarSync:Test",
|
||||||
|
NilObject: (*sugarsync.Object)(nil),
|
||||||
|
})
|
||||||
|
}
|
||||||
+34
-28
@@ -16,15 +16,16 @@ import (
|
|||||||
"github.com/ncw/swift"
|
"github.com/ncw/swift"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/config"
|
||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/operations"
|
"github.com/rclone/rclone/fs/operations"
|
||||||
"github.com/rclone/rclone/fs/walk"
|
"github.com/rclone/rclone/fs/walk"
|
||||||
"github.com/rclone/rclone/lib/bucket"
|
"github.com/rclone/rclone/lib/bucket"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
)
|
)
|
||||||
@@ -60,10 +61,14 @@ Rclone will still chunk files bigger than chunk_size when doing normal
|
|||||||
copy operations.`,
|
copy operations.`,
|
||||||
Default: false,
|
Default: false,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
Default: (encoder.EncodeInvalidUtf8 |
|
||||||
|
encoder.EncodeSlash),
|
||||||
}}
|
}}
|
||||||
|
|
||||||
const enc = encodings.Swift
|
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
func init() {
|
func init() {
|
||||||
fs.Register(&fs.RegInfo{
|
fs.Register(&fs.RegInfo{
|
||||||
@@ -109,7 +114,7 @@ func init() {
|
|||||||
Value: "https://auth.storage.memset.com/v2.0",
|
Value: "https://auth.storage.memset.com/v2.0",
|
||||||
}, {
|
}, {
|
||||||
Help: "OVH",
|
Help: "OVH",
|
||||||
Value: "https://auth.cloud.ovh.net/v2.0",
|
Value: "https://auth.cloud.ovh.net/v3",
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
Name: "user_id",
|
Name: "user_id",
|
||||||
@@ -187,26 +192,27 @@ provider.`,
|
|||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
EnvAuth bool `config:"env_auth"`
|
EnvAuth bool `config:"env_auth"`
|
||||||
User string `config:"user"`
|
User string `config:"user"`
|
||||||
Key string `config:"key"`
|
Key string `config:"key"`
|
||||||
Auth string `config:"auth"`
|
Auth string `config:"auth"`
|
||||||
UserID string `config:"user_id"`
|
UserID string `config:"user_id"`
|
||||||
Domain string `config:"domain"`
|
Domain string `config:"domain"`
|
||||||
Tenant string `config:"tenant"`
|
Tenant string `config:"tenant"`
|
||||||
TenantID string `config:"tenant_id"`
|
TenantID string `config:"tenant_id"`
|
||||||
TenantDomain string `config:"tenant_domain"`
|
TenantDomain string `config:"tenant_domain"`
|
||||||
Region string `config:"region"`
|
Region string `config:"region"`
|
||||||
StorageURL string `config:"storage_url"`
|
StorageURL string `config:"storage_url"`
|
||||||
AuthToken string `config:"auth_token"`
|
AuthToken string `config:"auth_token"`
|
||||||
AuthVersion int `config:"auth_version"`
|
AuthVersion int `config:"auth_version"`
|
||||||
ApplicationCredentialID string `config:"application_credential_id"`
|
ApplicationCredentialID string `config:"application_credential_id"`
|
||||||
ApplicationCredentialName string `config:"application_credential_name"`
|
ApplicationCredentialName string `config:"application_credential_name"`
|
||||||
ApplicationCredentialSecret string `config:"application_credential_secret"`
|
ApplicationCredentialSecret string `config:"application_credential_secret"`
|
||||||
StoragePolicy string `config:"storage_policy"`
|
StoragePolicy string `config:"storage_policy"`
|
||||||
EndpointType string `config:"endpoint_type"`
|
EndpointType string `config:"endpoint_type"`
|
||||||
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
ChunkSize fs.SizeSuffix `config:"chunk_size"`
|
||||||
NoChunk bool `config:"no_chunk"`
|
NoChunk bool `config:"no_chunk"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote swift server
|
// Fs represents a remote swift server
|
||||||
@@ -325,7 +331,7 @@ func parsePath(path string) (root string) {
|
|||||||
// relative to f.root
|
// relative to f.root
|
||||||
func (f *Fs) split(rootRelativePath string) (container, containerPath string) {
|
func (f *Fs) split(rootRelativePath string) (container, containerPath string) {
|
||||||
container, containerPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
container, containerPath = bucket.Split(path.Join(f.root, rootRelativePath))
|
||||||
return enc.FromStandardName(container), enc.FromStandardPath(containerPath)
|
return f.opt.Enc.FromStandardName(container), f.opt.Enc.FromStandardPath(containerPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// split returns container and containerPath from the object
|
// split returns container and containerPath from the object
|
||||||
@@ -446,7 +452,7 @@ func NewFsWithConnection(opt *Options, name, root string, c *swift.Connection, n
|
|||||||
// Check to see if the object exists - ignoring directory markers
|
// Check to see if the object exists - ignoring directory markers
|
||||||
var info swift.Object
|
var info swift.Object
|
||||||
var err error
|
var err error
|
||||||
encodedDirectory := enc.FromStandardPath(f.rootDirectory)
|
encodedDirectory := f.opt.Enc.FromStandardPath(f.rootDirectory)
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
var rxHeaders swift.Headers
|
var rxHeaders swift.Headers
|
||||||
info, rxHeaders, err = f.c.Object(f.rootContainer, encodedDirectory)
|
info, rxHeaders, err = f.c.Object(f.rootContainer, encodedDirectory)
|
||||||
@@ -559,7 +565,7 @@ func (f *Fs) listContainerRoot(container, directory, prefix string, addContainer
|
|||||||
if !recurse {
|
if !recurse {
|
||||||
isDirectory = strings.HasSuffix(object.Name, "/")
|
isDirectory = strings.HasSuffix(object.Name, "/")
|
||||||
}
|
}
|
||||||
remote := enc.ToStandardPath(object.Name)
|
remote := f.opt.Enc.ToStandardPath(object.Name)
|
||||||
if !strings.HasPrefix(remote, prefix) {
|
if !strings.HasPrefix(remote, prefix) {
|
||||||
fs.Logf(f, "Odd name received %q", remote)
|
fs.Logf(f, "Odd name received %q", remote)
|
||||||
continue
|
continue
|
||||||
@@ -642,7 +648,7 @@ func (f *Fs) listContainers(ctx context.Context) (entries fs.DirEntries, err err
|
|||||||
}
|
}
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
f.cache.MarkOK(container.Name)
|
f.cache.MarkOK(container.Name)
|
||||||
d := fs.NewDir(enc.ToStandardName(container.Name), time.Time{}).SetSize(container.Bytes).SetItems(container.Count)
|
d := fs.NewDir(f.opt.Enc.ToStandardName(container.Name), time.Time{}).SetSize(container.Bytes).SetItems(container.Count)
|
||||||
entries = append(entries, d)
|
entries = append(entries, d)
|
||||||
}
|
}
|
||||||
return entries, nil
|
return entries, nil
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
// TestIntegration runs integration tests against the remote
|
// TestIntegration runs integration tests against the remote
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
fstests.Run(t, &fstests.Opt{
|
fstests.Run(t, &fstests.Opt{
|
||||||
RemoteName: "TestSwift:",
|
RemoteName: "TestSwiftAIO:",
|
||||||
NilObject: (*Object)(nil),
|
NilObject: (*Object)(nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,6 +358,7 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
f.srv.SetHeader("Referer", u.String())
|
||||||
|
|
||||||
if root != "" && !rootIsDir {
|
if root != "" && !rootIsDir {
|
||||||
// Check to see if the root actually an existing file
|
// Check to see if the root actually an existing file
|
||||||
@@ -837,7 +838,7 @@ func (f *Fs) copyOrMove(ctx context.Context, src fs.Object, remote string, metho
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if f.useOCMtime {
|
if f.useOCMtime {
|
||||||
opts.ExtraHeaders["X-OC-Mtime"] = fmt.Sprintf("%f", float64(src.ModTime(ctx).UnixNano())/1e9)
|
opts.ExtraHeaders["X-OC-Mtime"] = fmt.Sprintf("%d", src.ModTime(ctx).Unix())
|
||||||
}
|
}
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
resp, err = f.srv.Call(ctx, &opts)
|
resp, err = f.srv.Call(ctx, &opts)
|
||||||
@@ -1137,7 +1138,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
if o.fs.useOCMtime || o.fs.hasMD5 || o.fs.hasSHA1 {
|
if o.fs.useOCMtime || o.fs.hasMD5 || o.fs.hasSHA1 {
|
||||||
opts.ExtraHeaders = map[string]string{}
|
opts.ExtraHeaders = map[string]string{}
|
||||||
if o.fs.useOCMtime {
|
if o.fs.useOCMtime {
|
||||||
opts.ExtraHeaders["X-OC-Mtime"] = fmt.Sprintf("%f", float64(src.ModTime(ctx).UnixNano())/1e9)
|
opts.ExtraHeaders["X-OC-Mtime"] = fmt.Sprintf("%d", src.ModTime(ctx).Unix())
|
||||||
}
|
}
|
||||||
// Set one upload checksum
|
// Set one upload checksum
|
||||||
// Owncloud uses one checksum only to check the upload and stores its own SHA1 and MD5
|
// Owncloud uses one checksum only to check the upload and stores its own SHA1 and MD5
|
||||||
|
|||||||
@@ -5,13 +5,36 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/rclone/rclone/backend/webdav"
|
"github.com/rclone/rclone/backend/webdav"
|
||||||
|
"github.com/rclone/rclone/fstest"
|
||||||
"github.com/rclone/rclone/fstest/fstests"
|
"github.com/rclone/rclone/fstest/fstests"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestIntegration runs integration tests against the remote
|
// TestIntegration runs integration tests against the remote
|
||||||
func TestIntegration(t *testing.T) {
|
func TestIntegration(t *testing.T) {
|
||||||
fstests.Run(t, &fstests.Opt{
|
fstests.Run(t, &fstests.Opt{
|
||||||
RemoteName: "TestWebdav:",
|
RemoteName: "TestWebdavNexcloud:",
|
||||||
|
NilObject: (*webdav.Object)(nil),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestIntegration runs integration tests against the remote
|
||||||
|
func TestIntegration2(t *testing.T) {
|
||||||
|
if *fstest.RemoteName != "" {
|
||||||
|
t.Skip("skipping as -remote is set")
|
||||||
|
}
|
||||||
|
fstests.Run(t, &fstests.Opt{
|
||||||
|
RemoteName: "TestWebdavOwncloud:",
|
||||||
|
NilObject: (*webdav.Object)(nil),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestIntegration runs integration tests against the remote
|
||||||
|
func TestIntegration3(t *testing.T) {
|
||||||
|
if *fstest.RemoteName != "" {
|
||||||
|
t.Skip("skipping as -remote is set")
|
||||||
|
}
|
||||||
|
fstests.Run(t, &fstests.Opt{
|
||||||
|
RemoteName: "TestWebdavRclone:",
|
||||||
NilObject: (*webdav.Object)(nil),
|
NilObject: (*webdav.Object)(nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
+24
-17
@@ -20,9 +20,9 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
"github.com/rclone/rclone/fs/encodings"
|
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
|
"github.com/rclone/rclone/lib/encoder"
|
||||||
"github.com/rclone/rclone/lib/oauthutil"
|
"github.com/rclone/rclone/lib/oauthutil"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
"github.com/rclone/rclone/lib/readers"
|
"github.com/rclone/rclone/lib/readers"
|
||||||
@@ -30,8 +30,6 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const enc = encodings.Yandex
|
|
||||||
|
|
||||||
//oAuth
|
//oAuth
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "ac39b43b9eba4cae8ffb788c06d816a8"
|
rcloneClientID = "ac39b43b9eba4cae8ffb788c06d816a8"
|
||||||
@@ -80,14 +78,23 @@ func init() {
|
|||||||
Help: "Remove existing public link to file/folder with link command rather than creating.\nDefault is false, meaning link command will create or retrieve public link.",
|
Help: "Remove existing public link to file/folder with link command rather than creating.\nDefault is false, meaning link command will create or retrieve public link.",
|
||||||
Default: false,
|
Default: false,
|
||||||
Advanced: true,
|
Advanced: true,
|
||||||
|
}, {
|
||||||
|
Name: config.ConfigEncoding,
|
||||||
|
Help: config.ConfigEncodingHelp,
|
||||||
|
Advanced: true,
|
||||||
|
// Of the control characters \t \n \r are allowed
|
||||||
|
// it doesn't seem worth making an exception for this
|
||||||
|
Default: (encoder.Display |
|
||||||
|
encoder.EncodeInvalidUtf8),
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options defines the configuration for this backend
|
// Options defines the configuration for this backend
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Token string `config:"token"`
|
Token string `config:"token"`
|
||||||
Unlink bool `config:"unlink"`
|
Unlink bool `config:"unlink"`
|
||||||
|
Enc encoder.MultiEncoder `config:"encoding"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fs represents a remote yandex
|
// Fs represents a remote yandex
|
||||||
@@ -210,7 +217,7 @@ func (f *Fs) readMetaDataForPath(ctx context.Context, path string, options *api.
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(path))
|
opts.Parameters.Set("path", f.opt.Enc.FromStandardPath(path))
|
||||||
|
|
||||||
if options.SortMode != nil {
|
if options.SortMode != nil {
|
||||||
opts.Parameters.Set("sort", options.SortMode.String())
|
opts.Parameters.Set("sort", options.SortMode.String())
|
||||||
@@ -237,7 +244,7 @@ func (f *Fs) readMetaDataForPath(ctx context.Context, path string, options *api.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info.Name = enc.ToStandardName(info.Name)
|
info.Name = f.opt.Enc.ToStandardName(info.Name)
|
||||||
return &info, nil
|
return &info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +371,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
|||||||
if info.ResourceType == "dir" {
|
if info.ResourceType == "dir" {
|
||||||
//list all subdirs
|
//list all subdirs
|
||||||
for _, element := range info.Embedded.Items {
|
for _, element := range info.Embedded.Items {
|
||||||
element.Name = enc.ToStandardName(element.Name)
|
element.Name = f.opt.Enc.ToStandardName(element.Name)
|
||||||
remote := path.Join(dir, element.Name)
|
remote := path.Join(dir, element.Name)
|
||||||
entry, err := f.itemToDirEntry(ctx, remote, &element)
|
entry, err := f.itemToDirEntry(ctx, remote, &element)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -467,7 +474,7 @@ func (f *Fs) CreateDir(ctx context.Context, path string) (err error) {
|
|||||||
if strings.IndexRune(path, ':') >= 0 {
|
if strings.IndexRune(path, ':') >= 0 {
|
||||||
path = "disk:" + path
|
path = "disk:" + path
|
||||||
}
|
}
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(path))
|
opts.Parameters.Set("path", f.opt.Enc.FromStandardPath(path))
|
||||||
|
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
resp, err = f.srv.Call(ctx, &opts)
|
resp, err = f.srv.Call(ctx, &opts)
|
||||||
@@ -581,7 +588,7 @@ func (f *Fs) delete(ctx context.Context, path string, hardDelete bool) (err erro
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(path))
|
opts.Parameters.Set("path", f.opt.Enc.FromStandardPath(path))
|
||||||
opts.Parameters.Set("permanently", strconv.FormatBool(hardDelete))
|
opts.Parameters.Set("permanently", strconv.FormatBool(hardDelete))
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
@@ -653,8 +660,8 @@ func (f *Fs) copyOrMove(ctx context.Context, method, src, dst string, overwrite
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set("from", enc.FromStandardPath(src))
|
opts.Parameters.Set("from", f.opt.Enc.FromStandardPath(src))
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(dst))
|
opts.Parameters.Set("path", f.opt.Enc.FromStandardPath(dst))
|
||||||
opts.Parameters.Set("overwrite", strconv.FormatBool(overwrite))
|
opts.Parameters.Set("overwrite", strconv.FormatBool(overwrite))
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
@@ -803,12 +810,12 @@ func (f *Fs) PublicLink(ctx context.Context, remote string) (link string, err er
|
|||||||
}
|
}
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "PUT",
|
Method: "PUT",
|
||||||
Path: enc.FromStandardPath(path),
|
Path: f.opt.Enc.FromStandardPath(path),
|
||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
NoResponse: true,
|
NoResponse: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(f.filePath(remote)))
|
opts.Parameters.Set("path", f.opt.Enc.FromStandardPath(f.filePath(remote)))
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@@ -994,7 +1001,7 @@ func (o *Object) setCustomProperty(ctx context.Context, property string, value s
|
|||||||
NoResponse: true,
|
NoResponse: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(o.filePath()))
|
opts.Parameters.Set("path", o.fs.opt.Enc.FromStandardPath(o.filePath()))
|
||||||
rcm := map[string]interface{}{
|
rcm := map[string]interface{}{
|
||||||
property: value,
|
property: value,
|
||||||
}
|
}
|
||||||
@@ -1031,7 +1038,7 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(o.filePath()))
|
opts.Parameters.Set("path", o.fs.opt.Enc.FromStandardPath(o.filePath()))
|
||||||
|
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
resp, err = o.fs.srv.CallJSON(ctx, &opts, nil, &dl)
|
resp, err = o.fs.srv.CallJSON(ctx, &opts, nil, &dl)
|
||||||
@@ -1068,7 +1075,7 @@ func (o *Object) upload(ctx context.Context, in io.Reader, overwrite bool, mimeT
|
|||||||
Parameters: url.Values{},
|
Parameters: url.Values{},
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Parameters.Set("path", enc.FromStandardPath(o.filePath()))
|
opts.Parameters.Set("path", o.fs.opt.Enc.FromStandardPath(o.filePath()))
|
||||||
opts.Parameters.Set("overwrite", strconv.FormatBool(overwrite))
|
opts.Parameters.Set("overwrite", strconv.FormatBool(overwrite))
|
||||||
|
|
||||||
err = o.fs.pacer.Call(func() (bool, error) {
|
err = o.fs.pacer.Call(func() (bool, error) {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ docs = [
|
|||||||
"koofr.md",
|
"koofr.md",
|
||||||
"mailru.md",
|
"mailru.md",
|
||||||
"mega.md",
|
"mega.md",
|
||||||
|
"memory.md",
|
||||||
"azureblob.md",
|
"azureblob.md",
|
||||||
"onedrive.md",
|
"onedrive.md",
|
||||||
"opendrive.md",
|
"opendrive.md",
|
||||||
@@ -54,6 +55,7 @@ docs = [
|
|||||||
"premiumizeme.md",
|
"premiumizeme.md",
|
||||||
"putio.md",
|
"putio.md",
|
||||||
"sftp.md",
|
"sftp.md",
|
||||||
|
"sugarsync.md",
|
||||||
"union.md",
|
"union.md",
|
||||||
"webdav.md",
|
"webdav.md",
|
||||||
"yandex.md",
|
"yandex.md",
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import (
|
|||||||
_ "github.com/rclone/rclone/cmd/memtest"
|
_ "github.com/rclone/rclone/cmd/memtest"
|
||||||
_ "github.com/rclone/rclone/cmd/mkdir"
|
_ "github.com/rclone/rclone/cmd/mkdir"
|
||||||
_ "github.com/rclone/rclone/cmd/mount"
|
_ "github.com/rclone/rclone/cmd/mount"
|
||||||
|
_ "github.com/rclone/rclone/cmd/mount2"
|
||||||
_ "github.com/rclone/rclone/cmd/move"
|
_ "github.com/rclone/rclone/cmd/move"
|
||||||
_ "github.com/rclone/rclone/cmd/moveto"
|
_ "github.com/rclone/rclone/cmd/moveto"
|
||||||
_ "github.com/rclone/rclone/cmd/ncdu"
|
_ "github.com/rclone/rclone/cmd/ncdu"
|
||||||
|
|||||||
+2
-2
@@ -42,11 +42,11 @@ You can use it like this to output a single file
|
|||||||
|
|
||||||
rclone cat remote:path/to/file
|
rclone cat remote:path/to/file
|
||||||
|
|
||||||
Or like this to output any file in dir or subdirectories.
|
Or like this to output any file in dir or its subdirectories.
|
||||||
|
|
||||||
rclone cat remote:path/to/dir
|
rclone cat remote:path/to/dir
|
||||||
|
|
||||||
Or like this to output any .txt files in dir or subdirectories.
|
Or like this to output any .txt files in dir or its subdirectories.
|
||||||
|
|
||||||
rclone --include "*.txt" cat remote:path/to/dir
|
rclone --include "*.txt" cat remote:path/to/dir
|
||||||
|
|
||||||
|
|||||||
+16
-18
@@ -226,7 +226,7 @@ func ShowStats() bool {
|
|||||||
|
|
||||||
// Run the function with stats and retries if required
|
// Run the function with stats and retries if required
|
||||||
func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
||||||
var err error
|
var cmdErr error
|
||||||
stopStats := func() {}
|
stopStats := func() {}
|
||||||
if !showStats && ShowStats() {
|
if !showStats && ShowStats() {
|
||||||
showStats = true
|
showStats = true
|
||||||
@@ -238,11 +238,11 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
|||||||
}
|
}
|
||||||
SigInfoHandler()
|
SigInfoHandler()
|
||||||
for try := 1; try <= *retries; try++ {
|
for try := 1; try <= *retries; try++ {
|
||||||
err = f()
|
cmdErr = f()
|
||||||
err = fs.CountError(err)
|
cmdErr = fs.CountError(cmdErr)
|
||||||
lastErr := accounting.GlobalStats().GetLastError()
|
lastErr := accounting.GlobalStats().GetLastError()
|
||||||
if err == nil {
|
if cmdErr == nil {
|
||||||
err = lastErr
|
cmdErr = lastErr
|
||||||
}
|
}
|
||||||
if !Retry || !accounting.GlobalStats().Errored() {
|
if !Retry || !accounting.GlobalStats().Errored() {
|
||||||
if try > 1 {
|
if try > 1 {
|
||||||
@@ -278,15 +278,6 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stopStats()
|
stopStats()
|
||||||
if err != nil {
|
|
||||||
nerrs := accounting.GlobalStats().GetErrors()
|
|
||||||
if nerrs <= 1 {
|
|
||||||
log.Printf("Failed to %s: %v", cmd.Name(), err)
|
|
||||||
} else {
|
|
||||||
log.Printf("Failed to %s with %d errors: last error was: %v", cmd.Name(), nerrs, err)
|
|
||||||
}
|
|
||||||
resolveExitCode(err)
|
|
||||||
}
|
|
||||||
if showStats && (accounting.GlobalStats().Errored() || *statsInterval > 0) {
|
if showStats && (accounting.GlobalStats().Errored() || *statsInterval > 0) {
|
||||||
accounting.GlobalStats().Log()
|
accounting.GlobalStats().Log()
|
||||||
}
|
}
|
||||||
@@ -294,7 +285,7 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
|||||||
|
|
||||||
// dump all running go-routines
|
// dump all running go-routines
|
||||||
if fs.Config.Dump&fs.DumpGoRoutines != 0 {
|
if fs.Config.Dump&fs.DumpGoRoutines != 0 {
|
||||||
err = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
err := pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Errorf(nil, "Failed to dump goroutines: %v", err)
|
fs.Errorf(nil, "Failed to dump goroutines: %v", err)
|
||||||
}
|
}
|
||||||
@@ -305,15 +296,22 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
|||||||
c := exec.Command("lsof", "-p", strconv.Itoa(os.Getpid()))
|
c := exec.Command("lsof", "-p", strconv.Itoa(os.Getpid()))
|
||||||
c.Stdout = os.Stdout
|
c.Stdout = os.Stdout
|
||||||
c.Stderr = os.Stderr
|
c.Stderr = os.Stderr
|
||||||
err = c.Run()
|
err := c.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Errorf(nil, "Failed to list open files: %v", err)
|
fs.Errorf(nil, "Failed to list open files: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if accounting.GlobalStats().Errored() {
|
// Log the final error message and exit
|
||||||
resolveExitCode(accounting.GlobalStats().GetLastError())
|
if cmdErr != nil {
|
||||||
|
nerrs := accounting.GlobalStats().GetErrors()
|
||||||
|
if nerrs <= 1 {
|
||||||
|
log.Printf("Failed to %s: %v", cmd.Name(), cmdErr)
|
||||||
|
} else {
|
||||||
|
log.Printf("Failed to %s with %d errors: last error was: %v", cmd.Name(), nerrs, cmdErr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
resolveExitCode(cmdErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckArgs checks there are enough arguments and prints a message if not
|
// CheckArgs checks there are enough arguments and prints a message if not
|
||||||
|
|||||||
+14
-10
@@ -371,12 +371,7 @@ func (fsys *FS) Write(path string, buff []byte, ofst int64, fh uint64) (n int) {
|
|||||||
if errc != 0 {
|
if errc != 0 {
|
||||||
return errc
|
return errc
|
||||||
}
|
}
|
||||||
var err error
|
n, err := handle.WriteAt(buff, ofst)
|
||||||
if fsys.VFS.Opt.CacheMode < vfs.CacheModeWrites || handle.Node().Mode()&os.ModeAppend == 0 {
|
|
||||||
n, err = handle.WriteAt(buff, ofst)
|
|
||||||
} else {
|
|
||||||
n, err = handle.Write(buff)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return translateError(err)
|
return translateError(err)
|
||||||
}
|
}
|
||||||
@@ -441,6 +436,11 @@ func (fsys *FS) Rename(oldPath string, newPath string) (errc int) {
|
|||||||
return translateError(fsys.VFS.Rename(oldPath, newPath))
|
return translateError(fsys.VFS.Rename(oldPath, newPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows sometimes seems to send times that are the epoch which is
|
||||||
|
// 1601-01-01 +/- timezone so filter out times that are earlier than
|
||||||
|
// this.
|
||||||
|
var invalidDateCutoff = time.Date(1601, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
// Utimens changes the access and modification times of a file.
|
// Utimens changes the access and modification times of a file.
|
||||||
func (fsys *FS) Utimens(path string, tmsp []fuse.Timespec) (errc int) {
|
func (fsys *FS) Utimens(path string, tmsp []fuse.Timespec) (errc int) {
|
||||||
defer log.Trace(path, "tmsp=%+v", tmsp)("errc=%d", &errc)
|
defer log.Trace(path, "tmsp=%+v", tmsp)("errc=%d", &errc)
|
||||||
@@ -448,12 +448,16 @@ func (fsys *FS) Utimens(path string, tmsp []fuse.Timespec) (errc int) {
|
|||||||
if errc != 0 {
|
if errc != 0 {
|
||||||
return errc
|
return errc
|
||||||
}
|
}
|
||||||
var t time.Time
|
|
||||||
if tmsp == nil || len(tmsp) < 2 {
|
if tmsp == nil || len(tmsp) < 2 {
|
||||||
t = time.Now()
|
fs.Debugf(path, "Utimens: Not setting time as timespec isn't complete: %v", tmsp)
|
||||||
} else {
|
return 0
|
||||||
t = tmsp[1].Time()
|
|
||||||
}
|
}
|
||||||
|
t := tmsp[1].Time()
|
||||||
|
if t.Before(invalidDateCutoff) {
|
||||||
|
fs.Debugf(path, "Utimens: Not setting out of range time: %v", t)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
fs.Debugf(path, "Utimens: SetModTime: %v", t)
|
||||||
return translateError(node.SetModTime(t))
|
return translateError(node.SetModTime(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ func init() {
|
|||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
name = "mount"
|
name = "mount"
|
||||||
}
|
}
|
||||||
mountlib.NewMountCommand(name, Mount)
|
mountlib.NewMountCommand(name, false, Mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mountOptions configures the options from the command line flags
|
// mountOptions configures the options from the command line flags
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ you would do:
|
|||||||
If any of the parameters passed is a password field, then rclone will
|
If any of the parameters passed is a password field, then rclone will
|
||||||
automatically obscure them before putting them in the config file.
|
automatically obscure them before putting them in the config file.
|
||||||
|
|
||||||
If the remote uses oauth the token will be updated, if you don't
|
If the remote uses OAuth the token will be updated, if you don't
|
||||||
require this add an extra parameter thus:
|
require this add an extra parameter thus:
|
||||||
|
|
||||||
rclone config update myremote swift env_auth true config_refresh_token false
|
rclone config update myremote swift env_auth true config_refresh_token false
|
||||||
|
|||||||
+32
-12
@@ -2,6 +2,8 @@ package copyurl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/rclone/rclone/cmd"
|
"github.com/rclone/rclone/cmd"
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
@@ -12,37 +14,55 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
autoFilename = false
|
autoFilename = false
|
||||||
|
stdout = false
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd.Root.AddCommand(commandDefinition)
|
cmd.Root.AddCommand(commandDefinition)
|
||||||
cmdFlags := commandDefinition.Flags()
|
cmdFlags := commandDefinition.Flags()
|
||||||
flags.BoolVarP(cmdFlags, &autoFilename, "auto-filename", "a", autoFilename, "Get the file name from the url and use it for destination file path")
|
flags.BoolVarP(cmdFlags, &autoFilename, "auto-filename", "a", autoFilename, "Get the file name from the URL and use it for destination file path")
|
||||||
|
flags.BoolVarP(cmdFlags, &stdout, "stdout", "", stdout, "Write the output to stdout rather than a file")
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandDefinition = &cobra.Command{
|
var commandDefinition = &cobra.Command{
|
||||||
Use: "copyurl https://example.com dest:path",
|
Use: "copyurl https://example.com dest:path",
|
||||||
Short: `Copy url content to dest.`,
|
Short: `Copy url content to dest.`,
|
||||||
Long: `
|
Long: `
|
||||||
Download urls content and copy it to destination
|
Download a URL's content and copy it to the destination without saving
|
||||||
without saving it in tmp storage.
|
it in temporary storage.
|
||||||
|
|
||||||
Setting --auto-filename flag will cause retrieving file name from url and using it in destination path.
|
Setting --auto-filename will cause the file name to be retreived from
|
||||||
|
the from URL (after any redirections) and used in the destination
|
||||||
|
path.
|
||||||
|
|
||||||
|
Setting --stdout or making the output file name "-" will cause the
|
||||||
|
output to be written to standard output.
|
||||||
`,
|
`,
|
||||||
Run: func(command *cobra.Command, args []string) {
|
RunE: func(command *cobra.Command, args []string) (err error) {
|
||||||
cmd.CheckArgs(2, 2, command, args)
|
cmd.CheckArgs(1, 2, command, args)
|
||||||
|
|
||||||
var dstFileName string
|
var dstFileName string
|
||||||
var fsdst fs.Fs
|
var fsdst fs.Fs
|
||||||
if autoFilename {
|
if !stdout {
|
||||||
fsdst = cmd.NewFsDir(args[1:])
|
if len(args) < 2 {
|
||||||
} else {
|
return errors.New("need 2 arguments if not using --stdout")
|
||||||
fsdst, dstFileName = cmd.NewFsDstFile(args[1:])
|
}
|
||||||
|
if args[1] == "-" {
|
||||||
|
stdout = true
|
||||||
|
} else if autoFilename {
|
||||||
|
fsdst = cmd.NewFsDir(args[1:])
|
||||||
|
} else {
|
||||||
|
fsdst, dstFileName = cmd.NewFsDstFile(args[1:])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Run(true, true, command, func() error {
|
cmd.Run(true, true, command, func() error {
|
||||||
_, err := operations.CopyURL(context.Background(), fsdst, dstFileName, args[0], autoFilename)
|
if stdout {
|
||||||
|
err = operations.CopyURLToWriter(context.Background(), args[0], os.Stdout)
|
||||||
|
} else {
|
||||||
|
_, err = operations.CopyURL(context.Background(), fsdst, dstFileName, args[0], autoFilename)
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/rclone/rclone/backend/dropbox/dbhash"
|
"github.com/rclone/rclone/backend/dropbox"
|
||||||
"github.com/rclone/rclone/cmd"
|
"github.com/rclone/rclone/cmd"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
|
||||||
"github.com/rclone/rclone/fs/operations"
|
"github.com/rclone/rclone/fs/operations"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -28,8 +27,7 @@ The output is in the same format as md5sum and sha1sum.
|
|||||||
cmd.CheckArgs(1, 1, command, args)
|
cmd.CheckArgs(1, 1, command, args)
|
||||||
fsrc := cmd.NewFsSrc(args)
|
fsrc := cmd.NewFsSrc(args)
|
||||||
cmd.Run(false, false, command, func() error {
|
cmd.Run(false, false, command, func() error {
|
||||||
dbHashType := hash.RegisterHash("Dropbox", 64, dbhash.New)
|
return operations.HashLister(context.Background(), dropbox.DbHashType, fsrc, os.Stdout)
|
||||||
return operations.HashLister(context.Background(), dbHashType, fsrc, os.Stdout)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ var (
|
|||||||
func init() {
|
func init() {
|
||||||
cmd.Root.AddCommand(commandDefinition)
|
cmd.Root.AddCommand(commandDefinition)
|
||||||
cmdFlag := commandDefinition.Flags()
|
cmdFlag := commandDefinition.Flags()
|
||||||
flags.FVarP(cmdFlag, &dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
|
flags.FVarP(cmdFlag, &dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|largest|smallest|rename.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandDefinition = &cobra.Command{
|
var commandDefinition = &cobra.Command{
|
||||||
@@ -94,6 +94,7 @@ Dedupe can be run non interactively using the ` + "`" + `--dedupe-mode` + "`" +
|
|||||||
* ` + "`" + `--dedupe-mode newest` + "`" + ` - removes identical files then keeps the newest one.
|
* ` + "`" + `--dedupe-mode newest` + "`" + ` - removes identical files then keeps the newest one.
|
||||||
* ` + "`" + `--dedupe-mode oldest` + "`" + ` - removes identical files then keeps the oldest one.
|
* ` + "`" + `--dedupe-mode oldest` + "`" + ` - removes identical files then keeps the oldest one.
|
||||||
* ` + "`" + `--dedupe-mode largest` + "`" + ` - removes identical files then keeps the largest one.
|
* ` + "`" + `--dedupe-mode largest` + "`" + ` - removes identical files then keeps the largest one.
|
||||||
|
* ` + "`" + `--dedupe-mode smallest` + "`" + ` - removes identical files then keeps the smallest one.
|
||||||
* ` + "`" + `--dedupe-mode rename` + "`" + ` - removes identical files then renames the rest to be different.
|
* ` + "`" + `--dedupe-mode rename` + "`" + ` - removes identical files then renames the rest to be different.
|
||||||
|
|
||||||
For example to rename all the identically named photos in your Google Photos directory, do
|
For example to rename all the identically named photos in your Google Photos directory, do
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ date: %s
|
|||||||
title: "%s"
|
title: "%s"
|
||||||
slug: %s
|
slug: %s
|
||||||
url: %s
|
url: %s
|
||||||
|
# autogenerated - DO NOT EDIT, instead edit the source code in %s and as part of making a release run "make commanddocs"
|
||||||
---
|
---
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -67,7 +68,8 @@ rclone.org website.`,
|
|||||||
name := filepath.Base(filename)
|
name := filepath.Base(filename)
|
||||||
base := strings.TrimSuffix(name, path.Ext(name))
|
base := strings.TrimSuffix(name, path.Ext(name))
|
||||||
url := "/commands/" + strings.ToLower(base) + "/"
|
url := "/commands/" + strings.ToLower(base) + "/"
|
||||||
return fmt.Sprintf(gendocFrontmatterTemplate, now, strings.Replace(base, "_", " ", -1), base, url)
|
source := strings.Replace(strings.Replace(base, "rclone", "cmd", -1), "_", "/", -1) + "/"
|
||||||
|
return fmt.Sprintf(gendocFrontmatterTemplate, now, strings.Replace(base, "_", " ", -1), base, url, source)
|
||||||
}
|
}
|
||||||
linkHandler := func(name string) string {
|
linkHandler := func(name string) string {
|
||||||
base := strings.TrimSuffix(name, path.Ext(name))
|
base := strings.TrimSuffix(name, path.Ext(name))
|
||||||
|
|||||||
@@ -7,13 +7,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/rclone/rclone/cmd"
|
"github.com/rclone/rclone/cmd"
|
||||||
|
"github.com/rclone/rclone/fs/config/flags"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/operations"
|
"github.com/rclone/rclone/fs/operations"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
outputBase64 = false
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd.Root.AddCommand(commandDefinition)
|
cmd.Root.AddCommand(commandDefinition)
|
||||||
|
cmdFlags := commandDefinition.Flags()
|
||||||
|
flags.BoolVarP(cmdFlags, &outputBase64, "base64", "", outputBase64, "Output base64 encoded hashsum")
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandDefinition = &cobra.Command{
|
var commandDefinition = &cobra.Command{
|
||||||
@@ -55,6 +62,9 @@ Then
|
|||||||
}
|
}
|
||||||
fsrc := cmd.NewFsSrc(args[1:])
|
fsrc := cmd.NewFsSrc(args[1:])
|
||||||
cmd.Run(false, false, command, func() error {
|
cmd.Run(false, false, command, func() error {
|
||||||
|
if outputBase64 {
|
||||||
|
return operations.HashListerBase64(context.Background(), ht, fsrc, os.Stdout)
|
||||||
|
}
|
||||||
return operations.HashLister(context.Background(), ht, fsrc, os.Stdout)
|
return operations.HashLister(context.Background(), ht, fsrc, os.Stdout)
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+6
-4
@@ -166,10 +166,11 @@ func Lsf(ctx context.Context, fsrc fs.Fs, out io.Writer) error {
|
|||||||
list.SetDirSlash(dirSlash)
|
list.SetDirSlash(dirSlash)
|
||||||
list.SetAbsolute(absolute)
|
list.SetAbsolute(absolute)
|
||||||
var opt = operations.ListJSONOpt{
|
var opt = operations.ListJSONOpt{
|
||||||
NoModTime: true,
|
NoModTime: true,
|
||||||
DirsOnly: dirsOnly,
|
NoMimeType: true,
|
||||||
FilesOnly: filesOnly,
|
DirsOnly: dirsOnly,
|
||||||
Recurse: recurse,
|
FilesOnly: filesOnly,
|
||||||
|
Recurse: recurse,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, char := range format {
|
for _, char := range format {
|
||||||
@@ -188,6 +189,7 @@ func Lsf(ctx context.Context, fsrc fs.Fs, out io.Writer) error {
|
|||||||
list.AddID()
|
list.AddID()
|
||||||
case 'm':
|
case 'm':
|
||||||
list.AddMimeType()
|
list.AddMimeType()
|
||||||
|
opt.NoMimeType = false
|
||||||
case 'e':
|
case 'e':
|
||||||
list.AddEncrypted()
|
list.AddEncrypted()
|
||||||
opt.ShowEncrypted = true
|
opt.ShowEncrypted = true
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func init() {
|
|||||||
flags.BoolVarP(cmdFlags, &opt.Recurse, "recursive", "R", false, "Recurse into the listing.")
|
flags.BoolVarP(cmdFlags, &opt.Recurse, "recursive", "R", false, "Recurse into the listing.")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer).")
|
flags.BoolVarP(cmdFlags, &opt.ShowHash, "hash", "", false, "Include hashes in the output (may take longer).")
|
||||||
flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up).")
|
flags.BoolVarP(cmdFlags, &opt.NoModTime, "no-modtime", "", false, "Don't read the modification time (can speed things up).")
|
||||||
|
flags.BoolVarP(cmdFlags, &opt.NoMimeType, "no-mimetype", "", false, "Don't read the mime type (can speed things up).")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names.")
|
flags.BoolVarP(cmdFlags, &opt.ShowEncrypted, "encrypted", "M", false, "Show the encrypted names.")
|
||||||
flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object.")
|
flags.BoolVarP(cmdFlags, &opt.ShowOrigIDs, "original", "", false, "Show the ID of the underlying Object.")
|
||||||
flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing.")
|
flags.BoolVarP(cmdFlags, &opt.FilesOnly, "files-only", "", false, "Show only files in the listing.")
|
||||||
@@ -59,7 +60,9 @@ The output is an array of Items, where each Item looks like this
|
|||||||
|
|
||||||
If --hash is not specified the Hashes property won't be emitted.
|
If --hash is not specified the Hashes property won't be emitted.
|
||||||
|
|
||||||
If --no-modtime is specified then ModTime will be blank.
|
If --no-modtime is specified then ModTime will be blank. This can speed things up on remotes where reading the ModTime takes an extra request (eg s3, swift).
|
||||||
|
|
||||||
|
If --no-mimetype is specified then MimeType will be blank. This can speed things up on remotes where reading the MimeType takes an extra request (eg s3, swift).
|
||||||
|
|
||||||
If --encrypted is not specified the Encrypted won't be emitted.
|
If --encrypted is not specified the Encrypted won't be emitted.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// +build linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// +build linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
|
|
||||||
package mount
|
package mount
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// +build linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// +build linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
|
|
||||||
package mount
|
package mount
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// FUSE main Fs
|
// FUSE main Fs
|
||||||
|
|
||||||
// +build linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// +build linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
|
|
||||||
package mount
|
package mount
|
||||||
|
|
||||||
|
|||||||
+2
-8
@@ -1,11 +1,10 @@
|
|||||||
// +build linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// +build linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
|
|
||||||
package mount
|
package mount
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
|
|
||||||
"bazil.org/fuse"
|
"bazil.org/fuse"
|
||||||
fusefs "bazil.org/fuse/fs"
|
fusefs "bazil.org/fuse/fs"
|
||||||
@@ -42,12 +41,7 @@ var _ fusefs.HandleWriter = (*FileHandle)(nil)
|
|||||||
// Write data to the file handle
|
// Write data to the file handle
|
||||||
func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) (err error) {
|
func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) (err error) {
|
||||||
defer log.Trace(fh, "len=%d, offset=%d", len(req.Data), req.Offset)("written=%d, err=%v", &resp.Size, &err)
|
defer log.Trace(fh, "len=%d, offset=%d", len(req.Data), req.Offset)("written=%d, err=%v", &resp.Size, &err)
|
||||||
var n int
|
n, err := fh.Handle.WriteAt(req.Data, req.Offset)
|
||||||
if fh.Handle.Node().VFS().Opt.CacheMode < vfs.CacheModeWrites || fh.Handle.Node().Mode()&os.ModeAppend == 0 {
|
|
||||||
n, err = fh.Handle.WriteAt(req.Data, req.Offset)
|
|
||||||
} else {
|
|
||||||
n, err = fh.Handle.Write(req.Data)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return translateError(err)
|
return translateError(err)
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,6 @@
|
|||||||
// Package mount implents a FUSE mounting system for rclone remotes.
|
// Package mount implents a FUSE mounting system for rclone remotes.
|
||||||
|
|
||||||
// +build linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// +build linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
|
|
||||||
package mount
|
package mount
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
mountlib.NewMountCommand("mount", Mount)
|
mountlib.NewMountCommand("mount", false, Mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// mountOptions configures the options from the command line flags
|
// mountOptions configures the options from the command line flags
|
||||||
@@ -32,12 +32,14 @@ func mountOptions(device string) (options []fuse.MountOption) {
|
|||||||
fuse.Subtype("rclone"),
|
fuse.Subtype("rclone"),
|
||||||
fuse.FSName(device),
|
fuse.FSName(device),
|
||||||
fuse.VolumeName(mountlib.VolumeName),
|
fuse.VolumeName(mountlib.VolumeName),
|
||||||
fuse.AsyncRead(),
|
|
||||||
|
|
||||||
// Options from benchmarking in the fuse module
|
// Options from benchmarking in the fuse module
|
||||||
//fuse.MaxReadahead(64 * 1024 * 1024),
|
//fuse.MaxReadahead(64 * 1024 * 1024),
|
||||||
//fuse.WritebackCache(),
|
//fuse.WritebackCache(),
|
||||||
}
|
}
|
||||||
|
if mountlib.AsyncRead {
|
||||||
|
options = append(options, fuse.AsyncRead())
|
||||||
|
}
|
||||||
if mountlib.NoAppleDouble {
|
if mountlib.NoAppleDouble {
|
||||||
options = append(options, fuse.NoAppleDouble())
|
options = append(options, fuse.NoAppleDouble())
|
||||||
}
|
}
|
||||||
@@ -51,7 +53,8 @@ func mountOptions(device string) (options []fuse.MountOption) {
|
|||||||
options = append(options, fuse.AllowOther())
|
options = append(options, fuse.AllowOther())
|
||||||
}
|
}
|
||||||
if mountlib.AllowRoot {
|
if mountlib.AllowRoot {
|
||||||
options = append(options, fuse.AllowRoot())
|
// options = append(options, fuse.AllowRoot())
|
||||||
|
fs.Errorf(nil, "Ignoring --allow-root. Support has been removed upstream - see https://github.com/bazil/fuse/issues/144 for more info")
|
||||||
}
|
}
|
||||||
if mountlib.DefaultPermissions {
|
if mountlib.DefaultPermissions {
|
||||||
options = append(options, fuse.DefaultPermissions())
|
options = append(options, fuse.DefaultPermissions())
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// +build linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
|
|
||||||
package mount
|
package mount
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
// Build for mount for unsupported platforms to stop go complaining
|
// Build for mount for unsupported platforms to stop go complaining
|
||||||
// about "no buildable Go source files "
|
// about "no buildable Go source files "
|
||||||
|
|
||||||
// Invert the build constraint: linux,go1.11 darwin,go1.11 freebsd,go1.11
|
// Invert the build constraint: linux,go1.13 darwin,go1.13 freebsd,go1.13
|
||||||
//
|
//
|
||||||
// !((linux&&go1.11) || (darwin&&go1.11) || (freebsd&&go1.11))
|
// !((linux&&go1.13) || (darwin&&go1.13) || (freebsd&&go1.13))
|
||||||
// == !(linux&&go1.11) && !(darwin&&go1.11) && !(freebsd&&go1.11))
|
// == !(linux&&go1.13) && !(darwin&&go1.13) && !(freebsd&&go1.13))
|
||||||
// == (!linux || !go1.11) && (!darwin || go1.11) && (!freebsd || !go1.11))
|
// == (!linux || !go1.13) && (!darwin || go1.13) && (!freebsd || !go1.13))
|
||||||
|
|
||||||
// +build !linux !go1.11
|
// +build !linux !go1.13
|
||||||
// +build !darwin !go1.11
|
// +build !darwin !go1.13
|
||||||
// +build !freebsd !go1.11
|
// +build !freebsd !go1.13
|
||||||
|
|
||||||
package mount
|
package mount
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
// +build linux darwin,amd64
|
||||||
|
|
||||||
|
package mount2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
fusefs "github.com/hanwen/go-fuse/v2/fs"
|
||||||
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
|
"github.com/rclone/rclone/fs/log"
|
||||||
|
"github.com/rclone/rclone/vfs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileHandle is a resource identifier for opened files. Usually, a
|
||||||
|
// FileHandle should implement some of the FileXxxx interfaces.
|
||||||
|
//
|
||||||
|
// All of the FileXxxx operations can also be implemented at the
|
||||||
|
// InodeEmbedder level, for example, one can implement NodeReader
|
||||||
|
// instead of FileReader.
|
||||||
|
//
|
||||||
|
// FileHandles are useful in two cases: First, if the underlying
|
||||||
|
// storage systems needs a handle for reading/writing. This is the
|
||||||
|
// case with Unix system calls, which need a file descriptor (See also
|
||||||
|
// the function `NewLoopbackFile`). Second, it is useful for
|
||||||
|
// implementing files whose contents are not tied to an inode. For
|
||||||
|
// example, a file like `/proc/interrupts` has no fixed content, but
|
||||||
|
// changes on each open call. This means that each file handle must
|
||||||
|
// have its own view of the content; this view can be tied to a
|
||||||
|
// FileHandle. Files that have such dynamic content should return the
|
||||||
|
// FOPEN_DIRECT_IO flag from their `Open` method. See directio_test.go
|
||||||
|
// for an example.
|
||||||
|
type FileHandle struct {
|
||||||
|
h vfs.Handle
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new FileHandle
|
||||||
|
func newFileHandle(h vfs.Handle) *FileHandle {
|
||||||
|
return &FileHandle{
|
||||||
|
h: h,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check interface satistfied
|
||||||
|
var _ fusefs.FileHandle = (*FileHandle)(nil)
|
||||||
|
|
||||||
|
// The String method is for debug printing.
|
||||||
|
func (f *FileHandle) String() string {
|
||||||
|
return fmt.Sprintf("fh=%p(%s)", f, f.h.Node().Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read data from a file. The data should be returned as
|
||||||
|
// ReadResult, which may be constructed from the incoming
|
||||||
|
// `dest` buffer.
|
||||||
|
func (f *FileHandle) Read(ctx context.Context, dest []byte, off int64) (res fuse.ReadResult, errno syscall.Errno) {
|
||||||
|
var n int
|
||||||
|
var err error
|
||||||
|
defer log.Trace(f, "off=%d", off)("n=%d, off=%d, errno=%v", &n, &off, &errno)
|
||||||
|
n, err = f.h.ReadAt(dest, off)
|
||||||
|
if err == io.EOF {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
return fuse.ReadResultData(dest[:n]), translateError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.FileReader = (*FileHandle)(nil)
|
||||||
|
|
||||||
|
// Write the data into the file handle at given offset. After
|
||||||
|
// returning, the data will be reused and may not referenced.
|
||||||
|
func (f *FileHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, errno syscall.Errno) {
|
||||||
|
var n int
|
||||||
|
var err error
|
||||||
|
defer log.Trace(f, "off=%d", off)("n=%d, off=%d, errno=%v", &n, &off, &errno)
|
||||||
|
n, err = f.h.WriteAt(data, off)
|
||||||
|
return uint32(n), translateError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.FileWriter = (*FileHandle)(nil)
|
||||||
|
|
||||||
|
// Flush is called for the close(2) call on a file descriptor. In case
|
||||||
|
// of a descriptor that was duplicated using dup(2), it may be called
|
||||||
|
// more than once for the same FileHandle.
|
||||||
|
func (f *FileHandle) Flush(ctx context.Context) syscall.Errno {
|
||||||
|
return translateError(f.h.Flush())
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.FileFlusher = (*FileHandle)(nil)
|
||||||
|
|
||||||
|
// Release is called to before a FileHandle is forgotten. The
|
||||||
|
// kernel ignores the return value of this method,
|
||||||
|
// so any cleanup that requires specific synchronization or
|
||||||
|
// could fail with I/O errors should happen in Flush instead.
|
||||||
|
func (f *FileHandle) Release(ctx context.Context) syscall.Errno {
|
||||||
|
return translateError(f.h.Release())
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.FileReleaser = (*FileHandle)(nil)
|
||||||
|
|
||||||
|
// Fsync is a signal to ensure writes to the Inode are flushed
|
||||||
|
// to stable storage.
|
||||||
|
func (f *FileHandle) Fsync(ctx context.Context, flags uint32) (errno syscall.Errno) {
|
||||||
|
return translateError(f.h.Sync())
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.FileFsyncer = (*FileHandle)(nil)
|
||||||
|
|
||||||
|
// Getattr reads attributes for an Inode. The library will ensure that
|
||||||
|
// Mode and Ino are set correctly. For files that are not opened with
|
||||||
|
// FOPEN_DIRECTIO, Size should be set so it can be read correctly. If
|
||||||
|
// returning zeroed permissions, the default behavior is to change the
|
||||||
|
// mode of 0755 (directory) or 0644 (files). This can be switched off
|
||||||
|
// with the Options.NullPermissions setting. If blksize is unset, 4096
|
||||||
|
// is assumed, and the 'blocks' field is set accordingly.
|
||||||
|
func (f *FileHandle) Getattr(ctx context.Context, out *fuse.AttrOut) (errno syscall.Errno) {
|
||||||
|
defer log.Trace(f, "")("attr=%v, errno=%v", &out, &errno)
|
||||||
|
setAttrOut(f.h.Node(), out)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.FileGetattrer = (*FileHandle)(nil)
|
||||||
|
|
||||||
|
// Setattr sets attributes for an Inode.
|
||||||
|
func (f *FileHandle) Setattr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno) {
|
||||||
|
defer log.Trace(f, "in=%v", in)("attr=%v, errno=%v", &out, &errno)
|
||||||
|
var err error
|
||||||
|
setAttrOut(f.h.Node(), out)
|
||||||
|
size, ok := in.GetSize()
|
||||||
|
if ok {
|
||||||
|
err = f.h.Truncate(int64(size))
|
||||||
|
if err != nil {
|
||||||
|
return translateError(err)
|
||||||
|
}
|
||||||
|
out.Attr.Size = size
|
||||||
|
}
|
||||||
|
mtime, ok := in.GetMTime()
|
||||||
|
if ok {
|
||||||
|
err = f.h.Node().SetModTime(mtime)
|
||||||
|
if err != nil {
|
||||||
|
return translateError(err)
|
||||||
|
}
|
||||||
|
out.Attr.Mtime = uint64(mtime.Unix())
|
||||||
|
out.Attr.Mtimensec = uint32(mtime.Nanosecond())
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.FileSetattrer = (*FileHandle)(nil)
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
// FUSE main Fs
|
||||||
|
|
||||||
|
// +build linux darwin,amd64
|
||||||
|
|
||||||
|
package mount2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rclone/rclone/cmd/mountlib"
|
||||||
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/log"
|
||||||
|
"github.com/rclone/rclone/vfs"
|
||||||
|
"github.com/rclone/rclone/vfs/vfsflags"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FS represents the top level filing system
|
||||||
|
type FS struct {
|
||||||
|
VFS *vfs.VFS
|
||||||
|
f fs.Fs
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFS creates a pathfs.FileSystem from the fs.Fs passed in
|
||||||
|
func NewFS(f fs.Fs) *FS {
|
||||||
|
fsys := &FS{
|
||||||
|
VFS: vfs.New(f, &vfsflags.Opt),
|
||||||
|
f: f,
|
||||||
|
}
|
||||||
|
return fsys
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root returns the root node
|
||||||
|
func (f *FS) Root() (node *Node, err error) {
|
||||||
|
defer log.Trace("", "")("node=%+v, err=%v", &node, &err)
|
||||||
|
root, err := f.VFS.Root()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newNode(f, root), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDebug if called, provide debug output through the log package.
|
||||||
|
func (f *FS) SetDebug(debug bool) {
|
||||||
|
fs.Debugf(f.f, "SetDebug %v", debug)
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the Mode from a vfs Node
|
||||||
|
func getMode(node os.FileInfo) uint32 {
|
||||||
|
Mode := node.Mode().Perm()
|
||||||
|
if node.IsDir() {
|
||||||
|
Mode |= fuse.S_IFDIR
|
||||||
|
} else {
|
||||||
|
Mode |= fuse.S_IFREG
|
||||||
|
}
|
||||||
|
return uint32(Mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill in attr from node
|
||||||
|
func setAttr(node vfs.Node, attr *fuse.Attr) {
|
||||||
|
Size := uint64(node.Size())
|
||||||
|
const BlockSize = 512
|
||||||
|
Blocks := (Size + BlockSize - 1) / BlockSize
|
||||||
|
modTime := node.ModTime()
|
||||||
|
// set attributes
|
||||||
|
vfs := node.VFS()
|
||||||
|
attr.Owner.Gid = vfs.Opt.UID
|
||||||
|
attr.Owner.Uid = vfs.Opt.GID
|
||||||
|
attr.Mode = getMode(node)
|
||||||
|
attr.Size = Size
|
||||||
|
attr.Nlink = 1
|
||||||
|
attr.Blocks = Blocks
|
||||||
|
// attr.Blksize = BlockSize // not supported in freebsd/darwin, defaults to 4k if not set
|
||||||
|
s := uint64(modTime.Unix())
|
||||||
|
ns := uint32(modTime.Nanosecond())
|
||||||
|
attr.Atime = s
|
||||||
|
attr.Atimensec = ns
|
||||||
|
attr.Mtime = s
|
||||||
|
attr.Mtimensec = ns
|
||||||
|
attr.Ctime = s
|
||||||
|
attr.Ctimensec = ns
|
||||||
|
//attr.Rdev
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill in AttrOut from node
|
||||||
|
func setAttrOut(node vfs.Node, out *fuse.AttrOut) {
|
||||||
|
setAttr(node, &out.Attr)
|
||||||
|
out.SetTimeout(mountlib.AttrTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill in EntryOut from node
|
||||||
|
func setEntryOut(node vfs.Node, out *fuse.EntryOut) {
|
||||||
|
setAttr(node, &out.Attr)
|
||||||
|
out.SetEntryTimeout(mountlib.AttrTimeout)
|
||||||
|
out.SetAttrTimeout(mountlib.AttrTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translate errors from mountlib into Syscall error numbers
|
||||||
|
func translateError(err error) syscall.Errno {
|
||||||
|
if err == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
switch errors.Cause(err) {
|
||||||
|
case vfs.OK:
|
||||||
|
return 0
|
||||||
|
case vfs.ENOENT:
|
||||||
|
return syscall.ENOENT
|
||||||
|
case vfs.EEXIST:
|
||||||
|
return syscall.EEXIST
|
||||||
|
case vfs.EPERM:
|
||||||
|
return syscall.EPERM
|
||||||
|
case vfs.ECLOSED:
|
||||||
|
return syscall.EBADF
|
||||||
|
case vfs.ENOTEMPTY:
|
||||||
|
return syscall.ENOTEMPTY
|
||||||
|
case vfs.ESPIPE:
|
||||||
|
return syscall.ESPIPE
|
||||||
|
case vfs.EBADF:
|
||||||
|
return syscall.EBADF
|
||||||
|
case vfs.EROFS:
|
||||||
|
return syscall.EROFS
|
||||||
|
case vfs.ENOSYS:
|
||||||
|
return syscall.ENOSYS
|
||||||
|
case vfs.EINVAL:
|
||||||
|
return syscall.EINVAL
|
||||||
|
}
|
||||||
|
fs.Errorf(nil, "IO error: %v", err)
|
||||||
|
return syscall.EIO
|
||||||
|
}
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
// Package mount implents a FUSE mounting system for rclone remotes.
|
||||||
|
|
||||||
|
// +build linux darwin,amd64
|
||||||
|
|
||||||
|
package mount2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
fusefs "github.com/hanwen/go-fuse/v2/fs"
|
||||||
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
|
"github.com/okzk/sdnotify"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/rclone/rclone/cmd/mountlib"
|
||||||
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/lib/atexit"
|
||||||
|
"github.com/rclone/rclone/vfs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
mountlib.NewMountCommand("mount2", true, Mount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// mountOptions configures the options from the command line flags
|
||||||
|
//
|
||||||
|
// man mount.fuse for more info and note the -o flag for other options
|
||||||
|
func mountOptions(fsys *FS, f fs.Fs) (mountOpts *fuse.MountOptions) {
|
||||||
|
device := f.Name() + ":" + f.Root()
|
||||||
|
mountOpts = &fuse.MountOptions{
|
||||||
|
AllowOther: mountlib.AllowOther,
|
||||||
|
FsName: device,
|
||||||
|
Name: "rclone",
|
||||||
|
DisableXAttrs: true,
|
||||||
|
Debug: mountlib.DebugFUSE,
|
||||||
|
MaxReadAhead: int(mountlib.MaxReadAhead),
|
||||||
|
|
||||||
|
// RememberInodes: true,
|
||||||
|
// SingleThreaded: true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
AllowOther bool
|
||||||
|
|
||||||
|
// Options are passed as -o string to fusermount.
|
||||||
|
Options []string
|
||||||
|
|
||||||
|
// Default is _DEFAULT_BACKGROUND_TASKS, 12. This numbers
|
||||||
|
// controls the allowed number of requests that relate to
|
||||||
|
// async I/O. Concurrency for synchronous I/O is not limited.
|
||||||
|
MaxBackground int
|
||||||
|
|
||||||
|
// Write size to use. If 0, use default. This number is
|
||||||
|
// capped at the kernel maximum.
|
||||||
|
MaxWrite int
|
||||||
|
|
||||||
|
// Max read ahead to use. If 0, use default. This number is
|
||||||
|
// capped at the kernel maximum.
|
||||||
|
MaxReadAhead int
|
||||||
|
|
||||||
|
// If IgnoreSecurityLabels is set, all security related xattr
|
||||||
|
// requests will return NO_DATA without passing through the
|
||||||
|
// user defined filesystem. You should only set this if you
|
||||||
|
// file system implements extended attributes, and you are not
|
||||||
|
// interested in security labels.
|
||||||
|
IgnoreSecurityLabels bool // ignoring labels should be provided as a fusermount mount option.
|
||||||
|
|
||||||
|
// If RememberInodes is set, we will never forget inodes.
|
||||||
|
// This may be useful for NFS.
|
||||||
|
RememberInodes bool
|
||||||
|
|
||||||
|
// Values shown in "df -T" and friends
|
||||||
|
// First column, "Filesystem"
|
||||||
|
FsName string
|
||||||
|
|
||||||
|
// Second column, "Type", will be shown as "fuse." + Name
|
||||||
|
Name string
|
||||||
|
|
||||||
|
// If set, wrap the file system in a single-threaded locking wrapper.
|
||||||
|
SingleThreaded bool
|
||||||
|
|
||||||
|
// If set, return ENOSYS for Getxattr calls, so the kernel does not issue any
|
||||||
|
// Xattr operations at all.
|
||||||
|
DisableXAttrs bool
|
||||||
|
|
||||||
|
// If set, print debugging information.
|
||||||
|
Debug bool
|
||||||
|
|
||||||
|
// If set, ask kernel to forward file locks to FUSE. If using,
|
||||||
|
// you must implement the GetLk/SetLk/SetLkw methods.
|
||||||
|
EnableLocks bool
|
||||||
|
|
||||||
|
// If set, ask kernel not to do automatic data cache invalidation.
|
||||||
|
// The filesystem is fully responsible for invalidating data cache.
|
||||||
|
ExplicitDataCacheControl bool
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
var opts []string
|
||||||
|
// FIXME doesn't work opts = append(opts, fmt.Sprintf("max_readahead=%d", maxReadAhead))
|
||||||
|
if mountlib.AllowNonEmpty {
|
||||||
|
opts = append(opts, "nonempty")
|
||||||
|
}
|
||||||
|
if mountlib.AllowOther {
|
||||||
|
opts = append(opts, "allow_other")
|
||||||
|
}
|
||||||
|
if mountlib.AllowRoot {
|
||||||
|
opts = append(opts, "allow_root")
|
||||||
|
}
|
||||||
|
if mountlib.DefaultPermissions {
|
||||||
|
opts = append(opts, "default_permissions")
|
||||||
|
}
|
||||||
|
if fsys.VFS.Opt.ReadOnly {
|
||||||
|
opts = append(opts, "ro")
|
||||||
|
}
|
||||||
|
if mountlib.WritebackCache {
|
||||||
|
log.Printf("FIXME --write-back-cache not supported")
|
||||||
|
// FIXME opts = append(opts,fuse.WritebackCache())
|
||||||
|
}
|
||||||
|
// Some OS X only options
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
opts = append(opts,
|
||||||
|
// VolumeName sets the volume name shown in Finder.
|
||||||
|
fmt.Sprintf("volname=%s", device),
|
||||||
|
|
||||||
|
// NoAppleXattr makes OSXFUSE disallow extended attributes with the
|
||||||
|
// prefix "com.apple.". This disables persistent Finder state and
|
||||||
|
// other such information.
|
||||||
|
"noapplexattr",
|
||||||
|
|
||||||
|
// NoAppleDouble makes OSXFUSE disallow files with names used by OS X
|
||||||
|
// to store extended attributes on file systems that do not support
|
||||||
|
// them natively.
|
||||||
|
//
|
||||||
|
// Such file names are:
|
||||||
|
//
|
||||||
|
// ._*
|
||||||
|
// .DS_Store
|
||||||
|
"noappledouble",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
mountOpts.Options = opts
|
||||||
|
return mountOpts
|
||||||
|
}
|
||||||
|
|
||||||
|
// mount the file system
|
||||||
|
//
|
||||||
|
// The mount point will be ready when this returns.
|
||||||
|
//
|
||||||
|
// returns an error, and an error channel for the serve process to
|
||||||
|
// report an error when fusermount is called.
|
||||||
|
func mount(f fs.Fs, mountpoint string) (*vfs.VFS, <-chan error, func() error, error) {
|
||||||
|
fs.Debugf(f, "Mounting on %q", mountpoint)
|
||||||
|
|
||||||
|
fsys := NewFS(f)
|
||||||
|
// nodeFsOpts := &fusefs.PathNodeFsOptions{
|
||||||
|
// ClientInodes: false,
|
||||||
|
// Debug: mountlib.DebugFUSE,
|
||||||
|
// }
|
||||||
|
// nodeFs := fusefs.NewPathNodeFs(fsys, nodeFsOpts)
|
||||||
|
|
||||||
|
//mOpts := fusefs.NewOptions() // default options
|
||||||
|
// FIXME
|
||||||
|
// mOpts.EntryTimeout = 10 * time.Second
|
||||||
|
// mOpts.AttrTimeout = 10 * time.Second
|
||||||
|
// mOpts.NegativeTimeout = 10 * time.Second
|
||||||
|
//mOpts.Debug = mountlib.DebugFUSE
|
||||||
|
|
||||||
|
//conn := fusefs.NewFileSystemConnector(nodeFs.Root(), mOpts)
|
||||||
|
mountOpts := mountOptions(fsys, f)
|
||||||
|
|
||||||
|
// FIXME fill out
|
||||||
|
opts := fusefs.Options{
|
||||||
|
MountOptions: *mountOpts,
|
||||||
|
EntryTimeout: &mountlib.AttrTimeout,
|
||||||
|
AttrTimeout: &mountlib.AttrTimeout,
|
||||||
|
// UID
|
||||||
|
// GID
|
||||||
|
}
|
||||||
|
|
||||||
|
root, err := fsys.Root()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
rawFS := fusefs.NewNodeFS(root, &opts)
|
||||||
|
server, err := fuse.NewServer(rawFS, mountpoint, &opts.MountOptions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//mountOpts := &fuse.MountOptions{}
|
||||||
|
//server, err := fusefs.Mount(mountpoint, fsys, &opts)
|
||||||
|
// server, err := fusefs.Mount(mountpoint, root, &opts)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, nil, nil, err
|
||||||
|
// }
|
||||||
|
|
||||||
|
umount := func() error {
|
||||||
|
// Shutdown the VFS
|
||||||
|
fsys.VFS.Shutdown()
|
||||||
|
return server.Unmount()
|
||||||
|
}
|
||||||
|
|
||||||
|
// serverSettings := server.KernelSettings()
|
||||||
|
// fs.Debugf(f, "Server settings %+v", serverSettings)
|
||||||
|
|
||||||
|
// Serve the mount point in the background returning error to errChan
|
||||||
|
errs := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
server.Serve()
|
||||||
|
errs <- nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
fs.Debugf(f, "Waiting for the mount to start...")
|
||||||
|
err = server.WaitMount()
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.Debugf(f, "Mount started")
|
||||||
|
return fsys.VFS, errs, umount, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mount mounts the remote at mountpoint.
|
||||||
|
//
|
||||||
|
// If noModTime is set then it
|
||||||
|
func Mount(f fs.Fs, mountpoint string) error {
|
||||||
|
// Mount it
|
||||||
|
vfs, errChan, unmount, err := mount(f, mountpoint)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to mount FUSE fs")
|
||||||
|
}
|
||||||
|
|
||||||
|
sigInt := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigInt, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
sigHup := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigHup, syscall.SIGHUP)
|
||||||
|
atexit.Register(func() {
|
||||||
|
_ = unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := sdnotify.Ready(); err != nil && err != sdnotify.ErrSdNotifyNoSocket {
|
||||||
|
return errors.Wrap(err, "failed to notify systemd")
|
||||||
|
}
|
||||||
|
|
||||||
|
waitloop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
// umount triggered outside the app
|
||||||
|
case err = <-errChan:
|
||||||
|
break waitloop
|
||||||
|
// Program abort: umount
|
||||||
|
case <-sigInt:
|
||||||
|
err = unmount()
|
||||||
|
break waitloop
|
||||||
|
// user sent SIGHUP to clear the cache
|
||||||
|
case <-sigHup:
|
||||||
|
root, err := vfs.Root()
|
||||||
|
if err != nil {
|
||||||
|
fs.Errorf(f, "Error reading root: %v", err)
|
||||||
|
} else {
|
||||||
|
root.ForgetAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = sdnotify.Stopping()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to umount FUSE fs")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// +build linux darwin,amd64
|
||||||
|
|
||||||
|
package mount2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/cmd/mountlib/mounttest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMount(t *testing.T) {
|
||||||
|
mounttest.RunTests(t, mount)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// Build for mount for unsupported platforms to stop go complaining
|
||||||
|
// about "no buildable Go source files "
|
||||||
|
|
||||||
|
// +build !linux
|
||||||
|
// +build !darwin !amd64
|
||||||
|
|
||||||
|
package mount2
|
||||||
@@ -0,0 +1,400 @@
|
|||||||
|
// +build linux darwin,amd64
|
||||||
|
|
||||||
|
package mount2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
fusefs "github.com/hanwen/go-fuse/v2/fs"
|
||||||
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
|
"github.com/rclone/rclone/cmd/mountlib"
|
||||||
|
"github.com/rclone/rclone/fs"
|
||||||
|
"github.com/rclone/rclone/fs/log"
|
||||||
|
"github.com/rclone/rclone/vfs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Node represents a directory or file
|
||||||
|
type Node struct {
|
||||||
|
fusefs.Inode
|
||||||
|
node vfs.Node
|
||||||
|
fsys *FS
|
||||||
|
}
|
||||||
|
|
||||||
|
// Node types must be InodeEmbedders
|
||||||
|
var _ fusefs.InodeEmbedder = (*Node)(nil)
|
||||||
|
|
||||||
|
// newNode creates a new fusefs.Node from a vfs Node
|
||||||
|
func newNode(fsys *FS, node vfs.Node) *Node {
|
||||||
|
return &Node{
|
||||||
|
node: node,
|
||||||
|
fsys: fsys,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// String used for pretty printing.
|
||||||
|
func (n *Node) String() string {
|
||||||
|
return n.node.Path()
|
||||||
|
}
|
||||||
|
|
||||||
|
// lookup a Node in a directory
|
||||||
|
func (n *Node) lookupVfsNodeInDir(leaf string) (vfsNode vfs.Node, errno syscall.Errno) {
|
||||||
|
dir, ok := n.node.(*vfs.Dir)
|
||||||
|
if !ok {
|
||||||
|
return nil, syscall.ENOTDIR
|
||||||
|
}
|
||||||
|
vfsNode, err := dir.Stat(leaf)
|
||||||
|
return vfsNode, translateError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// // lookup a Dir given a path
|
||||||
|
// func (n *Node) lookupDir(path string) (dir *vfs.Dir, code fuse.Status) {
|
||||||
|
// node, code := fsys.lookupVfsNodeInDir(path)
|
||||||
|
// if !code.Ok() {
|
||||||
|
// return nil, code
|
||||||
|
// }
|
||||||
|
// dir, ok := n.(*vfs.Dir)
|
||||||
|
// if !ok {
|
||||||
|
// return nil, fuse.ENOTDIR
|
||||||
|
// }
|
||||||
|
// return dir, fuse.OK
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // lookup a parent Dir given a path returning the dir and the leaf
|
||||||
|
// func (n *Node) lookupParentDir(filePath string) (leaf string, dir *vfs.Dir, code fuse.Status) {
|
||||||
|
// parentDir, leaf := path.Split(filePath)
|
||||||
|
// dir, code = fsys.lookupDir(parentDir)
|
||||||
|
// return leaf, dir, code
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Statfs implements statistics for the filesystem that holds this
|
||||||
|
// Inode. If not defined, the `out` argument will zeroed with an OK
|
||||||
|
// result. This is because OSX filesystems must Statfs, or the mount
|
||||||
|
// will not work.
|
||||||
|
func (n *Node) Statfs(ctx context.Context, out *fuse.StatfsOut) syscall.Errno {
|
||||||
|
defer log.Trace(n, "")("out=%+v", &out)
|
||||||
|
out = new(fuse.StatfsOut)
|
||||||
|
const blockSize = 4096
|
||||||
|
const fsBlocks = (1 << 50) / blockSize
|
||||||
|
out.Blocks = fsBlocks // Total data blocks in file system.
|
||||||
|
out.Bfree = fsBlocks // Free blocks in file system.
|
||||||
|
out.Bavail = fsBlocks // Free blocks in file system if you're not root.
|
||||||
|
out.Files = 1e9 // Total files in file system.
|
||||||
|
out.Ffree = 1e9 // Free files in file system.
|
||||||
|
out.Bsize = blockSize // Block size
|
||||||
|
out.NameLen = 255 // Maximum file name length?
|
||||||
|
out.Frsize = blockSize // Fragment size, smallest addressable data size in the file system.
|
||||||
|
mountlib.ClipBlocks(&out.Blocks)
|
||||||
|
mountlib.ClipBlocks(&out.Bfree)
|
||||||
|
mountlib.ClipBlocks(&out.Bavail)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeStatfser)((*Node)(nil))
|
||||||
|
|
||||||
|
// Getattr reads attributes for an Inode. The library will ensure that
|
||||||
|
// Mode and Ino are set correctly. For files that are not opened with
|
||||||
|
// FOPEN_DIRECTIO, Size should be set so it can be read correctly. If
|
||||||
|
// returning zeroed permissions, the default behavior is to change the
|
||||||
|
// mode of 0755 (directory) or 0644 (files). This can be switched off
|
||||||
|
// with the Options.NullPermissions setting. If blksize is unset, 4096
|
||||||
|
// is assumed, and the 'blocks' field is set accordingly.
|
||||||
|
func (n *Node) Getattr(ctx context.Context, f fusefs.FileHandle, out *fuse.AttrOut) syscall.Errno {
|
||||||
|
setAttrOut(n.node, out)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeGetattrer)((*Node)(nil))
|
||||||
|
|
||||||
|
// Setattr sets attributes for an Inode.
|
||||||
|
func (n *Node) Setattr(ctx context.Context, f fusefs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "in=%v", in)("out=%#v, errno=%v", &out, &errno)
|
||||||
|
var err error
|
||||||
|
setAttrOut(n.node, out)
|
||||||
|
size, ok := in.GetSize()
|
||||||
|
if ok {
|
||||||
|
err = n.node.Truncate(int64(size))
|
||||||
|
if err != nil {
|
||||||
|
return translateError(err)
|
||||||
|
}
|
||||||
|
out.Attr.Size = size
|
||||||
|
}
|
||||||
|
mtime, ok := in.GetMTime()
|
||||||
|
if ok {
|
||||||
|
err = n.node.SetModTime(mtime)
|
||||||
|
if err != nil {
|
||||||
|
return translateError(err)
|
||||||
|
}
|
||||||
|
out.Attr.Mtime = uint64(mtime.Unix())
|
||||||
|
out.Attr.Mtimensec = uint32(mtime.Nanosecond())
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeSetattrer)((*Node)(nil))
|
||||||
|
|
||||||
|
// Open opens an Inode (of regular file type) for reading. It
|
||||||
|
// is optional but recommended to return a FileHandle.
|
||||||
|
func (n *Node) Open(ctx context.Context, flags uint32) (fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "flags=%#o", flags)("errno=%v", &errno)
|
||||||
|
// fuse flags are based off syscall flags as are os flags, so
|
||||||
|
// should be compatible
|
||||||
|
handle, err := n.node.Open(int(flags))
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, translateError(err)
|
||||||
|
}
|
||||||
|
// If size unknown then use direct io to read
|
||||||
|
if entry := n.node.DirEntry(); entry != nil && entry.Size() < 0 {
|
||||||
|
fuseFlags |= fuse.FOPEN_DIRECT_IO
|
||||||
|
}
|
||||||
|
return newFileHandle(handle), fuseFlags, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeOpener)((*Node)(nil))
|
||||||
|
|
||||||
|
// Lookup should find a direct child of a directory by the child's name. If
|
||||||
|
// the entry does not exist, it should return ENOENT and optionally
|
||||||
|
// set a NegativeTimeout in `out`. If it does exist, it should return
|
||||||
|
// attribute data in `out` and return the Inode for the child. A new
|
||||||
|
// inode can be created using `Inode.NewInode`. The new Inode will be
|
||||||
|
// added to the FS tree automatically if the return status is OK.
|
||||||
|
//
|
||||||
|
// If a directory does not implement NodeLookuper, the library looks
|
||||||
|
// for an existing child with the given name.
|
||||||
|
//
|
||||||
|
// The input to a Lookup is {parent directory, name string}.
|
||||||
|
//
|
||||||
|
// Lookup, if successful, must return an *Inode. Once the Inode is
|
||||||
|
// returned to the kernel, the kernel can issue further operations,
|
||||||
|
// such as Open or Getxattr on that node.
|
||||||
|
//
|
||||||
|
// A successful Lookup also returns an EntryOut. Among others, this
|
||||||
|
// contains file attributes (mode, size, mtime, etc.).
|
||||||
|
//
|
||||||
|
// FUSE supports other operations that modify the namespace. For
|
||||||
|
// example, the Symlink, Create, Mknod, Link methods all create new
|
||||||
|
// children in directories. Hence, they also return *Inode and must
|
||||||
|
// populate their fuse.EntryOut arguments.
|
||||||
|
func (n *Node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (inode *fusefs.Inode, errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "name=%q", name)("inode=%v, attr=%v, errno=%v", &inode, &out, &errno)
|
||||||
|
vfsNode, errno := n.lookupVfsNodeInDir(name)
|
||||||
|
if errno != 0 {
|
||||||
|
return nil, errno
|
||||||
|
}
|
||||||
|
newNode := &Node{
|
||||||
|
node: vfsNode,
|
||||||
|
fsys: n.fsys,
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
// out.SetEntryTimeout(dt time.Duration)
|
||||||
|
// out.SetAttrTimeout(dt time.Duration)
|
||||||
|
setEntryOut(vfsNode, out)
|
||||||
|
|
||||||
|
return n.NewInode(ctx, newNode, fusefs.StableAttr{Mode: out.Attr.Mode}), 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeLookuper)((*Node)(nil))
|
||||||
|
|
||||||
|
// Opendir opens a directory Inode for reading its
|
||||||
|
// contents. The actual reading is driven from Readdir, so
|
||||||
|
// this method is just for performing sanity/permission
|
||||||
|
// checks. The default is to return success.
|
||||||
|
func (n *Node) Opendir(ctx context.Context) syscall.Errno {
|
||||||
|
if !n.node.IsDir() {
|
||||||
|
return syscall.ENOTDIR
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeOpendirer)((*Node)(nil))
|
||||||
|
|
||||||
|
type dirStream struct {
|
||||||
|
nodes []os.FileInfo
|
||||||
|
i int
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasNext indicates if there are further entries. HasNext
|
||||||
|
// might be called on already closed streams.
|
||||||
|
func (ds *dirStream) HasNext() bool {
|
||||||
|
return ds.i < len(ds.nodes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next retrieves the next entry. It is only called if HasNext
|
||||||
|
// has previously returned true. The Errno return may be used to
|
||||||
|
// indicate I/O errors
|
||||||
|
func (ds *dirStream) Next() (de fuse.DirEntry, errno syscall.Errno) {
|
||||||
|
// defer log.Trace(nil, "")("de=%+v, errno=%v", &de, &errno)
|
||||||
|
fi := ds.nodes[ds.i]
|
||||||
|
de = fuse.DirEntry{
|
||||||
|
// Mode is the file's mode. Only the high bits (eg. S_IFDIR)
|
||||||
|
// are considered.
|
||||||
|
Mode: getMode(fi),
|
||||||
|
|
||||||
|
// Name is the basename of the file in the directory.
|
||||||
|
Name: path.Base(fi.Name()),
|
||||||
|
|
||||||
|
// Ino is the inode number.
|
||||||
|
Ino: 0, // FIXME
|
||||||
|
}
|
||||||
|
ds.i++
|
||||||
|
return de, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close releases resources related to this directory
|
||||||
|
// stream.
|
||||||
|
func (ds *dirStream) Close() {
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fusefs.DirStream = (*dirStream)(nil)
|
||||||
|
|
||||||
|
// Readdir opens a stream of directory entries.
|
||||||
|
//
|
||||||
|
// Readdir essentiallly returns a list of strings, and it is allowed
|
||||||
|
// for Readdir to return different results from Lookup. For example,
|
||||||
|
// you can return nothing for Readdir ("ls my-fuse-mount" is empty),
|
||||||
|
// while still implementing Lookup ("ls my-fuse-mount/a-specific-file"
|
||||||
|
// shows a single file).
|
||||||
|
//
|
||||||
|
// If a directory does not implement NodeReaddirer, a list of
|
||||||
|
// currently known children from the tree is returned. This means that
|
||||||
|
// static in-memory file systems need not implement NodeReaddirer.
|
||||||
|
func (n *Node) Readdir(ctx context.Context) (ds fusefs.DirStream, errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "")("ds=%v, errno=%v", &ds, &errno)
|
||||||
|
if !n.node.IsDir() {
|
||||||
|
return nil, syscall.ENOTDIR
|
||||||
|
}
|
||||||
|
fh, err := n.node.Open(os.O_RDONLY)
|
||||||
|
if err != nil {
|
||||||
|
return nil, translateError(err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
closeErr := fh.Close()
|
||||||
|
if errno == 0 && closeErr != nil {
|
||||||
|
errno = translateError(closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
items, err := fh.Readdir(-1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, translateError(err)
|
||||||
|
}
|
||||||
|
return &dirStream{
|
||||||
|
nodes: items,
|
||||||
|
}, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeReaddirer)((*Node)(nil))
|
||||||
|
|
||||||
|
// Mkdir is similar to Lookup, but must create a directory entry and Inode.
|
||||||
|
// Default is to return EROFS.
|
||||||
|
func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (inode *fusefs.Inode, errno syscall.Errno) {
|
||||||
|
defer log.Trace(name, "mode=0%o", mode)("inode=%v, errno=%v", &inode, &errno)
|
||||||
|
dir, ok := n.node.(*vfs.Dir)
|
||||||
|
if !ok {
|
||||||
|
return nil, syscall.ENOTDIR
|
||||||
|
}
|
||||||
|
newDir, err := dir.Mkdir(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, translateError(err)
|
||||||
|
}
|
||||||
|
newNode := newNode(n.fsys, newDir)
|
||||||
|
setEntryOut(newNode.node, out)
|
||||||
|
newInode := n.NewInode(ctx, newNode, fusefs.StableAttr{Mode: out.Attr.Mode})
|
||||||
|
return newInode, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeMkdirer)((*Node)(nil))
|
||||||
|
|
||||||
|
// Create is similar to Lookup, but should create a new
|
||||||
|
// child. It typically also returns a FileHandle as a
|
||||||
|
// reference for future reads/writes.
|
||||||
|
// Default is to return EROFS.
|
||||||
|
func (n *Node) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (node *fusefs.Inode, fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "name=%q, flags=%#o, mode=%#o", name, flags, mode)("node=%v, fh=%v, flags=%#o, errno=%v", &node, &fh, &fuseFlags, &errno)
|
||||||
|
dir, ok := n.node.(*vfs.Dir)
|
||||||
|
if !ok {
|
||||||
|
return nil, nil, 0, syscall.ENOTDIR
|
||||||
|
}
|
||||||
|
// translate the fuse flags to os flags
|
||||||
|
osFlags := int(flags) | os.O_CREATE
|
||||||
|
file, err := dir.Create(name, osFlags)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, 0, translateError(err)
|
||||||
|
}
|
||||||
|
handle, err := file.Open(osFlags)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, 0, translateError(err)
|
||||||
|
}
|
||||||
|
fh = newFileHandle(handle)
|
||||||
|
// FIXME
|
||||||
|
// fh = &fusefs.WithFlags{
|
||||||
|
// File: fh,
|
||||||
|
// //FuseFlags: fuse.FOPEN_NONSEEKABLE,
|
||||||
|
// OpenFlags: flags,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Find the created node
|
||||||
|
vfsNode, errno := n.lookupVfsNodeInDir(name)
|
||||||
|
if errno != 0 {
|
||||||
|
return nil, nil, 0, errno
|
||||||
|
}
|
||||||
|
setEntryOut(vfsNode, out)
|
||||||
|
newNode := newNode(n.fsys, vfsNode)
|
||||||
|
fs.Debugf(nil, "attr=%#v", out.Attr)
|
||||||
|
newInode := n.NewInode(ctx, newNode, fusefs.StableAttr{Mode: out.Attr.Mode})
|
||||||
|
return newInode, fh, 0, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeCreater)((*Node)(nil))
|
||||||
|
|
||||||
|
// Unlink should remove a child from this directory. If the
|
||||||
|
// return status is OK, the Inode is removed as child in the
|
||||||
|
// FS tree automatically. Default is to return EROFS.
|
||||||
|
func (n *Node) Unlink(ctx context.Context, name string) (errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "name=%q", name)("errno=%v", &errno)
|
||||||
|
vfsNode, errno := n.lookupVfsNodeInDir(name)
|
||||||
|
if errno != 0 {
|
||||||
|
return errno
|
||||||
|
}
|
||||||
|
return translateError(vfsNode.Remove())
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeUnlinker)((*Node)(nil))
|
||||||
|
|
||||||
|
// Rmdir is like Unlink but for directories.
|
||||||
|
// Default is to return EROFS.
|
||||||
|
func (n *Node) Rmdir(ctx context.Context, name string) (errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "name=%q", name)("errno=%v", &errno)
|
||||||
|
vfsNode, errno := n.lookupVfsNodeInDir(name)
|
||||||
|
if errno != 0 {
|
||||||
|
return errno
|
||||||
|
}
|
||||||
|
return translateError(vfsNode.Remove())
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeRmdirer)((*Node)(nil))
|
||||||
|
|
||||||
|
// Rename should move a child from one directory to a different
|
||||||
|
// one. The change is effected in the FS tree if the return status is
|
||||||
|
// OK. Default is to return EROFS.
|
||||||
|
func (n *Node) Rename(ctx context.Context, oldName string, newParent fusefs.InodeEmbedder, newName string, flags uint32) (errno syscall.Errno) {
|
||||||
|
defer log.Trace(n, "oldName=%q, newParent=%v, newName=%q", oldName, newParent, newName)("errno=%v", &errno)
|
||||||
|
oldDir, ok := n.node.(*vfs.Dir)
|
||||||
|
if !ok {
|
||||||
|
return syscall.ENOTDIR
|
||||||
|
}
|
||||||
|
newParentNode, ok := newParent.(*Node)
|
||||||
|
if !ok {
|
||||||
|
fs.Errorf(n, "newParent was not a *Node")
|
||||||
|
return syscall.EIO
|
||||||
|
}
|
||||||
|
newDir, ok := newParentNode.node.(*vfs.Dir)
|
||||||
|
if !ok {
|
||||||
|
return syscall.ENOTDIR
|
||||||
|
}
|
||||||
|
return translateError(oldDir.Rename(oldName, newName, newDir))
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = (fusefs.NodeRenamer)((*Node)(nil))
|
||||||
+46
-6
@@ -36,6 +36,7 @@ var (
|
|||||||
NoAppleDouble = true // use noappledouble by default
|
NoAppleDouble = true // use noappledouble by default
|
||||||
NoAppleXattr = false // do not use noapplexattr by default
|
NoAppleXattr = false // do not use noapplexattr by default
|
||||||
DaemonTimeout time.Duration // OSXFUSE only
|
DaemonTimeout time.Duration // OSXFUSE only
|
||||||
|
AsyncRead = true // do async reads by default
|
||||||
)
|
)
|
||||||
|
|
||||||
// Global constants
|
// Global constants
|
||||||
@@ -98,10 +99,11 @@ func checkMountpointOverlap(root, mountpoint string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewMountCommand makes a mount command with the given name and Mount function
|
// NewMountCommand makes a mount command with the given name and Mount function
|
||||||
func NewMountCommand(commandName string, Mount func(f fs.Fs, mountpoint string) error) *cobra.Command {
|
func NewMountCommand(commandName string, hidden bool, Mount func(f fs.Fs, mountpoint string) error) *cobra.Command {
|
||||||
var commandDefinition = &cobra.Command{
|
var commandDefinition = &cobra.Command{
|
||||||
Use: commandName + " remote:path /path/to/mountpoint",
|
Use: commandName + " remote:path /path/to/mountpoint",
|
||||||
Short: `Mount the remote as file system on a mountpoint.`,
|
Hidden: hidden,
|
||||||
|
Short: `Mount the remote as file system on a mountpoint.`,
|
||||||
Long: `
|
Long: `
|
||||||
rclone ` + commandName + ` allows Linux, FreeBSD, macOS and Windows to
|
rclone ` + commandName + ` allows Linux, FreeBSD, macOS and Windows to
|
||||||
mount any of Rclone's cloud storage systems as a file system with
|
mount any of Rclone's cloud storage systems as a file system with
|
||||||
@@ -109,6 +111,11 @@ FUSE.
|
|||||||
|
|
||||||
First set up your remote using ` + "`rclone config`" + `. Check it works with ` + "`rclone ls`" + ` etc.
|
First set up your remote using ` + "`rclone config`" + `. Check it works with ` + "`rclone ls`" + ` etc.
|
||||||
|
|
||||||
|
You can either run mount in foreground mode or background(daemon) mode. Mount runs in
|
||||||
|
foreground mode by default, use the --daemon flag to specify background mode mode.
|
||||||
|
Background mode is only supported on Linux and OSX, you can only run mount in
|
||||||
|
foreground mode on Windows.
|
||||||
|
|
||||||
Start the mount like this
|
Start the mount like this
|
||||||
|
|
||||||
rclone ` + commandName + ` remote:path/to/files /path/to/local/mount
|
rclone ` + commandName + ` remote:path/to/files /path/to/local/mount
|
||||||
@@ -117,11 +124,15 @@ Or on Windows like this where X: is an unused drive letter
|
|||||||
|
|
||||||
rclone ` + commandName + ` remote:path/to/files X:
|
rclone ` + commandName + ` remote:path/to/files X:
|
||||||
|
|
||||||
When the program ends, either via Ctrl+C or receiving a SIGINT or SIGTERM signal,
|
When running in background mode the user will have to stop the mount manually (specified below).
|
||||||
the mount is automatically stopped.
|
|
||||||
|
When the program ends while in foreground mode, either via Ctrl+C or receiving
|
||||||
|
a SIGINT or SIGTERM signal, the mount is automatically stopped.
|
||||||
|
|
||||||
The umount operation can fail, for example when the mountpoint is busy.
|
The umount operation can fail, for example when the mountpoint is busy.
|
||||||
When that happens, it is the user's responsibility to stop the mount manually with
|
When that happens, it is the user's responsibility to stop the mount manually.
|
||||||
|
|
||||||
|
Stopping the mount manually:
|
||||||
|
|
||||||
# Linux
|
# Linux
|
||||||
fusermount -u /path/to/local/mount
|
fusermount -u /path/to/local/mount
|
||||||
@@ -157,6 +168,34 @@ infrastructure](https://github.com/billziss-gh/winfsp/wiki/WinFsp-Service-Archit
|
|||||||
which creates drives accessible for everyone on the system or
|
which creates drives accessible for everyone on the system or
|
||||||
alternatively using [the nssm service manager](https://nssm.cc/usage).
|
alternatively using [the nssm service manager](https://nssm.cc/usage).
|
||||||
|
|
||||||
|
#### Mount as a network drive
|
||||||
|
|
||||||
|
By default, rclone will mount the remote as a normal drive. However,
|
||||||
|
you can also mount it as a **Network Drive** (or **Network Share**, as
|
||||||
|
mentioned in some places)
|
||||||
|
|
||||||
|
Unlike other systems, Windows provides a different filesystem type for
|
||||||
|
network drives. Windows and other programs treat the network drives
|
||||||
|
and fixed/removable drives differently: In network drives, many I/O
|
||||||
|
operations are optimized, as the high latency and low reliability
|
||||||
|
(compared to a normal drive) of a network is expected.
|
||||||
|
|
||||||
|
Although many people prefer network shares to be mounted as normal
|
||||||
|
system drives, this might cause some issues, such as programs not
|
||||||
|
working as expected or freezes and errors while operating with the
|
||||||
|
mounted remote in Windows Explorer. If you experience any of those,
|
||||||
|
consider mounting rclone remotes as network shares, as Windows expects
|
||||||
|
normal drives to be fast and reliable, while cloud storage is far from
|
||||||
|
that. See also [Limitations](#limitations) section below for more
|
||||||
|
info
|
||||||
|
|
||||||
|
Add "--fuse-flag --VolumePrefix=\server\share" to your "mount"
|
||||||
|
command, **replacing "share" with any other name of your choice if you
|
||||||
|
are mounting more than one remote**. Otherwise, the mountpoints will
|
||||||
|
conflict and your mounted filesystems will overlap.
|
||||||
|
|
||||||
|
[Read more about drive mapping](https://en.wikipedia.org/wiki/Drive_mapping)
|
||||||
|
|
||||||
### Limitations
|
### Limitations
|
||||||
|
|
||||||
Without the use of "--vfs-cache-mode" this can only write files
|
Without the use of "--vfs-cache-mode" this can only write files
|
||||||
@@ -318,6 +357,7 @@ be copied to the vfs cache before opening with --vfs-cache-mode full.
|
|||||||
flags.BoolVarP(cmdFlags, &Daemon, "daemon", "", Daemon, "Run mount as a daemon (background mode).")
|
flags.BoolVarP(cmdFlags, &Daemon, "daemon", "", Daemon, "Run mount as a daemon (background mode).")
|
||||||
flags.StringVarP(cmdFlags, &VolumeName, "volname", "", VolumeName, "Set the volume name (not supported by all OSes).")
|
flags.StringVarP(cmdFlags, &VolumeName, "volname", "", VolumeName, "Set the volume name (not supported by all OSes).")
|
||||||
flags.DurationVarP(cmdFlags, &DaemonTimeout, "daemon-timeout", "", DaemonTimeout, "Time limit for rclone to respond to kernel (not supported by all OSes).")
|
flags.DurationVarP(cmdFlags, &DaemonTimeout, "daemon-timeout", "", DaemonTimeout, "Time limit for rclone to respond to kernel (not supported by all OSes).")
|
||||||
|
flags.BoolVarP(cmdFlags, &AsyncRead, "async-read", "", AsyncRead, "Use asynchronous reads.")
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
flags.BoolVarP(cmdFlags, &NoAppleDouble, "noappledouble", "", NoAppleDouble, "Sets the OSXFUSE option noappledouble.")
|
flags.BoolVarP(cmdFlags, &NoAppleDouble, "noappledouble", "", NoAppleDouble, "Sets the OSXFUSE option noappledouble.")
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/rclone/rclone/fstest"
|
"github.com/rclone/rclone/fstest"
|
||||||
"github.com/rclone/rclone/lib/file"
|
"github.com/rclone/rclone/lib/file"
|
||||||
"github.com/rclone/rclone/vfs"
|
"github.com/rclone/rclone/vfs"
|
||||||
|
"github.com/rclone/rclone/vfs/vfscommon"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -44,11 +45,11 @@ var (
|
|||||||
func RunTests(t *testing.T, fn MountFn) {
|
func RunTests(t *testing.T, fn MountFn) {
|
||||||
mountFn = fn
|
mountFn = fn
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
cacheModes := []vfs.CacheMode{
|
cacheModes := []vfscommon.CacheMode{
|
||||||
vfs.CacheModeOff,
|
vfscommon.CacheModeOff,
|
||||||
vfs.CacheModeMinimal,
|
vfscommon.CacheModeMinimal,
|
||||||
vfs.CacheModeWrites,
|
vfscommon.CacheModeWrites,
|
||||||
vfs.CacheModeFull,
|
vfscommon.CacheModeFull,
|
||||||
}
|
}
|
||||||
run = newRun()
|
run = newRun()
|
||||||
for _, cacheMode := range cacheModes {
|
for _, cacheMode := range cacheModes {
|
||||||
@@ -207,7 +208,7 @@ func (r *Run) umount() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cacheMode flushes the VFS and changes the CacheMode
|
// cacheMode flushes the VFS and changes the CacheMode
|
||||||
func (r *Run) cacheMode(cacheMode vfs.CacheMode) {
|
func (r *Run) cacheMode(cacheMode vfscommon.CacheMode) {
|
||||||
if r.skip {
|
if r.skip {
|
||||||
log.Printf("FUSE not found so skipping cacheMode")
|
log.Printf("FUSE not found so skipping cacheMode")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/vfs/vfscommon"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/rclone/rclone/vfs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestWriteFileNoWrite tests writing a file with no write()'s to it
|
// TestWriteFileNoWrite tests writing a file with no write()'s to it
|
||||||
@@ -91,7 +90,7 @@ func TestWriteFileFsync(t *testing.T) {
|
|||||||
func TestWriteFileDup(t *testing.T) {
|
func TestWriteFileDup(t *testing.T) {
|
||||||
run.skipIfNoFUSE(t)
|
run.skipIfNoFUSE(t)
|
||||||
|
|
||||||
if run.vfs.Opt.CacheMode < vfs.CacheModeWrites {
|
if run.vfs.Opt.CacheMode < vfscommon.CacheModeWrites {
|
||||||
t.Skip("not supported on vfs-cache-mode < writes")
|
t.Skip("not supported on vfs-cache-mode < writes")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -136,7 +135,7 @@ func TestWriteFileDup(t *testing.T) {
|
|||||||
func TestWriteFileAppend(t *testing.T) {
|
func TestWriteFileAppend(t *testing.T) {
|
||||||
run.skipIfNoFUSE(t)
|
run.skipIfNoFUSE(t)
|
||||||
|
|
||||||
if run.vfs.Opt.CacheMode < vfs.CacheModeWrites {
|
if run.vfs.Opt.CacheMode < vfscommon.CacheModeWrites {
|
||||||
t.Skip("not supported on vfs-cache-mode < writes")
|
t.Skip("not supported on vfs-cache-mode < writes")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/rclone/rclone/vfs/vfscommon"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/rclone/rclone/vfs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestWriteFileDoubleClose tests double close on write
|
// TestWriteFileDoubleClose tests double close on write
|
||||||
@@ -45,7 +44,7 @@ func TestWriteFileDoubleClose(t *testing.T) {
|
|||||||
|
|
||||||
// write to the other dup
|
// write to the other dup
|
||||||
_, err = unix.Write(fd2, buf)
|
_, err = unix.Write(fd2, buf)
|
||||||
if run.vfs.Opt.CacheMode < vfs.CacheModeWrites {
|
if run.vfs.Opt.CacheMode < vfscommon.CacheModeWrites {
|
||||||
// produces an error if cache mode < writes
|
// produces an error if cache mode < writes
|
||||||
assert.Error(t, err, "input/output error")
|
assert.Error(t, err, "input/output error")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loaded 100 of 848 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user