Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #251 from cap10morgan/fix-tempfile

fix file not found error when running under JRuby
  • Loading branch information...
commit f9e62e964a9468aa0b5e5d3f4e972cff08ac90d7 2 parents 9c0098d + 99615aa
@javan authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 lib/whenever/command_line.rb
View
11 lib/whenever/command_line.rb
@@ -66,22 +66,23 @@ def read_crontab
end
def write_crontab(contents)
- tmp_cron_file = Tempfile.new('whenever_tmp_cron').path
- File.open(tmp_cron_file, File::WRONLY | File::APPEND) do |file|
- file << contents
- end
+ tmp_cron_file = Tempfile.open('whenever_tmp_cron')
+ tmp_cron_file << contents
+ tmp_cron_file.fsync
command = ['crontab']
command << "-u #{@options[:user]}" if @options[:user]
- command << tmp_cron_file
+ command << tmp_cron_file.path
if system(command.join(' '))
action = 'written' if @options[:write]
action = 'updated' if @options[:update]
puts "[write] crontab file #{action}"
+ tmp_cron_file.close!
exit(0)
else
warn "[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid."
+ tmp_cron_file.close!
exit(1)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.