From e6e6069f5375631c28dbb41077d42e350135d995 Mon Sep 17 00:00:00 2001 From: lnu Date: Mon, 2 Jan 2006 23:42:41 +0000 Subject: lockfile now works git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@76 f70e237a-67f3-0310-a06c-d2b8a7116972 --- lib/feed2imap/feed2imap.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/feed2imap/feed2imap.rb') diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb index 77bd48e..e8e45a0 100644 --- a/lib/feed2imap/feed2imap.rb +++ b/lib/feed2imap/feed2imap.rb @@ -62,14 +62,18 @@ class Feed2Imap # init cache @logger.info('Initializing cache') @cache = ItemCache::new + if not File::exist?(@config.cache + '.lock') + f = File::new(@config.cache + '.lock', 'w') + f.close + end + if File::new(@config.cache + '.lock').flock(File::LOCK_EX | File::LOCK_NB) == false + @logger.fatal("Another instance of feed2imap is already locking the cache file") + exit(1) + end if not File::exist?(@config.cache) @logger.warn("Cache file #{@config.cache} not found, using a new one") else File::open(@config.cache) do |f| - if not f.flock(File::LOCK_UN) - @logger.fatal("Another instance of feed2imap is already locking the cache file") - exit(1) - end @cache.load(f) end end -- cgit v1.2.3-54-g00ecf