From e8c53071a1eb1dbb312aafbe6c0f111145f7c3bb Mon Sep 17 00:00:00 2001 From: Jason Hutchens Date: Wed, 9 Nov 2011 11:10:02 +0800 Subject: [PATCH 1/4] fixes https://github.com/rumblelabs/asset_sync/issues/16 --- lib/asset_sync/storage.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 0c65343e..6e7740de 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -31,7 +31,11 @@ def local_files def get_remote_files raise BucketNotFound.new("AWS Bucket: #{self.config.aws_bucket} not found.") unless bucket - return bucket.files.map { |f| f.key } + # fixes: https://github.com/rumblelabs/asset_sync/issues/16 + # (work-around for https://github.com/fog/fog/issues/596) + files = [] + bucket.files.each { |f| files << f.key } + return files end def delete_file(f, remote_files_to_delete) @@ -115,4 +119,4 @@ def sync end end -end \ No newline at end of file +end From 649dd6713a246daf2c70646d39f60f5e1d17039d Mon Sep 17 00:00:00 2001 From: Jason Hutchens Date: Wed, 9 Nov 2011 11:38:47 +0800 Subject: [PATCH 2/4] fixes https://github.com/rumblelabs/asset_sync/issues/18 --- lib/asset_sync/storage.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 6e7740de..d352cfa1 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -14,7 +14,8 @@ def connection end def bucket - @bucket ||= connection.directories.get(self.config.aws_bucket) + # fixes: https://github.com/rumblelabs/asset_sync/issues/18 + @bucket ||= connection.directories.get(self.config.aws_bucket, :prefix => 'assets') end def keep_existing_remote_files? From bdfaf15c8d3b410e17f97a5d25fa8cf5a8356832 Mon Sep 17 00:00:00 2001 From: Jason Hutchens Date: Wed, 9 Nov 2011 12:49:46 +0800 Subject: [PATCH 3/4] Implements https://github.com/rumblelabs/asset_sync/issues/17 --- lib/asset_sync/config.rb | 3 +++ lib/asset_sync/storage.rb | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index 8735f683..c0b85751 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -10,6 +10,7 @@ class Invalid < StandardError; end attr_accessor :aws_region attr_accessor :existing_remote_files attr_accessor :gzip_compression + attr_accessor :manifest validates :aws_access_key, :presence => true validates :aws_access_secret, :presence => true @@ -21,6 +22,7 @@ def initialize self.aws_region = nil self.existing_remote_files = 'keep' self.gzip_compression = false + self.manifest = nil load_yml! if yml_exists? end @@ -52,6 +54,7 @@ def load_yml! self.aws_region = yml["aws_region"] if yml.has_key?("aws_region") self.existing_remote_files = yml["existing_remote_files"] if yml.has_key?("existing_remote_files") self.gzip_compression = yml["gzip_compression"] if yml.has_key?("gzip_compression") + self.manifest = yml["manifest"] if yml.has_key?("manifest") # TODO deprecate old style config settings self.aws_access_key = yml["access_key_id"] if yml.has_key?("access_key_id") diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index d352cfa1..2b9585b4 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -27,9 +27,20 @@ def path end def local_files - Dir["#{path}/assets/**/**"].map { |f| f[path.length+1,f.length-path.length] } + @local_files ||= get_local_files end + def get_local_files + if self.config.manifest + path = File.join(self.config.manifest, 'manifest.yml') + if File.exists?(path) + yml = YAML.load(IO.read(path)) + return yml.values.map { |f| File.join('assets', f) } + end + end + Dir["#{path}/assets/**/**"].map { |f| f[path.length+1,f.length-path.length] } + end + def get_remote_files raise BucketNotFound.new("AWS Bucket: #{self.config.aws_bucket} not found.") unless bucket # fixes: https://github.com/rumblelabs/asset_sync/issues/16 From e26f5ca36dee1c2196653268ed6bb38c0226e4d2 Mon Sep 17 00:00:00 2001 From: Jason Hutchens Date: Wed, 9 Nov 2011 13:00:37 +0800 Subject: [PATCH 4/4] fixes https://github.com/rumblelabs/asset_sync/issues/19 --- lib/asset_sync/storage.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 2b9585b4..68d09eac 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -60,7 +60,8 @@ def delete_file(f, remote_files_to_delete) def delete_extra_remote_files STDERR.puts "Fetching files to flag for delete" remote_files = get_remote_files - from_remote_files_to_delete = (local_files | remote_files) - (local_files & remote_files) + # fixes: https://github.com/rumblelabs/asset_sync/issues/19 + from_remote_files_to_delete = remote_files - local_files STDERR.puts "Flagging #{from_remote_files_to_delete.size} file(s) for deletion" # Delete unneeded remote files @@ -115,7 +116,8 @@ def upload_file(f) def upload_files # get a fresh list of remote files remote_files = get_remote_files - local_files_to_upload = (remote_files | local_files) - (remote_files & local_files) + # fixes: https://github.com/rumblelabs/asset_sync/issues/19 + local_files_to_upload = local_files - remote_files # Upload new files local_files_to_upload.each do |f| @@ -125,8 +127,9 @@ def upload_files end def sync - delete_extra_remote_files unless keep_existing_remote_files? + # fixes: https://github.com/rumblelabs/asset_sync/issues/19 upload_files + delete_extra_remote_files unless keep_existing_remote_files? STDERR.puts "Done." end