def load_current_resource
crontab_lines = []
@current_resource = Chef::Resource::Cron.new(@new_resource.name)
@current_resource.user(@new_resource.user)
if crontab = read_crontab
cron_found = false
crontab.each_line do |line|
case line.chomp
when "# Chef Name: #{@new_resource.name}"
Chef::Log.debug("Found cron '#{@new_resource.name}'")
cron_found = true
@cron_exists = true
next
when ENV_PATTERN
set_environment_var($1, $2) if cron_found
next
when CRON_PATTERN
if cron_found
@current_resource.minute($1)
@current_resource.hour($2)
@current_resource.day($3)
@current_resource.month($4)
@current_resource.weekday($5)
@current_resource.command($6)
cron_found=false
end
next
else
cron_found=false
next
end
end
Chef::Log.debug("Cron '#{@new_resource.name}' not found") unless @cron_exists
else
Chef::Log.debug("Cron empty for '#{@new_resource.user}'")
@cron_empty = true
end
@current_resource
end