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]})
|
||||
object.store
|
||||
|
||||
create_parent_directory_objects(user, category)
|
||||
update_directory_object(user, category)
|
||||
rescue ::Riak::HTTPFailedRequest
|
||||
halt 422
|
||||
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)
|
||||
if category.match /\//
|
||||
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.length.must_be :>=, 10
|
||||
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
|
||||
|
||||
context "for a sub-directory" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user