@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + ctime + ", (lock=" + this + ")"); } }
@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // check we are still in the locks map (some debugger or something crazy didn't remove us) if (!LOCK_HELD.contains(path.toString())) { throw new AlreadyClosedException("Lock path unexpectedly cleared from map: " + this); } // check our lock wasn't invalidated. if (!lock.isValid()) { throw new AlreadyClosedException("FileLock invalidated by an external force: " + this); } // try to validate the underlying file descriptor. // this will throw IOException if something is wrong. long size = channel.size(); if (size != 0) { throw new AlreadyClosedException("Unexpected lock file size: " + size + ", (lock=" + this + ")"); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + ctime + ", (lock=" + this + ")"); } }
private boolean refreshNeeded() throws IOException { return !Files.getLastModifiedTime(file).equals(lastModifiedHolder.get()); }
public boolean check() throws IOException { if (checked && size == Files.size(file) && this.mtime.equals(Files.getLastModifiedTime(file))) { return true; } this.checked = true; this.size = Files.size(file); this.mtime = Files.getLastModifiedTime(file); return false; } }
private boolean modificationTimeChanged(Path monitoredFile) { try { FileTime current = getLastModifiedTime(monitoredFile); FileTime previous = lastChangedTime.getAndSet(current); boolean changed = !previous.equals(current); LOGGER.debug("modificationTimeChange probe. Changed={}", changed); return changed; } catch (IOException e) { String message = format("Cannot get modification time for Path=%s", monitoredFile); throw new RuntimeException(message, e); } }
private boolean probe() { try { FileTime nowLastModified = Files.getLastModifiedTime(file); FileTime previousLastModified = lastModifiedHolder.getAndSet(nowLastModified); return !nowLastModified.equals(previousLastModified); } catch (Exception e) { throw uncheck(e); } }
private boolean haveChanges(String projectPath, List<String> paths) { boolean statusChanged = false; for (String path : paths) { String filePath = resolve(projectPath, path); FileTime fileTime = projectFiles.get(filePath); try { FileTime currentFileTime = getLastModifiedTime(Paths.get(filePath)); if (fileTime == null || !fileTime.equals(currentFileTime)) { projectFiles.put(filePath, currentFileTime); statusChanged = true; } } catch (IOException exception) { if (exception instanceof NoSuchFileException) { statusChanged = projectFiles.remove(filePath) != null; } else { LOG.error(exception.getMessage()); } } } return statusChanged; }
private void refresh() throws Exception { lock.lock(); try { FileTime lastModifiedTime = Files.getLastModifiedTime(file); String content = Paths2.readText(file, StandardCharsets.UTF_8); if (lastModifiedTime.equals(lastModifiedHolder.get()) && content.equals(contentHolder.get())) { return; } T previous = delegateHolder.getAndSet(null); if (previous != null) { releaser.release(previous); } delegateHolder.set(producer.produce(file, content)); this.lastModifiedHolder.set(lastModifiedTime); this.contentHolder.set(content); } finally { lock.unlock(); } }
@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + creationTime + ", (lock=" + this + ")"); } }
@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + creationTime + ", (lock=" + this + ")"); } }
@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + ctime + ", (lock=" + this + ")"); } }
public boolean equals(Object obj) { if (obj instanceof Key) { Key key = (Key)obj; if (!attrs.lastModifiedTime().equals(key.attrs.lastModifiedTime())) { return false; } Object fk = attrs.fileKey(); if (fk != null) { return fk.equals(key.attrs.fileKey()); } else { return file.equals(key.file); } } return false; } }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof FileInfo) { FileInfo that = (FileInfo) o; return ((this.key == null) ? (that.key() == null) : this.key.equals(that.key())) && (this.size == that.size()) && ((this.modificationTime == null) ? (that.modificationTime() == null) : this.modificationTime.equals(that.modificationTime())) && (this.path.equals(that.path())); } return false; }
@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // check we are still in the locks map (some debugger or something crazy didn't remove us) if (!LOCK_HELD.contains(path.toString())) { throw new AlreadyClosedException("Lock path unexpectedly cleared from map: " + this); } // check our lock wasn't invalidated. if (!lock.isValid()) { throw new AlreadyClosedException("FileLock invalidated by an external force: " + this); } // try to validate the underlying file descriptor. // this will throw IOException if something is wrong. long size = channel.size(); if (size != 0) { throw new AlreadyClosedException("Unexpected lock file size: " + size + ", (lock=" + this + ")"); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + ctime + ", (lock=" + this + ")"); } }
@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // check we are still in the locks map (some debugger or something crazy didn't remove us) if (!LOCK_HELD.contains(path.toString())) { throw new AlreadyClosedException("Lock path unexpectedly cleared from map: " + this); } // check our lock wasn't invalidated. if (!lock.isValid()) { throw new AlreadyClosedException("FileLock invalidated by an external force: " + this); } // try to validate the underlying file descriptor. // this will throw IOException if something is wrong. long size = channel.size(); if (size != 0) { throw new AlreadyClosedException("Unexpected lock file size: " + size + ", (lock=" + this + ")"); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + creationTime + ", (lock=" + this + ")"); } }
@Override public void ensureValid() throws IOException { if (closed) { throw new AlreadyClosedException("Lock instance already released: " + this); } // check we are still in the locks map (some debugger or something crazy didn't remove us) if (!LOCK_HELD.contains(path.toString())) { throw new AlreadyClosedException("Lock path unexpectedly cleared from map: " + this); } // check our lock wasn't invalidated. if (!lock.isValid()) { throw new AlreadyClosedException("FileLock invalidated by an external force: " + this); } // try to validate the underlying file descriptor. // this will throw IOException if something is wrong. long size = channel.size(); if (size != 0) { throw new AlreadyClosedException("Unexpected lock file size: " + size + ", (lock=" + this + ")"); } // try to validate the backing file name, that it still exists, // and has the same creation time as when we obtained the lock. // if it differs, someone deleted our lock file (and we are ineffective) FileTime ctime = Files.readAttributes(path, BasicFileAttributes.class).creationTime(); if (!creationTime.equals(ctime)) { throw new AlreadyClosedException("Underlying file changed by an external force at " + creationTime + ", (lock=" + this + ")"); } }
public static boolean equals(BasicFileAttributes a, BasicFileAttributes b) { if(a == b) return true; if(a == null || b == null) return false; if(!a.creationTime().equals(b.creationTime())) return false; if(!Objects.equals(a.fileKey(), b.fileKey())) return false; if(a.isDirectory() != b.isDirectory()) return false; if(a.isOther() != b.isOther()) return false; if(a.isRegularFile() != b.isRegularFile()) return false; if(a.isSymbolicLink() != b.isSymbolicLink()) return false; if(!a.lastAccessTime().equals(b.lastAccessTime())) return false; if(!a.lastModifiedTime().equals(b.lastModifiedTime())) return false; if(a.size() != b.size()) return false; return true; }
public static boolean equalsIgnoreLastAccessTime(BasicFileAttributes a, BasicFileAttributes b) { if(a == b) return true; if(a == null || b == null) return false; if(!a.creationTime().equals(b.creationTime())) return false; if(!Objects.equals(a.fileKey(), b.fileKey())) return false; if(a.isDirectory() != b.isDirectory()) return false; if(a.isOther() != b.isOther()) return false; if(a.isRegularFile() != b.isRegularFile()) return false; if(a.isSymbolicLink() != b.isSymbolicLink()) return false; if(!a.lastModifiedTime().equals(b.lastModifiedTime())) return false; if(a.size() != b.size()) return false; return true; }
void setTimes( UnixSshPath path, FileTime lastModifiedTime, FileTime lastAccessTime ) throws IOException { if ( lastModifiedTime != null && lastModifiedTime.equals( lastAccessTime ) ) { String command = path.getFileSystem().getCommand( "touch" ) + " -t " + toTouchTime( lastModifiedTime ) + " " + path.toAbsolutePath().quotedString(); executeForStdout( path, command ); return; } if ( lastModifiedTime != null ) { String command = path.getFileSystem().getCommand( "touch" ) + " -m -t " + toTouchTime( lastModifiedTime ) + " " + path.toAbsolutePath().quotedString(); executeForStdout( path, command ); } if ( lastAccessTime != null ) { String command = path.getFileSystem().getCommand( "touch" ) + " -a -t " + toTouchTime( lastModifiedTime ) + " " + path.toAbsolutePath().quotedString(); executeForStdout( path, command ); } }