summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-08-06 14:52:16 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-08-13 08:07:23 +1000
commit63cb1ade80187ebc6f7f24c74e4d1e4db53422c1 (patch)
tree7c2a53d59be84d9aa9c4466d61edc23589cc4b25 /lib/puppet
parentc129f2a15fdccc12baa3d929531221cbade7ff10 (diff)
downloadpuppet-63cb1ade80187ebc6f7f24c74e4d1e4db53422c1.tar.gz
puppet-63cb1ade80187ebc6f7f24c74e4d1e4db53422c1.tar.xz
puppet-63cb1ade80187ebc6f7f24c74e4d1e4db53422c1.zip
Fixes #2503
Added a random suffex to the temporary file name and verify that the name is not in use (retry on collison). No additional tests added as the lifetime of the temporary file is bound by the routine, making spec driven tests impraticable. Includes logic to account for dead-end symlinks as well, as per Luke. Signed-off-by: Markus Roberts <Markus@reality.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/type/file.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 0fc2c9626..f62af871e 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -722,8 +722,14 @@ module Puppet
remove_existing(:file)
use_temporary_file = (content.length != 0)
- path = self[:path]
- path += ".puppettmp" if use_temporary_file
+ if use_temporary_file
+ path = "#{self[:path]}.puppettmp_#{rand(10000)}"
+ while File.exists?(path) or File.symlink?(path)
+ path = "#{self[:path]}.puppettmp_#{rand(10000)}"
+ end
+ else
+ path = self[:path]
+ end
mode = self.should(:mode) # might be nil
umask = mode ? 000 : 022