summaryrefslogtreecommitdiff
path: root/lib/rbot/config.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-08-31 20:39:19 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-08-31 20:39:19 +0000
commit70b4d72c18d092bf14c982a28e860321f947755c (patch)
treef7427015f8b55c3fbd28d4a3be7f388bf5d7b0f8 /lib/rbot/config.rb
parentbf85fc8d462037b072af0616d8a26d267614a205 (diff)
a little more robustness around emtpy lookups
Also more robustness around reading/writing conf.yaml
Diffstat (limited to 'lib/rbot/config.rb')
-rw-r--r--lib/rbot/config.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index 36160875..7475d617 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -311,20 +311,30 @@ module Irc
:defaults => {:topic => false}
if(File.exist?("#{@@bot.botclass}/conf.yaml"))
- newconfig = YAML::load_file("#{@@bot.botclass}/conf.yaml")
- @@config.update newconfig
- else
- # first-run wizard!
- BotConfigWizard.new(@@bot).run
- # save newly created config
- save
+ begin
+ newconfig = YAML::load_file("#{@@bot.botclass}/conf.yaml")
+ @@config.update newconfig
+ return
+ rescue
+ $stderr.puts "failed to read conf.yaml: #{$!}"
+ end
end
+ # if we got here, we need to run the first-run wizard
+ BotConfigWizard.new(@@bot).run
+ # save newly created config
+ save
end
# write current configuration to #{botclass}/conf.rbot
def save
- File.open("#{@@bot.botclass}/conf.yaml", "w") do |file|
- file.puts @@config.to_yaml
+ begin
+ File.open("#{@@bot.botclass}/conf.yaml.new", "w") do |file|
+ file.puts @@config.to_yaml
+ end
+ File.rename("#{@@bot.botclass}/conf.yaml.new",
+ "#{@@bot.botclass}/conf.yaml")
+ rescue
+ $stderr.puts "failed to write configuration file conf.yaml! #{$!}"
end
end