From 6c0ef220d25d7a569c38e53730377a2ff8eb92b7 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 15 Oct 2006 21:09:43 +0000 Subject: Safe-save tempfiles are now created in a botclass-local directory, because atomic renaming only works within a filesystem --- lib/rbot/ircbot.rb | 2 ++ lib/rbot/utils.rb | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index ac7aa829..8249895b 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -266,6 +266,8 @@ class IrcBot Dir.mkdir("#{botclass}/logs") unless File.exist?("#{botclass}/logs") Dir.mkdir("#{botclass}/registry") unless File.exist?("#{botclass}/registry") + Dir.mkdir("#{botclass}/safe_save") unless File.exist?("#{botclass}/safe_save") + Utils.set_safe_save_dir("#{botclass}/safe_save") @ping_timer = nil @pong_timer = nil diff --git a/lib/rbot/utils.rb b/lib/rbot/utils.rb index ae45e5d5..d1052390 100644 --- a/lib/rbot/utils.rb +++ b/lib/rbot/utils.rb @@ -320,9 +320,15 @@ module Irc end + @@safe_save_dir = nil + def Utils.set_safe_save_dir(str) + @@safe_save_dir = str.dup + end + def Utils.safe_save(file) + raise 'No safe save directory defined!' if @@safe_save_dir.nil? basename = File.basename(file) - temp = Tempfile.new(basename) + temp = Tempfile.new(basename,@@safe_save_dir) temp.binmode yield temp if block_given? temp.close -- cgit v1.2.3