lib/fakes3/file_store.rb in fakes3-0.1.0 vs lib/fakes3/file_store.rb in fakes3-0.1.1

- old
+ new

@@ -110,22 +110,23 @@ obj.md5 = src_metadata[:md5] obj.content_type = src_metadata[:content_type] return obj end - def store_object(bucket,object,request) + def store_object(bucket,object_name,request) begin - filename = File.join(@root,bucket,object) + filename = File.join(@root,bucket.name,object_name) FileUtils.mkdir_p(filename) metadata_dir = File.join(filename,SHUCK_METADATA_DIR) FileUtils.mkdir_p(metadata_dir) content = File.join(filename,SHUCK_METADATA_DIR,"content") metadata = File.join(filename,SHUCK_METADATA_DIR,"metadata") md5 = Digest::MD5.new + # TODO put a tmpfile here first and mv it over at the end File.open(content,'wb') do |f| request.body do |chunk| f << chunk md5 << chunk @@ -137,13 +138,30 @@ metadata_struct[:content_type] = request.header["content-type"].first File.open(metadata,'w') do |f| f << YAML::dump(metadata_struct) end + obj = S3Object.new + obj.name = object_name obj.md5 = metadata_struct[:md5] obj.content_type = metadata_struct[:content_type] + + # TODO need a semaphore here since bucket is not probably not thread safe + bucket << obj return obj + rescue + puts $! + $!.backtrace.each { |line| puts line } + return nil + end + end + + def delete_object(bucket,object_name,request) + begin + filename = File.join(@root,bucket.name,object_name) + FileUtils.rm_rf(filename) + bucket.delete(object_name) rescue puts $! $!.backtrace.each { |line| puts line } return nil end