s3: server-side copy fails on DigitalOcean Spaces when the key contains a comma (`,` not escaped in X-Amz-Copy-Source)
What is the problem you are having with rclone?
Any server-side copy on DigitalOcean Spaces fails when the source key contains a comma. That includes copyto/moveto, a rename on a mount, and setting a modtime (which uses CopyObject). Spaces rejects the request:
operation error S3: CopyObject, https response error StatusCode: 400, ..., api error InvalidArgument:
Copy Source must mention the source bucket and key: sourcebucket/sourcekey.
On a VFS mount this is worse than a failed copy. Renaming a folder that contains comma-named files moves some of the files and then fails (Finder reports error -36), so the folder ends up split between the old and new names.
The cause is pathEscape in backend/s3/s3.go, which builds CopySource:
// pathEscape escapes s as for a URL path. It uses rest.URLPathEscape
// but also escapes '+' for S3 and Digital Ocean spaces compatibility
func pathEscape(s string) string {
return strings.ReplaceAll(rest.URLPathEscape(s), "+", "%2B")
}
rest.URLPathEscape leaves , unescaped, which is valid in a URL path (RFC 3986 sub-delim). Spaces doesn't accept a raw , in X-Amz-Copy-Source, but it does accept %2C. botocore (AWS CLI / boto3) percent-encodes everything in the copy source except / and ~, so it sends %2C and works.
I tested every other special character I could think of. Only the comma fails on Spaces. These all work with stock v1.75.2: & ( ) ' : = @ ! $ ; * +, a space, and non-ASCII (é).
Suggested fix: escape , the same way + already is:
func pathEscape(s string) string {
s = rest.URLPathEscape(s)
s = strings.ReplaceAll(s, "+", "%2B")
return strings.ReplaceAll(s, ",", "%2C")
}
A broader option is return rest.URLPathEscapeAll(s), which escapes everything except [A-Za-z0-9-._~/], like botocore. We've just switched our production Spaces mounts to a build with that version. It passes the same tests: all the characters above, mount renames of folders with 248 files, and modtime updates. Either is fine by me. The one-character version is the smallest change. pathEscape is only used for CopySource in (*Fs).copy, which also covers multipart copies.
I haven't tested AWS S3 itself, but since botocore always sends %2C there, the escaped form should be safe on AWS.
Happy to send a PR with whichever version you prefer.
What is your rclone version (output from rclone version)
rclone v1.75.2
- os/version: ubuntu 24.04 (64 bit)
- os/kernel: 6.8.0-149-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.26.9
- go/linking: static
- go/tags: none
pathEscape on current master (and v1.76.0) is unchanged.
Which OS you are using and how many bits (e.g. Windows 7, 64 bit)
Ubuntu 24.04, 64 bit
Which cloud storage system are you using? (e.g. Google Drive)
S3, provider = DigitalOcean (Spaces, lon1)
The command you were trying to run (e.g. rclone copy /tmp remote:tmp)
echo x > x.txt
rclone copyto x.txt "spaces:bucket/test/a,b.txt"
rclone copyto "spaces:bucket/test/a,b.txt" "spaces:bucket/test/copy.txt" -vv --retries 1
The upload works; the server-side copy fails. The same copy with a key like a;b.txt or a&b.txt works.
A log from the command with the -vv flag
DEBUG : rclone: Version "v1.75.2" starting with parameters ["/usr/local/bin/rclone" "copyto" "--config" "/path/to/rclone.conf" "spaces:bucket/test/a,b.txt" "spaces:bucket/test/copy.txt" "-vv" "--retries" "1"]
DEBUG : Creating backend with remote "spaces:bucket/test/a,b.txt"
DEBUG : Using config file from "/path/to/rclone.conf"
DEBUG : fs cache: renaming child cache item "spaces:bucket/test/a,b.txt" to be canonical for parent "spaces:bucket/test"
DEBUG : Creating backend with remote "spaces:bucket/test/"
DEBUG : fs cache: renaming cache item "spaces:bucket/test/" to be canonical "spaces:bucket/test"
DEBUG : a,b.txt: Need to transfer - File not found at Destination
ERROR : a,b.txt: Failed to copy: operation error S3: CopyObject, https response error StatusCode: 400, RequestID: <redacted>, HostID: , api error InvalidArgument: Copy Source must mention the source bucket and key: sourcebucket/sourcekey.
ERROR : Attempt 1/1 failed with 1 errors and: operation error S3: CopyObject, https response error StatusCode: 400, RequestID: <redacted>, HostID: , api error InvalidArgument: Copy Source must mention the source bucket and key: sourcebucket/sourcekey.
INFO :
Transferred: 0 B / 0 B, -, 0 B/s, ETA -
Errors: 1 (retrying may help)
Elapsed time: 0.0s
DEBUG : 4 go routines active
NOTICE: Failed to copyto: operation error S3: CopyObject, https response error StatusCode: 400, RequestID: <redacted>, HostID: , api error InvalidArgument: Copy Source must mention the source bucket and key: sourcebucket/sourcekey.
@markgerrard - can you check that @gomitrah fix for this in #10376 works ok?