lib/outback/directory_target.rb in outback-0.0.2 vs lib/outback/directory_target.rb in outback-0.0.3
- old
+ new
@@ -2,36 +2,40 @@
class DirectoryTarget < Target
attr_reader :path
attr_setter :user, :group, :directory_permissions, :archive_permissions, :ttl, :move
def initialize(path)
- @path = path
+ @path = Pathname.new(path)
end
def valid?
(user and group) or (not user and not group)
end
- def put(archives, timestamp)
- backup_folder = Pathname.new(path).join(timestamp[0..7]) # yyyymmdd
- Dir.mkdir(backup_folder) unless backup_folder.directory?
- FileUtils.chmod directory_permissions || 0700, backup_folder
+ def put(archives)
+ Dir.mkdir(path) unless path.directory?
+ FileUtils.chmod directory_permissions || 0700, path
archives.each do |archive|
basename = Pathname.new(archive.filename).basename
if move
- puts "moving #{archive.filename} to #{backup_folder}"
- FileUtils.mv archive.filename, backup_folder
+ Outback.debug "moving #{archive.filename} to #{path}"
+ FileUtils.mv archive.filename, path
else
- puts "copying #{archive.filename} to #{backup_folder}"
- FileUtils.cp_r
+ Outback.debug "copying #{archive.filename} to #{path}"
+ FileUtils.cp_r archive.filename, path
end
- archived_file = backup_folder.join(basename)
- puts "chmodding"
+ archived_file = path.join(basename)
+ Outback.debug "setting permissions for #{archived_file}"
FileUtils.chmod archive_permissions || 0600, archived_file
if user && group
- puts "chowning"
+ Outback.debug "setting owner #{user}, group #{group} for #{archived_file}"
FileUtils.chown user, group, archived_file
end
end
end
+
+ def list_archives
+ path.files(Archive::NAME_PATTERN).map { |f| DirectoryArchive.new(f, self) }
+ end
+
end
end
\ No newline at end of file