From: jprocter Date: Thu, 20 Oct 2005 10:00:35 +0000 (+0000) Subject: added better check for file change (length + last modified) X-Git-Tag: Release_0.2~452 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=547bc989d39632cfdc52663462402a093aee1a32;p=vamsas.git added better check for file change (length + last modified) git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@68 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/simpleclient/FileWatcher.java b/src/org/vamsas/client/simpleclient/FileWatcher.java index ce218ee..807473f 100644 --- a/src/org/vamsas/client/simpleclient/FileWatcher.java +++ b/src/org/vamsas/client/simpleclient/FileWatcher.java @@ -15,7 +15,7 @@ public class FileWatcher { private File subject = null; - private long lastStat; + private long lastStat[]; boolean exists = false; @@ -28,7 +28,7 @@ public class FileWatcher { * @param subject */ private boolean checkLock() { - if (subject!=null) { + if (subject!=null && subject.exists()) { Lock tl = new Lock(subject); if (tl.isLocked()) { tl.release(); @@ -39,6 +39,14 @@ public class FileWatcher { } return false; } + private long[] getStat(File subject) { + return new long[] { subject.lastModified(), subject.length() }; + } + private boolean compStat(long[] stat, long[] newstat) { + if (stat.hashCode()!=newstat.hashCode()) + return false; + return true; + } private boolean check() { if (subject != null) { if (!subject.exists()) { @@ -49,8 +57,8 @@ public class FileWatcher { return false; } else { - long newStat = subject.lastModified(); - if (exists && ((lastStat == newStat) || checkLock())) { + long[] newStat = getStat(subject); // subject.lastModified(); + if (exists && ((compStat(lastStat, newStat) || checkLock()))) { return false; } lastStat = newStat;