diff options
author | lnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972> | 2006-01-02 23:42:41 +0000 |
---|---|---|
committer | lnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972> | 2006-01-02 23:42:41 +0000 |
commit | e6e6069f5375631c28dbb41077d42e350135d995 (patch) | |
tree | 86a906d5fe0bc76afb04dac9507acbbba0f3e69d | |
parent | e65b54892d6af97b78244929ffebe69d50a90868 (diff) | |
download | feed2imap-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 '')
-rw-r--r-- | lib/feed2imap/feed2imap.rb | 12 |
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 |