Method: AssetSync::Storage#remote_files

Defined in:
lib/asset_sync/storage.rb

#remote_filesObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/asset_sync/storage.rb', line 81

def remote_files
  return [] if ignore_existing_remote_files?
  return @remote_files if @remote_files

  if remote_file_list_remote_path && remote_file_list_cache_file_path
    log "Downloading file list file from remote"
    remote_cache_file = bucket.files.get(remote_file_list_remote_path)
    if remote_cache_file
      File.open(remote_file_list_cache_file_path, 'w') do |local_file|
        local_file.write(remote_cache_file.body)
      end
    end
  end

  if remote_file_list_cache_file_path && File.file?(remote_file_list_cache_file_path)
    begin
      content = File.read(remote_file_list_cache_file_path)
      return @remote_files = JSON.parse(content)
    rescue JSON::ParserError
      warn "Failed to parse #{remote_file_list_cache_file_path} as json"
    end
  end

  @remote_files = get_remote_files
end