From 971854528b77e4b0d8bc0a598efbf8af1001721f Mon Sep 17 00:00:00 2001 From: Jeremy Lingmann Date: Thu, 10 Mar 2011 22:00:41 -0800 Subject: [PATCH] Revert "Don't anchor the regexp to EOL to fix matching issues that were causing the entire block of crontab entries to appear twice in the crontab. This could be due to the way cron is adding newlines or some other post-processing that occurs on the cron. This bug was reproduced in the following environment: Ubuntu 10.04.2 LTS, rvm 1.0.14, ruby 1.8.7 patchlevel 253, capistrano 2.5.19, capistrano-ext 1.2.1, bundler 1.0.10" This reverts commit 1f11510d8735bb4201730c7f71b580a4b04a6ba8. --- lib/whenever/command_line.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/whenever/command_line.rb b/lib/whenever/command_line.rb index 74c8a3a..14c0592 100644 --- a/lib/whenever/command_line.rb +++ b/lib/whenever/command_line.rb @@ -89,19 +89,19 @@ module Whenever def updated_crontab # Check for unopened or unclosed identifier blocks - if read_crontab =~ Regexp.new("^#{comment_open}") && (read_crontab =~ Regexp.new("^#{comment_close}")).nil? + if read_crontab =~ Regexp.new("^#{comment_open}$") && (read_crontab =~ Regexp.new("^#{comment_close}")).nil? warn "[fail] Unclosed indentifier; Your crontab file contains '#{comment_open}', but no '#{comment_close}'" exit(1) - elsif (read_crontab =~ Regexp.new("^#{comment_open}")).nil? && read_crontab =~ Regexp.new("^#{comment_close}") + elsif (read_crontab =~ Regexp.new("^#{comment_open}$")).nil? && read_crontab =~ Regexp.new("^#{comment_close}") warn "[fail] Unopened indentifier; Your crontab file contains '#{comment_close}', but no '#{comment_open}'" exit(1) end # If an existing identier block is found, replace it with the new cron entries - if read_crontab =~ Regexp.new("^#{comment_open}") && read_crontab =~ Regexp.new("^#{comment_close}") + if read_crontab =~ Regexp.new("^#{comment_open}$") && read_crontab =~ Regexp.new("^#{comment_close}$") # If the existing crontab file contains backslashes they get lost going through gsub. # .gsub('\\', '\\\\\\') preserves them. Go figure. - read_crontab.gsub(Regexp.new("^#{comment_open}.+^#{comment_close}", Regexp::MULTILINE), whenever_cron.chomp.gsub('\\', '\\\\\\')) + read_crontab.gsub(Regexp.new("^#{comment_open}$.+^#{comment_close}$", Regexp::MULTILINE), whenever_cron.chomp.gsub('\\', '\\\\\\')) else # Otherwise, append the new cron entries after any existing ones [read_crontab, whenever_cron].join("\n\n") end.gsub(/\n{3,}/, "\n\n") # More than two newlines becomes just two.