Don't try to do put or delete requests to root dir in order to update etag
This commit is contained in:
parent
902917d3ad
commit
c730333143
@ -411,10 +411,16 @@ module RemoteStorage
|
|||||||
timestamp = (Time.now.to_f * 1000).to_i
|
timestamp = (Time.now.to_f * 1000).to_i
|
||||||
|
|
||||||
parent_directories_for(directory).each do |dir|
|
parent_directories_for(directory).each do |dir|
|
||||||
# TODO check if we can actually do a put request to the root dir
|
unless dir == ""
|
||||||
res = do_put_request("#{url_for_directory(user, dir)}/", timestamp.to_s, "text/plain")
|
res = do_put_request("#{url_for_directory(user, dir)}/", timestamp.to_s, "text/plain")
|
||||||
|
etag = res.headers[:etag]
|
||||||
|
else
|
||||||
|
get_response = do_get_request("#{container_url_for(user)}/?format=json&path=")
|
||||||
|
etag = etag_for(get_response.body)
|
||||||
|
end
|
||||||
|
|
||||||
key = "rs_meta:#{user}:#{dir}/"
|
key = "rs_meta:#{user}:#{dir}/"
|
||||||
metadata = {etag: res.headers[:etag], modified: timestamp}
|
metadata = {etag: etag, modified: timestamp}
|
||||||
redis.hmset(key, *metadata)
|
redis.hmset(key, *metadata)
|
||||||
redis.sadd "rs_meta:#{user}:#{parent_directory_for(dir)}:items", "#{top_directory(dir)}/"
|
redis.sadd "rs_meta:#{user}:#{parent_directory_for(dir)}:items", "#{top_directory(dir)}/"
|
||||||
end
|
end
|
||||||
@ -422,9 +428,10 @@ module RemoteStorage
|
|||||||
true
|
true
|
||||||
rescue
|
rescue
|
||||||
parent_directories_for(directory).each do |dir|
|
parent_directories_for(directory).each do |dir|
|
||||||
# TODO check if we can actually do a delete request to the root dir
|
unless dir == ""
|
||||||
do_delete_request("#{url_for_directory(user, dir)}/") rescue false
|
do_delete_request("#{url_for_directory(user, dir)}/") rescue false
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
@ -438,15 +445,21 @@ module RemoteStorage
|
|||||||
def delete_dir_objects(user, directory)
|
def delete_dir_objects(user, directory)
|
||||||
parent_directories_for(directory).each do |dir|
|
parent_directories_for(directory).each do |dir|
|
||||||
if dir_empty?(user, dir)
|
if dir_empty?(user, dir)
|
||||||
# TODO check if we can actually do a delete request to the root dir
|
unless dir == ""
|
||||||
do_delete_request("#{url_for_directory(user, dir)}/")
|
do_delete_request("#{url_for_directory(user, dir)}/")
|
||||||
|
end
|
||||||
redis.del "rs_meta:#{user}:#{directory}/"
|
redis.del "rs_meta:#{user}:#{directory}/"
|
||||||
redis.srem "rs_meta:#{user}:#{parent_directory_for(dir)}:items", "#{dir}/"
|
redis.srem "rs_meta:#{user}:#{parent_directory_for(dir)}:items", "#{dir}/"
|
||||||
else
|
else
|
||||||
timestamp = (Time.now.to_f * 1000).to_i
|
timestamp = (Time.now.to_f * 1000).to_i
|
||||||
# TODO check if we can actually do a put request to the root dir
|
unless dir == ""
|
||||||
res = do_put_request("#{url_for_directory(user, dir)}/", timestamp.to_s, "text/plain")
|
res = do_put_request("#{url_for_directory(user, dir)}/", timestamp.to_s, "text/plain")
|
||||||
metadata = {etag: res.headers[:etag], modified: timestamp}
|
etag = res.headers[:etag]
|
||||||
|
else
|
||||||
|
get_response = do_get_request("#{container_url_for(user)}/?format=json&path=")
|
||||||
|
etag = etag_for(get_response.body)
|
||||||
|
end
|
||||||
|
metadata = {etag: etag, modified: timestamp}
|
||||||
redis.hmset("rs_meta:#{user}:#{dir}/", *metadata)
|
redis.hmset("rs_meta:#{user}:#{dir}/", *metadata)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -40,13 +40,18 @@ describe "App" do
|
|||||||
|
|
||||||
it "creates the directory objects metadata in redis" do
|
it "creates the directory objects metadata in redis" do
|
||||||
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
||||||
|
get_stub = OpenStruct.new(body: "rootbody")
|
||||||
RestClient.stub :put, put_stub do
|
RestClient.stub :put, put_stub do
|
||||||
|
RestClient.stub :get, get_stub do
|
||||||
|
RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do
|
||||||
put "/phil/food/aguacate", "si"
|
put "/phil/food/aguacate", "si"
|
||||||
put "/phil/food/camaron", "yummi"
|
put "/phil/food/camaron", "yummi"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
metadata = redis.hgetall "rs_meta:phil:/"
|
metadata = redis.hgetall "rs_meta:phil:/"
|
||||||
metadata["etag"].must_equal "bla"
|
metadata["etag"].must_equal "rootetag"
|
||||||
metadata["modified"].length.must_equal 13
|
metadata["modified"].length.must_equal 13
|
||||||
|
|
||||||
metadata = redis.hgetall "rs_meta:phil:food/"
|
metadata = redis.hgetall "rs_meta:phil:food/"
|
||||||
@ -65,9 +70,14 @@ describe "App" do
|
|||||||
describe "name collision checks" do
|
describe "name collision checks" do
|
||||||
it "is successful when there is no name collision" do
|
it "is successful when there is no name collision" do
|
||||||
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
||||||
|
get_stub = OpenStruct.new(body: "rootbody")
|
||||||
RestClient.stub :put, put_stub do
|
RestClient.stub :put, put_stub do
|
||||||
|
RestClient.stub :get, get_stub do
|
||||||
|
RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do
|
||||||
put "/phil/food/aguacate", "si"
|
put "/phil/food/aguacate", "si"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
last_response.status.must_equal 200
|
last_response.status.must_equal 200
|
||||||
|
|
||||||
@ -157,11 +167,16 @@ describe "App" do
|
|||||||
|
|
||||||
it "deletes the metadata object in redis" do
|
it "deletes the metadata object in redis" do
|
||||||
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
||||||
|
get_stub = OpenStruct.new(body: "rootbody")
|
||||||
RestClient.stub :put, put_stub do
|
RestClient.stub :put, put_stub do
|
||||||
RestClient.stub :delete, "" do
|
RestClient.stub :delete, "" do
|
||||||
|
RestClient.stub :get, get_stub do
|
||||||
|
RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do
|
||||||
delete "/phil/food/aguacate"
|
delete "/phil/food/aguacate"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
metadata = redis.hgetall "rs_meta:phil:food/aguacate"
|
metadata = redis.hgetall "rs_meta:phil:food/aguacate"
|
||||||
metadata.must_be_empty
|
metadata.must_be_empty
|
||||||
@ -171,11 +186,16 @@ describe "App" do
|
|||||||
old_metadata = redis.hgetall "rs_meta:phil:food/"
|
old_metadata = redis.hgetall "rs_meta:phil:food/"
|
||||||
|
|
||||||
put_stub = OpenStruct.new(headers: {etag: "newetag"})
|
put_stub = OpenStruct.new(headers: {etag: "newetag"})
|
||||||
|
get_stub = OpenStruct.new(body: "rootbody")
|
||||||
RestClient.stub :put, put_stub do
|
RestClient.stub :put, put_stub do
|
||||||
RestClient.stub :delete, "" do
|
RestClient.stub :delete, "" do
|
||||||
|
RestClient.stub :get, get_stub do
|
||||||
|
RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do
|
||||||
delete "/phil/food/aguacate"
|
delete "/phil/food/aguacate"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
metadata = redis.hgetall "rs_meta:phil:food/"
|
metadata = redis.hgetall "rs_meta:phil:food/"
|
||||||
metadata["etag"].must_equal "newetag"
|
metadata["etag"].must_equal "newetag"
|
||||||
@ -191,12 +211,17 @@ describe "App" do
|
|||||||
|
|
||||||
it "deletes the parent directory objects metadata when deleting all items" do
|
it "deletes the parent directory objects metadata when deleting all items" do
|
||||||
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
put_stub = OpenStruct.new(headers: {etag: "bla"})
|
||||||
|
get_stub = OpenStruct.new(body: "rootbody")
|
||||||
RestClient.stub :put, put_stub do
|
RestClient.stub :put, put_stub do
|
||||||
RestClient.stub :delete, "" do
|
RestClient.stub :delete, "" do
|
||||||
|
RestClient.stub :get, get_stub do
|
||||||
|
RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do
|
||||||
delete "/phil/food/aguacate"
|
delete "/phil/food/aguacate"
|
||||||
delete "/phil/food/camaron"
|
delete "/phil/food/camaron"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
metadata = redis.hgetall "rs_meta:phil:food/"
|
metadata = redis.hgetall "rs_meta:phil:food/"
|
||||||
metadata.must_be_empty
|
metadata.must_be_empty
|
||||||
|
Loading…
x
Reference in New Issue
Block a user