From 1d39445ba9713a81032796fbac7db121b95e6cc0 Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Fri, 4 Mar 2016 22:16:35 +0100 Subject: [PATCH] Fix deleting metadata for empty subdirectories --- lib/remote_storage/swift.rb | 4 +-- spec/swift/app_spec.rb | 65 ++++++++++--------------------------- 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb index 1cf8760..66f269a 100644 --- a/lib/remote_storage/swift.rb +++ b/lib/remote_storage/swift.rb @@ -341,8 +341,8 @@ module RemoteStorage parent_directories_for(directory).each do |dir| if dir_empty?(user, dir) - redis.del "rs:m:#{user}:#{directory}/" - redis.srem "rs:m:#{user}:#{parent_directory_for(dir)}:items", "#{dir}/" + redis.del "rs:m:#{user}:#{dir}/" + redis.srem "rs:m:#{user}:#{parent_directory_for(dir)}:items", "#{top_directory(dir)}/" else etag = etag_for(dir, timestamp) diff --git a/spec/swift/app_spec.rb b/spec/swift/app_spec.rb index 3df89e0..af0968f 100644 --- a/spec/swift/app_spec.rb +++ b/spec/swift/app_spec.rb @@ -186,23 +186,14 @@ describe "App" do RestClient.stub :put, put_stub do put "/phil/food/aguacate", "si" put "/phil/food/camaron", "yummi" + put "/phil/food/desunyos/bolon", "wow" end end it "deletes the metadata object in redis" do - put_stub = OpenStruct.new(headers: { - etag: "bla", - last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" - }) - get_stub = OpenStruct.new(body: "rootbody") - - RestClient.stub :put, put_stub do - RestClient.stub :delete, "" do - RestClient.stub :get, get_stub do - RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do - delete "/phil/food/aguacate" - end - end + RestClient.stub :delete, "" do + RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do + delete "/phil/food/aguacate" end end @@ -213,19 +204,9 @@ describe "App" do it "deletes the directory objects metadata in redis" do old_metadata = redis.hgetall "rs:m:phil:food/" - put_stub = OpenStruct.new(headers: { - etag: "bla", - last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" - }) - get_stub = OpenStruct.new(body: "rootbody") - - RestClient.stub :put, put_stub do - RestClient.stub :delete, "" do - RestClient.stub :get, get_stub do - RemoteStorage::Swift.stub_any_instance :etag_for, "newetag" do - delete "/phil/food/aguacate" - end - end + RestClient.stub :delete, "" do + RemoteStorage::Swift.stub_any_instance :etag_for, "newetag" do + delete "/phil/food/aguacate" end end @@ -235,38 +216,28 @@ describe "App" do metadata["m"].wont_equal old_metadata["m"] food_items = redis.smembers "rs:m:phil:food/:items" - food_items.must_equal ["camaron"] + food_items.must_equal ["desunyos/", "camaron"] root_items = redis.smembers "rs:m:phil:/:items" root_items.must_equal ["food/"] end it "deletes the parent directory objects metadata when deleting all items" do - put_stub = OpenStruct.new(headers: { - etag: "bla", - last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" - }) - get_stub = OpenStruct.new(body: "rootbody") - - RestClient.stub :put, put_stub 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/camaron" - end - end + RestClient.stub :delete, "" do + RemoteStorage::Swift.stub_any_instance :etag_for, "rootetag" do + delete "/phil/food/aguacate" + delete "/phil/food/camaron" + delete "/phil/food/desunyos/bolon" end end - metadata = redis.hgetall "rs:m:phil:food/" - metadata.must_be_empty + redis.smembers("rs:m:phil:food/desunyos:items").must_be_empty + redis.hgetall("rs:m:phil:food/desunyos/").must_be_empty - food_items = redis.smembers "rs:m:phil:food/:items" - food_items.must_be_empty + redis.smembers("rs:m:phil:food/:items").must_be_empty + redis.hgetall("rs:m:phil:food/").must_be_empty - root_items = redis.smembers "rs:m:phil:/:items" - root_items.must_be_empty + redis.smembers("rs:m:phil:/:items").must_be_empty end end end