From 45089ca8bace83ffd9ecd244af1b9f888736fc59 Mon Sep 17 00:00:00 2001 From: Toby Hede Date: Thu, 10 Oct 2013 16:41:10 +1100 Subject: [PATCH] Add Atmos meta_data request and file_size --- lib/fog/atmos/models/storage/file.rb | 18 ++++++++++-------- lib/fog/atmos/models/storage/files.rb | 5 +++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/fog/atmos/models/storage/file.rb b/lib/fog/atmos/models/storage/file.rb index 18f25f35b..782746e77 100644 --- a/lib/fog/atmos/models/storage/file.rb +++ b/lib/fog/atmos/models/storage/file.rb @@ -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. diff --git a/lib/fog/atmos/models/storage/files.rb b/lib/fog/atmos/models/storage/files.rb index ea0044f40..7b800b96f 100644 --- a/lib/fog/atmos/models/storage/files.rb +++ b/lib/fog/atmos/models/storage/files.rb @@ -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?