public static boolean correctKey( WatchKey key, Path file, WatchEvent.Kind<Path> kind ) { if( !key.isValid() ) { return false; } if( !childGetParent( file ).equals( key.watchable() ) ) { return false; } List<WatchEvent<?>> events = key.pollEvents(); return events.stream().filter( ev -> namedGetFilename( file ). equals( ev.context() ) && ev.kind().equals( kind ) ). findAny().isPresent(); }
@Override public long getLastVersion( String id ) { Path dir = childGetParent( getHost( id, 1L )); long max = 0; try ( DirectoryStream<Path> stream = Files.newDirectoryStream( dir )) { for ( Path kid : stream ) { max = Math.max( max, Long.parseLong( namedGetFilename( kid ).toString() )); } } catch( IOException e ) { return 0; } return max; }
@Test public void testGetFileNameIsIdempotent() throws Exception { Path fileName = namedGetFilename( relAB() ); assertThat( fileName.getFileName() ).isEqualTo( fileName ); }
public void newSymLink( EightyPath link, EightyPath existing, Principals principals ) { throwIfNotStd( link ); PathContent linkParentPC = content.getOrThrow( childGetParent( link ), () -> new IllegalArgumentException( "parent does not exist " + link ) ); linkParentPC.kids.add( link ); linkParentPC.attis.setLastAccessTime(); PathContent pc = PathContent.newSymLink( namedGetFilename( link ).toString(), existing, principals ); content.put( link, pc ); }
public static EightyPath toRealPathEx( EightyPath path, LinkOption... options ) { if( options.length == 0 ) { return toRealPath( path ); } // no follow links if( path.getParent() == null ) { return path; } if ( path.knownReal() ) { return path; } EightyPath parent = toRealPath( childGetParent( path )); return parent._resolve( namedGetFilename( path )); }
public void moveDir( EightyPath source, MemoryData targetData, EightyPath target ) { throwIfNotStd( source ); throwIfNotStd( target ); PathContent pcSrc = content.getOrThrow( source, () -> new IllegalArgumentException( "src does not exist " + source ) ); PathContent pcSrcParent = content.getOrThrow( childGetParent( source ), () -> new IllegalArgumentException( "srcs parent does not exist " + source ) ); PathContent pcTgtParent = targetData.content.getOrThrow( childGetParent( target ), () -> new IllegalArgumentException( "move: parent of target does not exist " + target ) ); List<EightyPath> kids = pcSrc.kids.copy(); targetData.content.put( target, pcSrc ); // // if( targetData.content.get( childGetParent( target ) ) == null ) { // Log.error( "internal data structure consistency problems (no parent) " + target ); // throw new IllegalStateException( "parent missing in internal structures " ); // } pcTgtParent.kids.add( target ); for( EightyPath kid : kids ) { EightyPath kidTarget = target._resolve( namedGetFilename( kid ) ); moveDir( source._resolve( kid ), targetData, kidTarget ); } content.remove( source ); pcSrcParent.kids.remove( source ); }