Method: Outback::DirectoryTarget#put

Defined in:
lib/outback/directory_target.rb

#put(archives) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/outback/directory_target.rb', line 19

def put(archives)
  FileUtils.mkdir_p(path) unless path.directory?
  FileUtils.chmod directory_permissions || 0700, path
  size = 0
  archives.each do |archive|
    basename = Pathname.new(archive.filename).basename
    if move
      logger.debug "moving #{archive.filename} to #{path}"
      FileUtils.mv archive.filename, path
    else
      logger.debug "copying #{archive.filename} to #{path}"
      FileUtils.cp_r archive.filename, path
    end
    archived_file = path.join(basename)
    logger.debug "setting permissions for #{archived_file}"
    FileUtils.chmod archive_permissions || 0600, archived_file
    if user && group
      logger.debug "setting owner #{user}, group #{group} for #{archived_file}"
      FileUtils.chown user, group, archived_file
    end
    size += archived_file.size
  end
  logger.info "#{move ? 'Moved' : 'Copied'} #{archives.size} archives (#{size} bytes) to #{self}"
  archives.size
end