Also use content checksum for ETag calculation

Timestamp is not enough, as it might be the same
for two consequent PUTs.
This commit is contained in:
Garret Alfert
2016-03-04 21:49:04 +01:00
parent 8bcb8bf337
commit 5378826c6a
2 changed files with 11 additions and 7 deletions

View File

@@ -156,7 +156,7 @@ module RemoteStorage
if update_metadata_object(user, directory, key, metadata)
if metadata_changed?(existing_metadata, metadata)
update_dir_objects(user, directory, timestamp)
update_dir_objects(user, directory, timestamp, checksum_for(data))
end
server.headers["ETag"] = %Q("#{res.headers[:etag]}")
@@ -166,6 +166,10 @@ module RemoteStorage
end
end
def checksum_for(data)
Digest::MD5.hexdigest(data)
end
def delete_data(user, directory, key)
url = url_for_key(user, directory, key)
@@ -316,9 +320,9 @@ module RemoteStorage
true
end
def update_dir_objects(user, directory, timestamp)
def update_dir_objects(user, directory, timestamp, checksum)
parent_directories_for(directory).each do |dir|
etag = etag_for(dir, timestamp)
etag = etag_for(dir, timestamp, checksum)
key = "rs:m:#{user}:#{dir}/"
metadata = {e: etag, m: timestamp}