summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-27 21:10:52 -0600
committerLuke Kanies <luke@madstop.com>2007-11-27 21:10:52 -0600
commit1e6ba6f9ff74bc1204c59457911621a3ad12e8ae (patch)
tree918fbd57923e17d1e6b17ca86b786b5beee90d34
parent5d30ea93ad23d10564a765337b26d137d6643101 (diff)
downloadpuppet-1e6ba6f9ff74bc1204c59457911621a3ad12e8ae.tar.gz
puppet-1e6ba6f9ff74bc1204c59457911621a3ad12e8ae.tar.xz
puppet-1e6ba6f9ff74bc1204c59457911621a3ad12e8ae.zip
Fixing #781, from what I can tell. I'm leaving it with
no tests for now, since it's a very small chunk of code and it's *insanely* difficult to test this kind problem.
-rwxr-xr-xlib/puppet/util/filetype.rb40
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index 2f1dabe62..81d93a924 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -198,26 +198,44 @@ class Puppet::Util::FileType
newfiletype(:suntab) do
# Read a specific @path's cron tab.
def read
- Puppet::Util::SUIDManager.asuser(@path) {
- %x{crontab -l 2>/dev/null}
- }
+ begin
+ output = Puppet::Util.execute(%w{crontab -l}, :uid => @path)
+ return "" if output.include?("can't open your crontab")
+ return output
+ rescue
+ # If there's a failure, treat it like an empty file.
+ return ""
+ end
end
# Remove a specific @path's cron tab.
def remove
- Puppet::Util::SUIDManager.asuser(@path) {
- %x{crontab -r 2>/dev/null}
- }
+ begin
+ Puppet::Util.execute(%w{crontab -r}, :uid => @path)
+ rescue => detail
+ raise Puppet::Error, "Could not remove crontab for %s: %s" % [@path, detail]
+ end
end
# Overwrite a specific @path's cron tab; must be passed the @path name
# and the text with which to create the cron tab.
def write(text)
- Puppet::Util::SUIDManager.asuser(@path) {
- IO.popen("crontab", "w") { |p|
- p.print text
- }
- }
+ puts text
+ require "tempfile"
+ output_file = Tempfile.new("puppet")
+ fh = output_file.open
+ fh.print text
+ fh.close
+
+ # We have to chown the stupid file to the user.
+ File.chown(Puppet::Util.uid(@path), nil, output_file.path)
+
+ begin
+ Puppet::Util.execute(["crontab", output_file.path], :uid => @path)
+ rescue => detail
+ raise Puppet::Error, "Could not write crontab for %s: %s" % [@path, detail]
+ end
+ output_file.delete
end
end