diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-06-24 12:08:40 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2008-06-24 12:29:59 +0200 |
commit | 06943ba66c9cb1426814f7be199f185605330a25 (patch) | |
tree | 1223e9fa16dba1399d14eda35651f030818e8767 /lib/rbot | |
parent | 9487a04ec88c8c55e8097664dcc74e79e87162d6 (diff) |
ircbot.rb: copy missing template files on startup
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/ircbot.rb | 14 |
1 files changed, 13 insertions, 1 deletions
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" |