2011-06-28 02:05:18 -04:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 15:07:16 -04:00
|
|
|
require 'fog/ninefold/models/storage/directory'
|
2011-06-28 02:05:18 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class Ninefold
|
|
|
|
|
|
|
|
class Directories < Fog::Collection
|
|
|
|
|
2011-07-09 02:55:55 -04:00
|
|
|
attribute :directory
|
|
|
|
|
2011-06-28 02:05:18 -04:00
|
|
|
model Fog::Storage::Ninefold::Directory
|
|
|
|
|
|
|
|
def all
|
2011-07-09 02:55:55 -04:00
|
|
|
directory ? ns = directory.key : ns = ''
|
2011-07-10 09:44:35 -04:00
|
|
|
ns = ns + '/' unless ns =~ /\/$/
|
2011-07-09 02:55:55 -04:00
|
|
|
data = connection.get_namespace(ns).body[:DirectoryList]
|
2011-06-28 02:05:18 -04:00
|
|
|
data = {:DirectoryEntry => []} if data.kind_of? String
|
|
|
|
data[:DirectoryEntry] = [data[:DirectoryEntry]] if data[:DirectoryEntry].kind_of? Hash
|
2011-07-09 02:55:55 -04:00
|
|
|
dirs = data[:DirectoryEntry].select {|de| de[:FileType] == 'directory'}
|
2011-07-10 09:44:35 -04:00
|
|
|
dirs.each do |d|
|
|
|
|
d[:Filename] = ns + d[:Filename] if directory
|
|
|
|
d[:Filename] += '/' unless d[:Filename] =~ /\/$/
|
|
|
|
end
|
|
|
|
load(dirs)
|
2011-06-28 02:05:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def get(key, options = {})
|
|
|
|
return nil if key == '' # Root dir shouldn't be retrieved like this.
|
2011-07-10 09:44:35 -04:00
|
|
|
key =~ /\/$/ ? ns = key : ns = key + '/'
|
|
|
|
res = connection.get_namespace ns
|
2011-06-28 02:05:18 -04:00
|
|
|
emc_meta = res.headers['x-emc-meta']
|
|
|
|
obj_id = emc_meta.scan(/objectid=(\w+),/).flatten[0]
|
2011-07-10 09:44:35 -04:00
|
|
|
new(:objectid => obj_id, :key => ns)
|
2011-06-28 02:05:18 -04:00
|
|
|
rescue Fog::Storage::Ninefold::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2011-07-09 02:55:55 -04:00
|
|
|
def new(attributes ={})
|
|
|
|
attributes = {:directory => directory}.merge(attributes) if directory
|
|
|
|
super(attributes)
|
|
|
|
end
|
|
|
|
|
2011-06-28 02:05:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|