diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb index b815ca3..4a64d13 100644 --- a/lib/remote_storage/swift.rb +++ b/lib/remote_storage/swift.rb @@ -453,8 +453,12 @@ module RemoteStorage end def dir_empty?(user, dir) - do_get_request("#{container_url_for(user)}/?format=plain&limit=1&path=#{escape(dir)}/") do |res| - return res.headers[:content_length] == "0" + if directory_backend(user).match /new/ + redis.smembers("rs_meta:#{user}:#{dir}/:items").empty? + else + do_get_request("#{container_url_for(user)}/?format=plain&limit=1&path=#{escape(dir)}/") do |res| + return res.headers[:content_length] == "0" + end end end diff --git a/spec/swift/app_spec.rb b/spec/swift/app_spec.rb index ac0b41a..dc51ee4 100644 --- a/spec/swift/app_spec.rb +++ b/spec/swift/app_spec.rb @@ -157,11 +157,9 @@ describe "App" do it "deletes the metadata object in redis" do put_stub = OpenStruct.new(headers: {etag: "bla"}) - RemoteStorage::Swift.stub_any_instance :dir_empty?, false do - RestClient.stub :put, put_stub do - RestClient.stub :delete, "" do - delete "/phil/food/aguacate" - end + RestClient.stub :put, put_stub do + RestClient.stub :delete, "" do + delete "/phil/food/aguacate" end end @@ -173,11 +171,9 @@ describe "App" do old_metadata = redis.hgetall "rs_meta:phil:food/" put_stub = OpenStruct.new(headers: {etag: "newetag"}) - RemoteStorage::Swift.stub_any_instance :dir_empty?, false do - RestClient.stub :put, put_stub do - RestClient.stub :delete, "" do - delete "/phil/food/aguacate" - end + RestClient.stub :put, put_stub do + RestClient.stub :delete, "" do + delete "/phil/food/aguacate" end end @@ -195,16 +191,9 @@ describe "App" do it "deletes the parent directory objects metadata when deleting all items" do put_stub = OpenStruct.new(headers: {etag: "bla"}) - RemoteStorage::Swift.stub_any_instance :dir_empty?, false do - RestClient.stub :put, put_stub do - RestClient.stub :delete, "" do - delete "/phil/food/aguacate" - end - end - end - - RemoteStorage::Swift.stub_any_instance :dir_empty?, true do + RestClient.stub :put, put_stub do RestClient.stub :delete, "" do + delete "/phil/food/aguacate" delete "/phil/food/camaron" end end