Create directory objects for parent directories that don't contain any files themselves
This commit is contained in:
parent
4d01144bf4
commit
9250bb7790
@ -72,11 +72,24 @@ module RemoteStorage
|
|||||||
:directory_bin => [category]})
|
:directory_bin => [category]})
|
||||||
object.store
|
object.store
|
||||||
|
|
||||||
|
create_parent_directory_objects(user, category)
|
||||||
update_directory_object(user, category)
|
update_directory_object(user, category)
|
||||||
rescue ::Riak::HTTPFailedRequest
|
rescue ::Riak::HTTPFailedRequest
|
||||||
halt 422
|
halt 422
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_parent_directory_objects(user, category)
|
||||||
|
parent_directories = category.split("/")
|
||||||
|
parent_directories.pop
|
||||||
|
while parent_directories.any?
|
||||||
|
directory = parent_directories.join("/")
|
||||||
|
unless directory_bucket.exist?("#{user}:#{directory}")
|
||||||
|
update_directory_object(user, directory)
|
||||||
|
end
|
||||||
|
parent_directories.pop
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_directory_object(user, category)
|
def update_directory_object(user, category)
|
||||||
if category.match /\//
|
if category.match /\//
|
||||||
parent_directory = category[0..category.rindex("/")-1]
|
parent_directory = category[0..category.rindex("/")-1]
|
||||||
|
|||||||
@ -65,6 +65,29 @@ describe "Directories" do
|
|||||||
content["home/"].to_s.must_match /\d+/
|
content["home/"].to_s.must_match /\d+/
|
||||||
content["home/"].to_s.length.must_be :>=, 10
|
content["home/"].to_s.length.must_be :>=, 10
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "sub-directories without objects" do
|
||||||
|
it "lists the direct sub-directories" do
|
||||||
|
put "/jimmy/tasks/private/projects/world-domination/start", "write a manifesto"
|
||||||
|
get "/jimmy/tasks/private/"
|
||||||
|
|
||||||
|
last_response.status.must_equal 200
|
||||||
|
|
||||||
|
content = JSON.parse(last_response.body)
|
||||||
|
content.must_include "projects/"
|
||||||
|
content["projects/"].to_s.must_match /\d+/
|
||||||
|
content["projects/"].to_s.length.must_be :>=, 10
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not update existing directory objects" do
|
||||||
|
tasks_timestamp = directory_bucket.get("jimmy:tasks").last_modified
|
||||||
|
wait_a_second
|
||||||
|
put "/jimmy/tasks/private/projects/world-domination/start", "write a manifesto"
|
||||||
|
|
||||||
|
tasks_object = directory_bucket.get("jimmy:tasks")
|
||||||
|
tasks_object.last_modified.must_equal tasks_timestamp
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "for a sub-directory" do
|
context "for a sub-directory" do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user