diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-28 17:19:45 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-28 17:19:45 +0000 |
commit | 047e63f8481a95c32ceccc22673d4a08659ec9c8 (patch) | |
tree | 718db0c8deeac14385627f6a2b25ec055fd3ad03 /lib | |
parent | 94caa8a48f32ed1fd3aa38dc43e2add97026fcf2 (diff) | |
download | puppet-047e63f8481a95c32ceccc22673d4a08659ec9c8.tar.gz puppet-047e63f8481a95c32ceccc22673d4a08659ec9c8.tar.xz puppet-047e63f8481a95c32ceccc22673d4a08659ec9c8.zip |
Making file copying significantly faster -- i found an extra call to "describe" in file sources and an extra read/checksumming of the dest file
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1147 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/type/pfile.rb | 17 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/checksum.rb | 12 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/source.rb | 33 |
3 files changed, 43 insertions, 19 deletions
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 1ea3473d9..5343d8a50 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -661,6 +661,9 @@ module Puppet unless @states.include?(:checksum) self[:checksum] = "md5" end + + # We have to retrieve the source info before the recursion happens, + # although I'm not exactly clear on why. @states[:source].retrieve end @@ -677,10 +680,19 @@ module Puppet next if name == :source state.is = :absent } + return end - super + states().each { |state| + # We don't want to call 'describe()' twice, so only do a local + # retrieve on the source. + if state.name == :source + state.retrieve(false) + else + state.retrieve + end + } end # Set the checksum, from another state. There are multiple states that @@ -726,6 +738,9 @@ module Puppet def uri2obj(source) sourceobj = FileSource.new path = nil + unless source + devfail "Got a nil source" + end if source =~ /^\// source = "file://localhost/%s" % source sourceobj.mount = "localhost" diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb index 02e2e5761..d5de955e6 100755 --- a/lib/puppet/type/pfile/checksum.rb +++ b/lib/puppet/type/pfile/checksum.rb @@ -141,11 +141,7 @@ module Puppet case checktype when :md5 text = file.read - Puppet.info "Reading all of %s with %s" % - [@parent.name, checktype.inspect] when :md5lite - Puppet.info "Reading a small part of %s with %s" % - [@parent.name, checktype.inspect] text = file.read(512) end @@ -226,7 +222,13 @@ module Puppet # Even though they can specify multiple checksums, the insync? # mechanism can really only test against one, so we'll just retrieve # the first specified sum type. - def retrieve + def retrieve(usecache = false) + # When the 'source' is retrieving, it passes "true" here so + # that we aren't reading the file twice in quick succession, yo. + if usecache and @is + return @is + end + unless defined? @checktypes @checktypes = ["md5"] end diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/pfile/source.rb index 8d770890b..0e63485a9 100755 --- a/lib/puppet/type/pfile/source.rb +++ b/lib/puppet/type/pfile/source.rb @@ -1,7 +1,9 @@ +require 'puppet/server/fileserver' + module Puppet # Copy files from a local or remote source. Puppet.type(:file).newstate(:source) do - PINPARAMS = [:mode, :type, :owner, :group, :checksum] + PINPARAMS = Puppet::Server::FileServer::CHECKPARAMS attr_accessor :source, :local desc "Copy a file over the current file. Uses ``checksum`` to @@ -71,7 +73,7 @@ module Puppet # of the local states appropriately. If the remote file is a normal # file then we set it to copy; if it's a directory, then we just mark # that the local directory should be created. - def retrieve + def retrieve(remote = true) sum = nil unless defined? @shouldorig @@ -79,16 +81,21 @@ module Puppet @parent.name end - @source = nil - - # Find the first source that exists. @shouldorig contains - # the sources as specified by the user. - @shouldorig.each { |source| - if @stats = self.describe(source) - @source = source - break - end - } + @source = nil unless defined? @source + + # This is set to false by the File#retrieve function on the second + # retrieve, so that we do not do two describes. + if remote + @source = nil + # Find the first source that exists. @shouldorig contains + # the sources as specified by the user. + @shouldorig.each { |source| + if @stats = self.describe(source) + @source = source + break + end + } + end if @stats.nil? or @stats[:type].nil? @is = :notdescribed @@ -102,7 +109,7 @@ module Puppet if sum = @parent.state(:checksum) if sum.is if sum.is == :absent - sum.retrieve + sum.retrieve(true) end @is = sum.is else |