summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/auth.rb30
-rw-r--r--lib/rbot/config.rb6
2 files changed, 30 insertions, 6 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
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index 027b9902..c974c78f 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -328,13 +328,17 @@ module Irc
# write current configuration to #{botclass}/conf.rbot
def save
begin
+ debug "Writing new conf.yaml ..."
File.open("#{@@bot.botclass}/conf.yaml.new", "w") do |file|
file.puts @@config.to_yaml
end
+ debug "Officializing conf.yaml ..."
File.rename("#{@@bot.botclass}/conf.yaml.new",
"#{@@bot.botclass}/conf.yaml")
- rescue
+ rescue => e
$stderr.puts "failed to write configuration file conf.yaml! #{$!}"
+ debug "#{e.class}: #{e}"
+ debug e.backtrace.join("\n")
end
end