summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-10-31 16:19:41 -0500
committerLuke Kanies <luke@madstop.com>2008-11-04 16:20:45 -0600
commitcaf15c27b84f2777d68e569cea11ef9534c44ed4 (patch)
treed610612e91e12bfcb34778cbcc3116ad4e172310 /lib
parentcccd83853883a84a31f22446e9d3be8501655739 (diff)
downloadpuppet-caf15c27b84f2777d68e569cea11ef9534c44ed4.tar.gz
puppet-caf15c27b84f2777d68e569cea11ef9534c44ed4.tar.xz
puppet-caf15c27b84f2777d68e569cea11ef9534c44ed4.zip
Fixing and migrating more file tests.
This is an unfortunately messy commit; I should have tried harder to separate the different tasks into different commits, but it's not worth going back and doing now. This is the first commit in the long road of fixing the existing file tests, and in the process refactoring and better testing the code. The refactoring in this commit is mostly around the 'stat' instance variable that tests whether the file exists (and provides its metadata if it does) and the 'insync?' method in the source property. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/type/file.rb8
-rwxr-xr-xlib/puppet/type/file/source.rb27
2 files changed, 18 insertions, 17 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index c55ff29a7..155cf62f4 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -339,6 +339,7 @@ module Puppet
@parameters.each do |name, param|
param.flush if param.respond_to?(:flush)
end
+ @stat = nil
end
# Deal with backups.
@@ -729,14 +730,15 @@ module Puppet
method = :lstat
end
path = self[:path]
+
if @stat.nil? or refresh == true
begin
@stat = File.send(method, self[:path])
rescue Errno::ENOENT => error
- @stat = nil
+ return nil
rescue Errno::EACCES => error
- self.warning "Could not stat; permission denied"
- @stat = nil
+ warning "Could not stat; permission denied"
+ return nil
end
end
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index e43706051..60d4a5708 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -89,9 +89,9 @@ module Puppet
def change_to_s(currentvalue, newvalue)
# newvalue = "{md5}" + @metadata.checksum
if @resource.property(:ensure).retrieve == :absent
- return "creating from source %s with contents %s" % [metadata.source, @metadata.checksum]
+ return "creating from source %s with contents %s" % [metadata.source, metadata.checksum]
else
- return "replacing from source %s with contents %s" % [metadata.source, @metadata.checksum]
+ return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum]
end
end
@@ -108,8 +108,8 @@ module Puppet
raise Puppet::DevError, "No source for content was stored with the metadata" unless metadata.source
unless defined?(@content) and @content
- unless tmp = Puppet::FileServing::Content.find(@metadata.source)
- fail "Could not find any content at %s" % @metadata.source
+ unless tmp = Puppet::FileServing::Content.find(metadata.source)
+ fail "Could not find any content at %s" % metadata.source
end
@content = tmp.content
end
@@ -147,18 +147,17 @@ module Puppet
def insync?(currentvalue)
# the only thing this actual state can do is copy files around. Therefore,
# only pay attention if the remote is a file.
- unless @metadata.ftype == "file"
- return true
- end
+ return true unless metadata.ftype == "file"
- #FIXARB: Inefficient? Needed to call retrieve on parent's ensure and checksum
- parentensure = @resource.property(:ensure).retrieve
- if parentensure != :absent and ! @resource.replace?
- return true
- end
+ # The file is not in sync if it doesn't even exist.
+ return false unless resource.stat
+
+ # The file is considered in sync if it exists and 'replace' is false.
+ return true unless resource.replace?
+
# Now, we just check to see if the checksums are the same
parentchecksum = @resource.property(:checksum).retrieve
- result = (!parentchecksum.nil? and (parentchecksum == @metadata.checksum))
+ result = (!parentchecksum.nil? and (parentchecksum == metadata.checksum))
# Diff the contents if they ask it. This is quite annoying -- we need to do this in
# 'insync?' because they might be in noop mode, but we don't want to do the file
@@ -174,7 +173,7 @@ module Puppet
end
def found?
- ! (@metadata.nil? or @metadata.ftype.nil?)
+ ! (metadata.nil? or metadata.ftype.nil?)
end
# Provide, and retrieve if necessary, the metadata for this file. Fail