diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
| commit | 3180b9d9b2c844dade1d361326600f7001ec66dd (patch) | |
| tree | 98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/provider/file | |
| parent | 543225970225de5697734bfaf0a6eee996802c04 (diff) | |
| download | puppet-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/provider/file')
| -rw-r--r-- | lib/puppet/provider/file/posix.rb | 146 | ||||
| -rw-r--r-- | lib/puppet/provider/file/win32.rb | 112 |
2 files changed, 129 insertions, 129 deletions
diff --git a/lib/puppet/provider/file/posix.rb b/lib/puppet/provider/file/posix.rb index d715d8802..6cbf98e9a 100644 --- a/lib/puppet/provider/file/posix.rb +++ b/lib/puppet/provider/file/posix.rb @@ -1,99 +1,99 @@ Puppet::Type.type(:file).provide :posix do - desc "Uses POSIX functionality to manage file's users and rights." + desc "Uses POSIX functionality to manage file's users and rights." - confine :feature => :posix + confine :feature => :posix - include Puppet::Util::POSIX - include Puppet::Util::Warnings + include Puppet::Util::POSIX + include Puppet::Util::Warnings - require 'etc' + require 'etc' - def id2name(id) - return id.to_s if id.is_a?(Symbol) - return nil if id > Puppet[:maximum_uid].to_i + def id2name(id) + return id.to_s if id.is_a?(Symbol) + return nil if id > Puppet[:maximum_uid].to_i - begin - user = Etc.getpwuid(id) - rescue TypeError - return nil - rescue ArgumentError - return nil - end - - if user.uid == "" - return nil - else - return user.name - end + begin + user = Etc.getpwuid(id) + rescue TypeError + return nil + rescue ArgumentError + return nil end - def insync?(current, should) - return true unless should - - should.each do |value| - if value =~ /^\d+$/ - uid = Integer(value) - elsif value.is_a?(String) - fail "Could not find user #{value}" unless uid = uid(value) - else - uid = value - end + if user.uid == "" + return nil + else + return user.name + end + end - return true if uid == current - end + def insync?(current, should) + return true unless should - unless Puppet.features.root? - warnonce "Cannot manage ownership unless running as root" - return true - end + should.each do |value| + if value =~ /^\d+$/ + uid = Integer(value) + elsif value.is_a?(String) + fail "Could not find user #{value}" unless uid = uid(value) + else + uid = value + end - false + return true if uid == current end - # Determine if the user is valid, and if so, return the UID - def validuser?(value) - Integer(value) rescue uid(value) || false + unless Puppet.features.root? + warnonce "Cannot manage ownership unless running as root" + return true end - def retrieve(resource) - unless stat = resource.stat(false) - return :absent - end + false + end + + # Determine if the user is valid, and if so, return the UID + def validuser?(value) + Integer(value) rescue uid(value) || false + end - currentvalue = stat.uid + def retrieve(resource) + unless stat = resource.stat(false) + return :absent + end - # On OS X, files that are owned by -2 get returned as really - # large UIDs instead of negative ones. This isn't a Ruby bug, - # it's an OS X bug, since it shows up in perl, too. - if currentvalue > Puppet[:maximum_uid].to_i - self.warning "Apparently using negative UID (#{currentvalue}) on a platform that does not consistently handle them" - currentvalue = :silly - end + currentvalue = stat.uid - currentvalue + # On OS X, files that are owned by -2 get returned as really + # large UIDs instead of negative ones. This isn't a Ruby bug, + # it's an OS X bug, since it shows up in perl, too. + if currentvalue > Puppet[:maximum_uid].to_i + self.warning "Apparently using negative UID (#{currentvalue}) on a platform that does not consistently handle them" + currentvalue = :silly end - def sync(path, links, should) - # Set our method appropriately, depending on links. - if links == :manage - method = :lchown - else - method = :chown - end + currentvalue + end - uid = nil - should.each do |user| - break if uid = validuser?(user) - end + def sync(path, links, should) + # Set our method appropriately, depending on links. + if links == :manage + method = :lchown + else + method = :chown + end - raise Puppet::Error, "Could not find user(s) #{should.join(",")}" unless uid + uid = nil + should.each do |user| + break if uid = validuser?(user) + end - begin - File.send(method, uid, nil, path) - rescue => detail - raise Puppet::Error, "Failed to set owner to '#{uid}': #{detail}" - end + raise Puppet::Error, "Could not find user(s) #{should.join(",")}" unless uid - :file_changed + begin + File.send(method, uid, nil, path) + rescue => detail + raise Puppet::Error, "Failed to set owner to '#{uid}': #{detail}" end + + :file_changed + end end diff --git a/lib/puppet/provider/file/win32.rb b/lib/puppet/provider/file/win32.rb index 93274ce0a..8ead69a89 100644 --- a/lib/puppet/provider/file/win32.rb +++ b/lib/puppet/provider/file/win32.rb @@ -1,74 +1,74 @@ Puppet::Type.type(:file).provide :microsoft_windows do - desc "Uses Microsoft Windows functionality to manage file's users and rights." + desc "Uses Microsoft Windows functionality to manage file's users and rights." - confine :feature => :microsoft_windows + confine :feature => :microsoft_windows - include Puppet::Util::Warnings + include Puppet::Util::Warnings - require 'sys/admin' if Puppet.features.microsoft_windows? + require 'sys/admin' if Puppet.features.microsoft_windows? - def id2name(id) - return id.to_s if id.is_a?(Symbol) - return nil if id > Puppet[:maximum_uid].to_i - # should translate ID numbers to usernames - id - end - - def insync?(current, should) - return true unless should + def id2name(id) + return id.to_s if id.is_a?(Symbol) + return nil if id > Puppet[:maximum_uid].to_i + # should translate ID numbers to usernames + id + end - should.each do |value| - if value =~ /^\d+$/ - uid = Integer(value) - elsif value.is_a?(String) - fail "Could not find user #{value}" unless uid = uid(value) - else - uid = value - end + def insync?(current, should) + return true unless should - return true if uid == current - end + should.each do |value| + if value =~ /^\d+$/ + uid = Integer(value) + elsif value.is_a?(String) + fail "Could not find user #{value}" unless uid = uid(value) + else + uid = value + end - unless Puppet.features.root? - warnonce "Cannot manage ownership unless running as root" - return true - end - - false + return true if uid == current end - # Determine if the user is valid, and if so, return the UID - def validuser?(value) - info "Is '#{value}' a valid user?" - return 0 - begin - number = Integer(value) - return number - rescue ArgumentError - number = nil - end - (number = uid(value)) && number + unless Puppet.features.root? + warnonce "Cannot manage ownership unless running as root" + return true end - def retrieve(resource) - unless stat = resource.stat(false) - return :absent - end - - currentvalue = stat.uid + false + end - # On OS X, files that are owned by -2 get returned as really - # large UIDs instead of negative ones. This isn't a Ruby bug, - # it's an OS X bug, since it shows up in perl, too. - if currentvalue > Puppet[:maximum_uid].to_i - self.warning "Apparently using negative UID (#{currentvalue}) on a platform that does not consistently handle them" - currentvalue = :silly - end + # Determine if the user is valid, and if so, return the UID + def validuser?(value) + info "Is '#{value}' a valid user?" + return 0 + begin + number = Integer(value) + return number + rescue ArgumentError + number = nil + end + (number = uid(value)) && number + end - currentvalue + def retrieve(resource) + unless stat = resource.stat(false) + return :absent end - def sync(path, links, should) - info("should set '%s'%%owner to '%s'" % [path, should]) + currentvalue = stat.uid + + # On OS X, files that are owned by -2 get returned as really + # large UIDs instead of negative ones. This isn't a Ruby bug, + # it's an OS X bug, since it shows up in perl, too. + if currentvalue > Puppet[:maximum_uid].to_i + self.warning "Apparently using negative UID (#{currentvalue}) on a platform that does not consistently handle them" + currentvalue = :silly end + + currentvalue + end + + def sync(path, links, should) + info("should set '%s'%%owner to '%s'" % [path, should]) + end end |
