summaryrefslogtreecommitdiff
path: root/lib/feed2imap/feed2imap.rb
diff options
context:
space:
mode:
authorlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2006-01-02 23:42:41 +0000
committerlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2006-01-02 23:42:41 +0000
commite6e6069f5375631c28dbb41077d42e350135d995 (patch)
tree86a906d5fe0bc76afb04dac9507acbbba0f3e69d /lib/feed2imap/feed2imap.rb
parente65b54892d6af97b78244929ffebe69d50a90868 (diff)
downloadfeed2imap-e6e6069f5375631c28dbb41077d42e350135d995.tar.gz
feed2imap-e6e6069f5375631c28dbb41077d42e350135d995.tar.bz2
feed2imap-e6e6069f5375631c28dbb41077d42e350135d995.zip
lockfile now works
git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@76 f70e237a-67f3-0310-a06c-d2b8a7116972
Diffstat (limited to 'lib/feed2imap/feed2imap.rb')
-rw-r--r--lib/feed2imap/feed2imap.rb12
1 files changed, 8 insertions, 4 deletions
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