diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-18 14:44:17 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-18 14:44:17 +0000 |
commit | 0d7772ca24e6683f3e2c43f6d5dae709d6d7b16b (patch) | |
tree | 1cc95fc155938e31417aad84e92251c43c009992 /lib/rbot/auth.rb | |
parent | b756b6655d94e3aedecb25c54ca27ab64f68b7f6 (diff) |
Improve robustness while saving auth config files and channel quotes
Diffstat (limited to 'lib/rbot/auth.rb')
-rw-r--r-- | lib/rbot/auth.rb | 30 |
1 files changed, 25 insertions, 5 deletions
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 |