Method: FakeS3::FileStore#copy_object

Defined in:
lib/fakes3/file_store.rb

#copy_object(src_bucket_name, src_name, dst_bucket_name, dst_name, request) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/fakes3/file_store.rb', line 113

def copy_object(src_bucket_name, src_name, dst_bucket_name, dst_name, request)
  src_root = File.join(@root,src_bucket_name,src_name,FAKE_S3_METADATA_DIR)
   = File.join(src_root, "metadata")
   = YAML.load(File.open(, 'rb').read)
  src_content_filename = File.join(src_root, "content")

  dst_filename= File.join(@root,dst_bucket_name,dst_name)
  FileUtils.mkdir_p(dst_filename)

   = File.join(dst_filename,FAKE_S3_METADATA_DIR)
  FileUtils.mkdir_p()

  content = File.join(, "content")
   = File.join(, "metadata")

  if src_bucket_name != dst_bucket_name || src_name != dst_name
    File.open(content, 'wb') do |f|
      File.open(src_content_filename, 'rb') do |input|
        f << input.read
      end
    end

    File.open(,'w') do |f|
      File.open(,'r') do |input|
        f << input.read
      end
    end
  end

   = request.header["x-amz-metadata-directive"].first
  if  == "REPLACE"
     = (content, request)
    File.open(,'w') do |f|
      f << YAML::dump()
    end
  end

  src_bucket = get_bucket(src_bucket_name) || create_bucket(src_bucket_name)
  dst_bucket = get_bucket(dst_bucket_name) || create_bucket(dst_bucket_name)

  obj = S3Object.new
  obj.name = dst_name
  obj.md5 = [:md5]
  obj.content_type = [:content_type]
  obj.content_disposition = [:content_disposition]
  obj.content_encoding = [:content_encoding] # if src_metadata[:content_encoding]
  obj.size = [:size]
  obj.modified_date = [:modified_date]

  src_bucket.find(src_name)
  dst_bucket.add(obj)
  return obj
end