1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 06:15:02 -05:00
This commit is contained in:
Reinhard Pointner 2014-01-13 11:06:41 +00:00
parent db9dbeb0f4
commit c75b376140

View File

@ -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)));