Update timestamps for all parent directories on PUT requests (fixes #11)
This commit is contained in:
parent
84b9e0561a
commit
6f975c6c45
@ -75,8 +75,7 @@ module RemoteStorage
|
|||||||
|
|
||||||
object.reload
|
object.reload
|
||||||
timestamp = object.last_modified.to_i
|
timestamp = object.last_modified.to_i
|
||||||
create_missing_directory_objects(user, directory, timestamp)
|
update_all_directory_objects(user, directory, timestamp)
|
||||||
update_directory_object(user, directory, timestamp)
|
|
||||||
rescue ::Riak::HTTPFailedRequest
|
rescue ::Riak::HTTPFailedRequest
|
||||||
halt 422
|
halt 422
|
||||||
end
|
end
|
||||||
@ -172,20 +171,16 @@ module RemoteStorage
|
|||||||
run
|
run
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_missing_directory_objects(user, directory, timestamp)
|
def update_all_directory_objects(user, directory, timestamp)
|
||||||
parent_directories = directory.split("/")
|
parent_directories = directory.split("/")
|
||||||
parent_directories.pop
|
|
||||||
while parent_directories.any?
|
while parent_directories.any?
|
||||||
parent_directory = parent_directories.join("/")
|
parent_directory = parent_directories.join("/")
|
||||||
unless directory_bucket.exist?("#{user}:#{parent_directory}")
|
update_directory_object(user, parent_directory, timestamp)
|
||||||
update_directory_object(user, parent_directory, timestamp)
|
|
||||||
end
|
|
||||||
parent_directories.pop
|
parent_directories.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
unless directory_bucket.exist?("#{user}:")
|
update_directory_object(user, "", timestamp)
|
||||||
update_directory_object(user, "", timestamp)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_directory_object(user, directory, timestamp)
|
def update_directory_object(user, directory, timestamp)
|
||||||
|
|||||||
@ -79,15 +79,18 @@ describe "Directories" do
|
|||||||
content["projects/"].to_s.length.must_be :>=, 10
|
content["projects/"].to_s.length.must_be :>=, 10
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not update existing directory objects" do
|
it "updates the timestamps of the existing directory objects" do
|
||||||
old_timestamp = (Time.now.to_i - 2).to_s
|
directory = directory_bucket.new("jimmy:tasks")
|
||||||
tasks_object = directory_bucket.get("jimmy:tasks")
|
directory.content_type = "text/plain"
|
||||||
tasks_object.data = old_timestamp
|
directory.data = 2.seconds.ago.to_i.to_s
|
||||||
tasks_object.store
|
directory.store
|
||||||
|
|
||||||
put "/jimmy/tasks/private/projects/world-domination/start", "write a manifesto"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user