1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add Atmos meta_data request and file_size

This commit is contained in:
Toby Hede 2013-10-10 16:41:10 +11:00
parent a4493b8c4f
commit 45089ca8ba
2 changed files with 15 additions and 8 deletions

View file

@ -11,6 +11,7 @@ module Fog
attribute :content_length, :aliases => ['bytes', 'Content-Length'], :type => :integer
attribute :content_type, :aliases => ['content_type', 'Content-Type']
attribute :objectid, :aliases => :ObjectID
attribute :created_at, :aliases => :ctime
def body
attributes[:body] ||= if objectid
@ -42,14 +43,15 @@ module Fog
true
end
# def owner=(new_owner)
# if new_owner
# attributes[:owner] = {
# :display_name => new_owner['DisplayName'],
# :id => new_owner['ID']
# }
# end
# end
def meta_data
requires :directory, :key
service.get_namespace([directory.key, key].join('/') + "?metadata/system")
end
def file_size
data = meta_data
meta_data.headers["x-emc-meta"].match(/size=\d+/).to_s.gsub(/size=/,"")
end
def public=(new_public)
# NOOP - we don't need to flag files as public, getting the public URL for a file handles it.

View file

@ -24,6 +24,11 @@ module Fog
data[:DirectoryEntry] = [data[:DirectoryEntry]] if data[:DirectoryEntry].kind_of? Hash
files = data[:DirectoryEntry].select {|de| de[:FileType] == 'regular'}
files.each do |s|
data = service.head_namespace(directory.key + s[:Filename], :parse => false)
headers = Hash[data.headers["x-emc-meta"].split(", ").collect{|s|s.split("=")}]
s[:content_length] = data.headers["Content-Length"]
s[:content_type] = data.headers["Content-Type"]
s[:created_at] = headers["ctime"]
s[:directory] = directory
end
# TODO - Load additional file meta?