From 0d7772ca24e6683f3e2c43f6d5dae709d6d7b16b Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 18 Jul 2006 14:44:17 +0000 Subject: Improve robustness while saving auth config files and channel quotes --- lib/rbot/auth.rb | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'lib/rbot/auth.rb') diff --git a/lib/rbot/auth.rb b/lib/rbot/auth.rb index 3fbf4b69..04e1e98b 100644 --- a/lib/rbot/auth.rb +++ b/lib/rbot/auth.rb @@ -60,13 +60,33 @@ module Irc # users are written to #{botclass}/users.yaml def save Dir.mkdir("#{@bot.botclass}") if(!File.exist?("#{@bot.botclass}")) - File.open("#{@bot.botclass}/users.yaml", 'w') do |file| - file.puts @users.to_yaml + begin + debug "Writing new users.yaml ..." + File.open("#{@bot.botclass}/users.yaml.new", 'w') do |file| + file.puts @users.to_yaml + end + debug "Officializing users.yaml ..." + File.rename("#{@bot.botclass}/users.yaml.new", + "#{@bot.botclass}/users.yaml") + rescue + $stderr.puts "failed to write configuration file users.yaml! #{$!}" + debug "#{e.class}: #{e}" + debug e.backtrace.join("\n") end - File.open("#{@bot.botclass}/levels.rbot", 'w') do |file| - @levels.each do |key, value| - file.puts "#{value} #{key}" + begin + debug "Writing new levels.rbot ..." + File.open("#{@bot.botclass}/levels.rbot.new", 'w') do |file| + @levels.each do |key, value| + file.puts "#{value} #{key}" + end end + debug "Officializing levels.rbot ..." + File.rename("#{@bot.botclass}/levels.rbot.new", + "#{@bot.botclass}/levels.rbot") + rescue + $stderr.puts "failed to write configuration file levels.rbot! #{$!}" + debug "#{e.class}: #{e}" + debug e.backtrace.join("\n") end end -- cgit v1.2.3