class Aptly::Files

Aptly files management. @see www.aptly.info/doc/api/files/

Public Class Methods

delete(path, connection = Connection.new, **kwords) click to toggle source

Delete files from remote's upload directory. @param path [String] path to delete (this may be a directory or a file) @return [nil]

# File lib/aptly/files.rb, line 67
def delete(path, connection = Connection.new, **kwords)
  connection.send(:delete, "/files/#{path}", kwords)
  nil
end
tmp_upload(files, connection = Connection.new, **kwords) { |dir| ... } click to toggle source

Upload files into a temporary directory on remote. This method expects a block which will be yielded to with the directory name on the remote. The directory will be deleted when this method returns. You'll generally want to use this instead of upload so you don't have to worry about name collission and clean up.

@param files [Array<String>] paths to files to upload @param connection [Connection] connection to use @yield [String] the remote directory name the files were uploaded to @return return value of block

@example Can be used to push into multiple repositories with one upload

Files.tmp_upload(files) do |d|
  repos.each { |r| r.add_files(d, noRemove: 1) }
end

@since 0.9.0

# File lib/aptly/files.rb, line 50
def tmp_upload(files, connection = Connection.new, **kwords)
  # TODO: 1.0 find out if #upload even has a use case and maybe replace it
  dir = tmp_dir_name
  upload(files, dir, connection, **kwords)
  uploaded = true
  yield dir
ensure
  # We have an uploaded var here as exceptions raised by upload would
  # still run this, but they may not have the remote file, so our
  # delete request would again cause an error making it harder to spot
  # the orignal problem.
  delete(dir) if uploaded
end
upload(files, directory, connection = Connection.new, **kwords) click to toggle source

Upload files to remote @param files [Array<String>] paths to files to upload @param directory [String] name of the directory to upload to. @param connection [Connection] connection to use @return [Array<String>] list of files now on the remote

# File lib/aptly/files.rb, line 26
def upload(files, directory, connection = Connection.new, **kwords)
  files.each_with_index { |f, i| kwords["file_#{i}".to_sym] = f }
  response = connection.send(:post, "/files/#{directory}", kwords)
  JSON.parse(response.body)
end

Private Class Methods

tmp_dir_name() click to toggle source
# File lib/aptly/files.rb, line 74
def tmp_dir_name
  prefix = "#{to_s.tr(':', '_')}-#{Socket.gethostname}"
  TmpName.dir(prefix)
end