diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 4148e8e..9b2cd4d 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -75,8 +75,7 @@ module RemoteStorage object.reload timestamp = object.last_modified.to_i - create_missing_directory_objects(user, directory, timestamp) - update_directory_object(user, directory, timestamp) + update_all_directory_objects(user, directory, timestamp) rescue ::Riak::HTTPFailedRequest halt 422 end @@ -172,20 +171,16 @@ module RemoteStorage run end - def create_missing_directory_objects(user, directory, timestamp) + def update_all_directory_objects(user, directory, timestamp) parent_directories = directory.split("/") - parent_directories.pop + while parent_directories.any? parent_directory = parent_directories.join("/") - unless directory_bucket.exist?("#{user}:#{parent_directory}") - update_directory_object(user, parent_directory, timestamp) - end + update_directory_object(user, parent_directory, timestamp) parent_directories.pop end - unless directory_bucket.exist?("#{user}:") - update_directory_object(user, "", timestamp) - end + update_directory_object(user, "", timestamp) end def update_directory_object(user, directory, timestamp) diff --git a/spec/directories_spec.rb b/spec/directories_spec.rb index 71f9259..0e93cfd 100644 --- a/spec/directories_spec.rb +++ b/spec/directories_spec.rb @@ -79,15 +79,18 @@ describe "Directories" do content["projects/"].to_s.length.must_be :>=, 10 end - it "does not update existing directory objects" do - old_timestamp = (Time.now.to_i - 2).to_s - tasks_object = directory_bucket.get("jimmy:tasks") - tasks_object.data = old_timestamp - tasks_object.store + it "updates the timestamps of the existing directory objects" do + directory = directory_bucket.new("jimmy:tasks") + directory.content_type = "text/plain" + directory.data = 2.seconds.ago.to_i.to_s + directory.store put "/jimmy/tasks/private/projects/world-domination/start", "write a manifesto" - tasks_object.reload.data.must_equal old_timestamp + object = data_bucket.get("jimmy:tasks/private/projects/world-domination:start") + directory.reload + + directory.data.to_i.must_equal object.last_modified.to_i end end end