lib/chef/provider/cron.rb in chef-0.7.16 vs lib/chef/provider/cron.rb in chef-0.8.2
- old
+ new
@@ -23,10 +23,12 @@
class Chef
class Provider
class Cron < Chef::Provider
include Chef::Mixin::Command
+ CRON_PATTERN = /([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*(.*)/
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
super(node, new_resource, collection, definitions, cookbook_loader)
@cron_exists = false
@cron_empty = false
end
@@ -60,11 +62,11 @@
@current_resource.shell($1) if cron_found
next
when /^HOME=(\S*)/
@current_resource.home($1) if cron_found
next
- when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
+ when CRON_PATTERN
if cron_found
@current_resource.minute($1)
@current_resource.hour($2)
@current_resource.day($3)
@current_resource.month($4)
@@ -112,11 +114,11 @@
stdout.each_line do |line|
case line
when /^# Chef Name: #{@new_resource.name}\n/
cron_found = true
next
- when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
+ when CRON_PATTERN
if cron_found
cron_found = false
crontab << newcron
next
end
@@ -127,11 +129,10 @@
end
end
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
crontab.each { |line| stdin.puts "#{line}" }
- stdin.close rescue nil
end
Chef::Log.info("Updated cron '#{@new_resource.name}'")
@new_resource.updated = true
else
unless @cron_empty
@@ -142,11 +143,10 @@
crontab << newcron
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
crontab.each { |line| stdin.puts "#{line}" }
- stdin.close rescue nil
end
Chef::Log.info("Added cron '#{@new_resource.name}'")
@new_resource.updated = true
end
end
@@ -159,11 +159,11 @@
stdout.each_line do |line|
case line
when /^# Chef Name: #{@new_resource.name}\n/
cron_found = true
next
- when /([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*([0-9\*]+)\s*(.*)/
+ when CRON_PATTERN
if cron_found
cron_found = false
next
end
else
@@ -173,10 +173,9 @@
end
end
status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
crontab.each { |line| stdin.puts "#{line}" }
- stdin.close rescue nil
end
Chef::Log.debug("Deleted cron '#{@new_resource.name}'")
@new_resource.updated = true
end
end