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

Chdir in a block to dry up all method

- also, plays much nicer with FakeFS
This commit is contained in:
Karl Freeman 2013-05-27 16:07:26 +01:00
parent 08de898804
commit 6ddc27f5de

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