From c75b37614057247cccf6db914e214d421ce098c1 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 13 Jan 2014 11:06:41 +0000 Subject: [PATCH] * fixfix --- source/net/sourceforge/filebot/Main.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/net/sourceforge/filebot/Main.java b/source/net/sourceforge/filebot/Main.java index 17a91aa8..a5f87dde 100644 --- a/source/net/sourceforge/filebot/Main.java +++ b/source/net/sourceforge/filebot/Main.java @@ -461,9 +461,12 @@ public class Main { } final File lockFile = new File(cache, ".lock"); + boolean isNewCache = !lockFile.exists(); + final RandomAccessFile handle = new RandomAccessFile(lockFile, "rw"); final FileChannel channel = handle.getChannel(); final FileLock lock = channel.tryLock(); + if (lock != null) { // setup cache dir for ehcache System.setProperty("ehcache.disk.store.dir", cache.getAbsolutePath()); @@ -476,16 +479,21 @@ public class Main { // ignore } - if (cacheRevision != applicationRevision && applicationRevision > 0) { + if (cacheRevision != applicationRevision && applicationRevision > 0 && !isNewCache) { Logger.getLogger(Main.class.getName()).log(Level.WARNING, String.format("App version (r%d) does not match cache version (r%d): reset cache", applicationRevision, cacheRevision)); + // tag cache with new revision number + isNewCache = true; + // delete all files related to previous cache instances for (File it : cache.listFiles()) { if (!it.equals(lockFile)) { delete(cache); } } + } + if (isNewCache) { // set new cache revision channel.position(0); channel.write(Charset.forName("UTF-8").encode(String.valueOf(applicationRevision)));