lib/fog/aliyun/models/storage/files.rb in fog-aliyun-0.3.15 vs lib/fog/aliyun/models/storage/files.rb in fog-aliyun-0.3.16
- old
+ new
@@ -34,55 +34,39 @@
# trim the suffix '/'
directory_key = directory_key.chomp('/')
# The bucket name can not contain '/', so if directory_key, return directory.
if directory_key.include? '/'
directory_key
+ elsif service.bucket_exists?(directory_key)
+ bucket_name = directory_key
+ directory_key = ''
else
- data = service.get_bucket(directory_key)
- if data.class == Hash && data.key?('Code') && !data['Code'].nil? && !data['Code'].empty?
- directory_key
- else
- bucket_name = directory_key
- directory_key = ''
- end
+ directory_key
end
end
return bucket_name, directory_key
end
def all(options = {})
requires :directory
- bucket_name, directory_key = check_directory_key(directory.key)
- remap_attributes(options, {
- :delimiter => 'delimiter',
- :marker => 'marker',
- :max_keys => 'max-keys',
- :prefix => 'prefix'
- })
- prefix_value = options['prefix']
- prefix_value = directory_key + '/' + prefix if directory_key != '' && directory_key != '.' && !directory_key.nil?
- options['prefix'] = prefix_value
- options['bucket'] = bucket_name
- files = service.list_objects(options)['Contents']
- return if files.nil?
- data = []
- i = 0
- files.each do |file|
- next unless file['Key'][0][-1] != '/'
- content_length = file['Size'][0].to_i
- key = file['Key'][0]
- lastModified = file['LastModified'][0]
- last_modified = (Time.parse(lastModified).localtime if !lastModified.nil? && lastModified != '')
- type = file['Type'][0]
- data[i] = { content_length: content_length,
- key: key,
- last_modified: last_modified,
- etag: file['ETag'][0],
- object_type: type }
- i += 1
+ options = {
+ 'delimiter' => delimiter,
+ 'marker' => marker,
+ 'max-keys' => max_keys.to_i,
+ 'prefix' => prefix
+ }.merge!(options)
+ options = options.reject {|key,value| value.nil? || value.to_s.empty?}
+ merge_attributes(options)
+ parent = directory.collection.get(
+ directory.key,
+ options
+ )
+ if parent
+ merge_attributes(parent.files.attributes)
+ load(parent.files.map {|file| file.attributes})
+ else
+ nil
end
-
- load(data)
end
alias each_file_this_page each
def each
if !block_given?