Skip to content

Commit

Permalink
Compare last modified time in ms.
Browse files Browse the repository at this point in the history
Fixes #574

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 16, 2019
1 parent f8a2c15 commit 3e9d047
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,39 @@ public class FilesChangedTracker {
private static class FileChangedTracker {

private final Path file;
private FileTime lastModified;
private Long lastModified;

public FileChangedTracker(Path file) {
this.file = file;
if (Files.exists(file)) {
try {
lastModified = Files.getLastModifiedTime(file);
lastModified = Files.getLastModifiedTime(file).toMillis();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Get last modified time failed", e);
}
}
}

public boolean isDirty() {
Long old = lastModified;
long currentLastModified = 0;
try {
if (!Files.exists(file)) {
// This case occurs when user delete the XML Schema / DTD file
System.err.println("FILE [" + file.toString() + "] IS DELETED!!!");
return true;
}
FileTime currentLastMofied = Files.getLastModifiedTime(file);
if (!currentLastMofied.equals(lastModified)) {
lastModified = currentLastMofied;
currentLastModified = Files.getLastModifiedTime(file).toMillis();
if (lastModified == null || lastModified != currentLastModified) {
lastModified = currentLastModified;
System.err.println("IS DIRTY! [" + file.toString() + "] lastModified=" + old + ", currentLastModified=" + currentLastModified);
return true;
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Get last modified time failed", e);
return true;
}
System.err.println("NO DIRTY! [" + file.toString() + "] lastModified=" + old + ", currentLastModified=" + currentLastModified);
return false;
}

Expand Down

0 comments on commit 3e9d047

Please sign in to comment.