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

Merge pull request #1836 from karlfreeman/block_local_chdir

Chdir in a block to dry up all method
This commit is contained in:
Wesley Beary 2013-05-28 06:42:28 -07:00
commit f6dc35bf06

View file

@ -14,19 +14,19 @@ module Fog
def all
requires :directory
if directory.collection.get(directory.key)
pwd = Dir.pwd
Dir.chdir(service.path_to(directory.key))
data = Dir.glob('**/*').reject do |file|
::File.directory?(file)
end.map do |key|
path = file_path(key)
{
:content_length => ::File.size(path),
:key => key,
:last_modified => ::File.mtime(path)
}
end
Dir.chdir(pwd)
data = []
Dir.chdir(service.path_to(directory.key)) {
data = Dir.glob('**/*').reject do |file|
::File.directory?(file)
end.map do |key|
path = file_path(key)
{
:content_length => ::File.size(path),
:key => key,
:last_modified => ::File.mtime(path)
}
end
}
load(data)
else
nil