ncw / swift

Go language interface to Swift / Openstack Object Storage / Rackspace cloud files (golang)
MIT License
310 stars 107 forks source link

Trim double quotes from received ETag when checking hashes #175

Closed timss closed 2 years ago

timss commented 2 years ago

This issue was originally discussing over at the rclone forums: https://forum.rclone.org/t/intended-behavior-of-sync-and-checksum-for-swift/26743


For Swift servers/accounts/containers that are configured to use RFC-compliant ETags enclosed in double quotes[1][2], rclone was mistakenly considering objects corrupted when comparing "<hash>" vs <hash>.

This could happen for operations such as sync (both ways), typically during transfer (ETag in response to PUT request`), or possibly triggering retransfers when object already present at destination (comparing object checksum in JSON formatted container listing vs. header ETag).

$ rclone sync --config rclone.conf src:container dest:container\
  --progress --checksum -vv --dump requests,responses
[...]
2021-09-30 11:38:18 DEBUG : myfile.gz: md5 = <hash> (Swift container mycontainer>
2021-09-30 11:38:18 DEBUG : myfile.gz: md5 = "<hash>" (Swift container mycontainer>
2021-09-30 11:38:18 DEBUG : md5 differ

I have tested my patch on Swift v2.25.1 together with rclone v1.56.2 on Go 1.17.1. This is my first time playing around with Go so if there's anything that needs to be addressed please let me know :-)

[1] https://github.com/openstack/swift/blob/2.24.0/CHANGELOG#L9 [2] https://datatracker.ietf.org/doc/html/rfc7232#section-2.3