diff --git a/config.yml.example b/config.yml.example index 5f65092..f0ed36d 100644 --- a/config.yml.example +++ b/config.yml.example @@ -20,7 +20,6 @@ development: &defaults # redis: # host: localhost # port: 6379 - # use_redis_dir_listing: true test: <<: *defaults diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb index 6074492..535947e 100644 --- a/lib/remote_storage/swift.rb +++ b/lib/remote_storage/swift.rb @@ -75,7 +75,7 @@ module RemoteStorage end def get_directory_listing(user, directory) - if settings.use_redis_dir_listing + if directory_backend(user).match /new/ get_directory_listing_from_redis(user, directory) else get_directory_listing_from_swift(user, directory) @@ -289,7 +289,7 @@ module RemoteStorage end def has_name_collision?(user, directory, key) - if settings.use_redis_dir_listing + if directory_backend(user).match /new/ has_name_collision_via_redis?(user, directory, key) else has_name_collision_via_swift?(user, directory, key) @@ -518,6 +518,10 @@ module RemoteStorage @redis ||= Redis.new(host: settings.redis["host"], port: settings.redis["port"]) end + def directory_backend(user) + @directory_backend ||= redis.get("rs_config:dir_backend:#{user}") || "legacy" + end + def etag_for(body) objects = JSON.parse(body) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c92c47f..8cec109 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,7 +38,7 @@ def redis end def purge_redis - redis.keys("*").each do |key| + redis.keys("rs_*").each do |key| redis.del key end end diff --git a/spec/swift/app_spec.rb b/spec/swift/app_spec.rb index 6b2a876..b4b9d38 100644 --- a/spec/swift/app_spec.rb +++ b/spec/swift/app_spec.rb @@ -16,6 +16,7 @@ describe "App" do before do purge_redis + redis.set "rs_config:dir_backend:phil", "new" end context "authorized" do @@ -107,6 +108,7 @@ describe "App" do before do purge_redis + redis.set "rs_config:dir_backend:phil", "new" end context "authorized" do @@ -191,9 +193,11 @@ describe "App" do before do purge_redis + redis.set "rs_config:dir_backend:phil", "new" end context "authorized" do + before do redis.sadd "authorizations:phil:amarillo", [":rw"] header "Authorization", "Bearer amarillo" @@ -255,6 +259,33 @@ describe "App" do end end + + context "with legacy directory backend" do + + before do + redis.sadd "authorizations:phil:amarillo", [":rw"] + header "Authorization", "Bearer amarillo" + + put_stub = OpenStruct.new(headers: {etag: "bla"}) + RestClient.stub :put, put_stub do + put "/phil/food/aguacate", "si" + put "/phil/food/camaron", "yummi" + end + + redis.set "rs_config:dir_backend:phil", "legacy" + end + + it "serves directory listing from Swift backend" do + RemoteStorage::Swift.stub_any_instance :get_directory_listing_from_swift, "directory listing" do + get "/phil/food/" + end + + last_response.status.must_equal 200 + last_response.body.must_equal "directory listing" + end + + end + end end