From 06943ba66c9cb1426814f7be199f185605330a25 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 24 Jun 2008 12:08:40 +0200 Subject: [PATCH] ircbot.rb: copy missing template files on startup --- lib/rbot/ircbot.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 932cc3b7..a8b5543e 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -417,7 +417,19 @@ class Bot botclass = File.expand_path(botclass) @botclass = botclass.gsub(/\/$/, "") - unless FileTest.directory? botclass + if FileTest.directory? botclass + # compare the templates dir with the current botclass, and fill it in with + # any missing file. + # Sadly, FileUtils.cp_r doesn't have an :update option, so we have to do it + # manually + template = File.join Config::datadir, 'templates' + # note that we use the */** pattern because we don't want to match + # keywords.rbot, which gets deleted on load and would therefore be missing always + missing = Dir.chdir(template) { Dir.glob('*/**') } - Dir.chdir(botclass) { Dir.glob('*/**') } + missing.map do |f| + FileUtils.cp File.join(template, f), File.join(botclass, f) + end + else log "no #{botclass} directory found, creating from templates.." if FileTest.exist? botclass error "file #{botclass} exists but isn't a directory" -- 2.39.2