From 1827f00c3a0aba353cb58f1e0b162fdde4c612fe Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Tue, 26 Apr 2011 15:13:56 -0700 Subject: [PATCH] [storage|aws] Make Files#each iterate all files, not just the first page. Removed Directory#each_file; it's not the API that people expect. This may break code that expects Files#each to only go a page at a time; those callers should switch to using #each_file_this_page. --- lib/fog/storage/models/aws/directory.rb | 15 --------------- lib/fog/storage/models/aws/files.rb | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/fog/storage/models/aws/directory.rb b/lib/fog/storage/models/aws/directory.rb index 9c0c4eec0..902cb4ae5 100644 --- a/lib/fog/storage/models/aws/directory.rb +++ b/lib/fog/storage/models/aws/directory.rb @@ -46,21 +46,6 @@ module Fog end end - def each_file - if !block_given? - Enumerable::Enumerator.new(self, :each_file) - else - page_of_files = files.all - page_of_files.each_nowarn {|f| yield f } - - while page_of_files.is_truncated - page_of_files = files.all(:marker => page_of_files.last.key) - page_of_files.each_nowarn {|f| yield f } - end - - end - end - def payer requires :key data = connection.get_request_payment(key) diff --git a/lib/fog/storage/models/aws/files.rb b/lib/fog/storage/models/aws/files.rb index ae6da2b8e..4e4b4ea60 100644 --- a/lib/fog/storage/models/aws/files.rb +++ b/lib/fog/storage/models/aws/files.rb @@ -39,10 +39,21 @@ module Fog end end - alias :each_nowarn :each + alias :each_file_this_page :each def each - Formatador.display_line("[yellow][WARN] fog: AWS::Storage::Files#each only works on the first page of files; consider using AWS::Storage::Directory#each_file instead[/]") - super + if !block_given? + self + else + subset = dup.all + + subset.each_file_this_page {|f| yield f} + while subset.is_truncated + subset = subset.all(:marker => subset.last.key) + subset.each_file_this_page {|f| yield f} + end + + self + end end def get(key, options = {}, &block)