From 262acc37b75a86ba88d56bc6a8b7dce8dd26a52c Mon Sep 17 00:00:00 2001 From: Cam Jackson Date: Thu, 19 Oct 2017 13:50:43 +0800 Subject: [PATCH] Fix list-objects returning nothing after restarting --- lib/fakes3/file_store.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/fakes3/file_store.rb b/lib/fakes3/file_store.rb index 03e98f3f..1a815c20 100644 --- a/lib/fakes3/file_store.rb +++ b/lib/fakes3/file_store.rb @@ -21,7 +21,7 @@ def initialize(root) @bucket_hash = {} Dir[File.join(root,"*")].each do |bucket| bucket_name = File.basename(bucket) - bucket_obj = Bucket.new(bucket_name,Time.now,[]) + bucket_obj = Bucket.new(bucket_name, Time.now, get_objects(bucket_name, bucket)) @buckets << bucket_obj @bucket_hash[bucket_name] = bucket_obj end @@ -278,5 +278,26 @@ def create_metadata(content,request) end return metadata end + + private + + def get_objects(bucket_name, path, root_path=nil) + if root_path.nil? + root_path = path + end + + objects = [] + if File.directory?(path) + Dir.new(path).each do |pathname| + next if ['.', '..'].include?(pathname) + if pathname == SHUCK_METADATA_DIR + objects << get_object(bucket_name, path[root_path.length+1..-1], nil) + else + objects += get_objects(bucket_name, File.join(path, pathname), root_path) + end + end + end + return objects + end end end