lib/cloudsync/backend/s3.rb in cloudsync-2.1.1 vs lib/cloudsync/backend/s3.rb in cloudsync-2.2.0

- old
+ new

@@ -65,22 +65,32 @@ end end rescue RightAws::AwsError => e $LOGGER.error("Caught error: #{e} trying to delete #{file}") end - + def files_to_sync(upload_prefix="") $LOGGER.info("Getting files to sync [#{self}]") buckets_to_sync(upload_prefix).inject([]) do |files, bucket| objects_from_bucket(bucket, upload_prefix).collect do |key| - files << Cloudsync::File.from_s3_obj(key, self.to_s) + file = Cloudsync::File.from_s3_obj(key, self.to_s) + if block_given? + yield file + else + files << file + end end files end end + # Convenience to grab a single file + def get_file_from_store(file) + Cloudsync::File.from_s3_obj( get_obj_from_store(file), self.to_s ) + end + private def buckets_to_sync(upload_prefix="") bucket_name = upload_prefix.split("/").first if bucket_name @@ -89,10 +99,12 @@ @store.buckets end end def objects_from_bucket(bucket, upload_prefix="") + $LOGGER.debug("Getting files from #{bucket}") + prefix_parts = upload_prefix.split("/") prefix_parts.shift prefix = prefix_parts.join("/") if !prefix.empty? @@ -100,20 +112,14 @@ else bucket.keys end end - # Convenience to grab a single file - def get_file_from_store(file) - Cloudsync::File.from_s3_obj( get_obj_from_store(file), self.to_s ) - end - def get_or_create_obj_from_store(file) @store.bucket(file.bucket, true).key(file.upload_path) end def get_obj_from_store(file) - $LOGGER.debug("gofs, buck: #{file.bucket}. upload path: #{file.upload_path}") if bucket = @store.bucket(file.bucket) key = bucket.key(file.upload_path) return key if key.exists? end end \ No newline at end of file