From 9dda344b26a64cf2d442854819451cc47b48b34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 30 Jun 2015 15:28:07 +0200 Subject: [PATCH] Fix root directory listing It was flattened by accident Refs #62 --- lib/remote_storage/swift.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb index 63366e0..8a9920f 100644 --- a/lib/remote_storage/swift.rb +++ b/lib/remote_storage/swift.rb @@ -78,10 +78,16 @@ module RemoteStorage end end - res = do_get_request("#{container_url_for(user)}/?format=json&path=#{escape(directory)}/") + is_root_listing = directory.empty? + + res = if is_root_listing + do_get_request("#{container_url_for(user)}/?format=json") + else + do_get_request("#{container_url_for(user)}/?format=json&path=#{escape(directory)}/") + end if body = JSON.parse(res.body) - listing = directory_listing(body) + listing = directory_listing(body, is_root_listing) else puts "listing not JSON" end @@ -169,14 +175,15 @@ module RemoteStorage permission end - def directory_listing(res_body) + def directory_listing(res_body, is_root_listing = false) listing = { "@context" => "http://remotestorage.io/spec/folder-description", "items" => {} } res_body.each do |entry| - name = entry["name"].gsub("#{File.dirname(entry["name"])}/", '') + name = entry["name"] + name.sub!("#{File.dirname(entry["name"])}/", '') unless is_root_listing if name[-1] == "/" listing["items"].merge!({ name => {