AssetSync / asset_sync

Synchronises Assets between Rails and S3
1.88k stars 346 forks source link

existing_remote_files = 'delete' on Rackspace Cloud Files #280

Open ghost opened 10 years ago

ghost commented 10 years ago

Using asset_sync via middleman-sync, I found that no files are actually retrieved from the given bucket, so existing_remote_files = 'delete' flags no files for deletion.

Comparing lib/asset_sync/storage.rb with fog's delete_file.rb example, bucket.files should return 37 files in this container, but instead comes up empty in get_remote_files

I modified

% sed -n 98,107p ~/.gem/ruby/2.1.0/gems/asset_sync-1.0.0/lib/asset_sync/storage.rb ~/.gem/ruby/2.1.0/gems/asset_sync-1.0.0/lib/asset_sync/storage.rb

    def get_remote_files
      raise BucketNotFound.new("#{self.config.fog_provider} Bucket: #{self.config.fog_directory} not found.") unless bucket
      # fixes: https://github.com/rumblelabs/asset_sync/issues/16
      #        (work-around for https://github.com/fog/fog/issues/596)
      files = []
      ap bucket
      ap bucket.files
      bucket.files.each { |f| files << f.key }
      return files
    end

which shows that the Fog::Storage::Rackspace::Directory has 37 files (which it does), but ap bucket.files just prints the square brackets of an empty array.

% middleman sync

...snip...
Fetching files to flag for delete
  <Fog::Storage::Rackspace::Directory
    key="rstroxbucket",
    bytes=2093842,
    count=37,
    cdn_cname=nil
  >
[]
Flagging 0 file(s) for deletion
AssetSync: Done.
ghost commented 10 years ago

I found that setting :prefix in #18 caused this. Changing line 23 in lib/asset_sync/storage.rb to

@bucket ||= connection.directories.get(self.config.fog_directory)

fixed delete functionality for me. I'll keep looking for a better solution.