summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/backups.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/util/backups.rb
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'lib/puppet/util/backups.rb')
-rw-r--r--lib/puppet/util/backups.rb130
1 files changed, 65 insertions, 65 deletions
diff --git a/lib/puppet/util/backups.rb b/lib/puppet/util/backups.rb
index 1e051498c..c01bdd400 100644
--- a/lib/puppet/util/backups.rb
+++ b/lib/puppet/util/backups.rb
@@ -2,86 +2,86 @@ require 'find'
require 'fileutils'
module Puppet::Util::Backups
- # Deal with backups.
- def perform_backup(file = nil)
- # if they specifically don't want a backup, then just say
- # we're good
- return true unless self[:backup]
+ # Deal with backups.
+ def perform_backup(file = nil)
+ # if they specifically don't want a backup, then just say
+ # we're good
+ return true unless self[:backup]
- # let the path be specified
- file ||= self[:path]
- return true unless FileTest.exists?(file)
+ # let the path be specified
+ file ||= self[:path]
+ return true unless FileTest.exists?(file)
- return(self.bucket ? perform_backup_with_bucket(file) : perform_backup_with_backuplocal(file, self[:backup]))
- end
+ return(self.bucket ? perform_backup_with_bucket(file) : perform_backup_with_backuplocal(file, self[:backup]))
+ end
- private
+ private
- def perform_backup_with_bucket(fileobj)
- file = (fileobj.class == String) ? fileobj : fileobj.name
- case File.stat(file).ftype
- when "directory"
- # we don't need to backup directories when recurse is on
- return true if self[:recurse]
- info "Recursively backing up to filebucket"
- Find.find(self[:path]) { |f| backup_file_with_filebucket(f) if File.file?(f) }
- when "file"; backup_file_with_filebucket(file)
- when "link";
- end
- true
+ def perform_backup_with_bucket(fileobj)
+ file = (fileobj.class == String) ? fileobj : fileobj.name
+ case File.stat(file).ftype
+ when "directory"
+ # we don't need to backup directories when recurse is on
+ return true if self[:recurse]
+ info "Recursively backing up to filebucket"
+ Find.find(self[:path]) { |f| backup_file_with_filebucket(f) if File.file?(f) }
+ when "file"; backup_file_with_filebucket(file)
+ when "link";
end
+ true
+ end
- def perform_backup_with_backuplocal(fileobj, backup)
- file = (fileobj.class == String) ? fileobj : fileobj.name
- newfile = file + backup
+ def perform_backup_with_backuplocal(fileobj, backup)
+ file = (fileobj.class == String) ? fileobj : fileobj.name
+ newfile = file + backup
- remove_backup(newfile)
+ remove_backup(newfile)
- begin
- bfile = file + backup
+ begin
+ bfile = file + backup
- # Ruby 1.8.1 requires the 'preserve' addition, but
- # later versions do not appear to require it.
- # N.B. cp_r works on both files and directories
- FileUtils.cp_r(file, bfile, :preserve => true)
- return true
- rescue => detail
- # since they said they want a backup, let's error out
- # if we couldn't make one
- self.fail "Could not back #{file} up: #{detail.message}"
- end
+ # Ruby 1.8.1 requires the 'preserve' addition, but
+ # later versions do not appear to require it.
+ # N.B. cp_r works on both files and directories
+ FileUtils.cp_r(file, bfile, :preserve => true)
+ return true
+ rescue => detail
+ # since they said they want a backup, let's error out
+ # if we couldn't make one
+ self.fail "Could not back #{file} up: #{detail.message}"
end
+ end
- def remove_backup(newfile)
- if self.class.name == :file and self[:links] != :follow
- method = :lstat
- else
- method = :stat
- end
+ def remove_backup(newfile)
+ if self.class.name == :file and self[:links] != :follow
+ method = :lstat
+ else
+ method = :stat
+ end
- begin
- stat = File.send(method, newfile)
- rescue Errno::ENOENT
- return
- end
+ begin
+ stat = File.send(method, newfile)
+ rescue Errno::ENOENT
+ return
+ end
- if stat.ftype == "directory"
- raise Puppet::Error, "Will not remove directory backup #{newfile}; use a filebucket"
- end
+ if stat.ftype == "directory"
+ raise Puppet::Error, "Will not remove directory backup #{newfile}; use a filebucket"
+ end
- info "Removing old backup of type #{stat.ftype}"
+ info "Removing old backup of type #{stat.ftype}"
- begin
- File.unlink(newfile)
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- self.fail "Could not remove old backup: #{detail}"
- end
+ begin
+ File.unlink(newfile)
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ self.fail "Could not remove old backup: #{detail}"
end
+ end
- def backup_file_with_filebucket(f)
- sum = self.bucket.backup(f)
- self.info "Filebucketed #{f} to #{self.bucket.name} with sum #{sum}"
- return sum
- end
+ def backup_file_with_filebucket(f)
+ sum = self.bucket.backup(f)
+ self.info "Filebucketed #{f} to #{self.bucket.name} with sum #{sum}"
+ return sum
+ end
end