diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 5b1e450..edaa5aa 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -83,7 +83,8 @@ module RemoteStorage def delete_data(user, directory, key) riak_response = data_bucket.delete("#{user}:#{directory}:#{key}") - delete_empty_directory_objects(user, directory) + timestamp = Time.now.to_i + delete_or_update_directory_objects(user, directory, timestamp) halt riak_response[:code] rescue ::Riak::HTTPFailedRequest @@ -200,7 +201,7 @@ module RemoteStorage directory_object.store end - def delete_empty_directory_objects(user, directory) + def delete_or_update_directory_objects(user, directory, timestamp) parent_directories = directory.split("/") while parent_directories.any? @@ -211,6 +212,8 @@ module RemoteStorage if existing_files.empty? && existing_subdirectories.empty? directory_bucket.delete "#{user}:#{parent_directory}" + else + update_directory_object(user, parent_directory, timestamp) end parent_directories.pop @@ -218,6 +221,8 @@ module RemoteStorage if directory_entries(user, "").empty? && sub_directories(user, "").empty? directory_bucket.delete "#{user}:" + else + update_directory_object(user, "", timestamp) end end diff --git a/spec/directories_spec.rb b/spec/directories_spec.rb index 4254604..c908f12 100644 --- a/spec/directories_spec.rb +++ b/spec/directories_spec.rb @@ -276,6 +276,26 @@ describe "Directories" do directory_bucket.get("jimmy:tasks").wont_be_nil directory_bucket.get("jimmy:").wont_be_nil end + + describe "timestamps" do + before do + @old_timestamp = 2.seconds.ago.to_i + + ["tasks/home", "tasks", ""].each do |dir| + directory = directory_bucket.get("jimmy:#{dir}") + directory.data = @old_timestamp.to_s + directory.store + end + end + + it "updates the timestamp for the parent directories" do + delete "/jimmy/tasks/home/trash" + + directory_bucket.get("jimmy:tasks/home").data.to_i.must_be :>, @old_timestamp + directory_bucket.get("jimmy:tasks").data.to_i.must_be :>, @old_timestamp + directory_bucket.get("jimmy:").data.to_i.must_be :>, @old_timestamp + end + end end end