Class: Outback::DirectoryTarget

Inherits:
Target show all
Defined in:
lib/outback/directory_target.rb

Instance Attribute Summary collapse

Attributes inherited from Target

#backup_name

Instance Method Summary collapse

Methods inherited from Target

#purge!

Methods included from Logging

#logger

Methods included from Configurable

#attr_setter, included

Constructor Details

#initialize(backup_name, path) ⇒ DirectoryTarget



6
7
8
9
# File 'lib/outback/directory_target.rb', line 6

def initialize(backup_name, path)
  super(backup_name)
  @path = Pathname.new(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/outback/directory_target.rb', line 3

def path
  @path
end

Instance Method Details

#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

#to_sObject



15
16
17
# File 'lib/outback/directory_target.rb', line 15

def to_s
  "directory:#{path}"
end

#valid?Boolean



11
12
13
# File 'lib/outback/directory_target.rb', line 11

def valid?
  (user and group) or (not user and not group)
end