public Path unnormalize( Path path ) { Path parent = childGetParent( path ); return parent.resolve( ".." ).resolve( parent.getFileName() ).resolve( "." ).resolve( path.getFileName() ); }
@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; }
public Path defaultRoot() { return absoluteGetRoot( FS.getPath( "" ).toAbsolutePath() ); }
@Test public void testGetFileNameIsIdempotent() throws Exception { Path fileName = namedGetFilename( relAB() ); assertThat( fileName.getFileName() ).isEqualTo( fileName ); }
private void normalizeParentCase( RealIt it ) { if( !isRoot( it.path ) ) { it.path = childGetParent( it.path ); } } }
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(); }
public static URI toURIWithRoot( FileSystem fs ) { return absoluteGetRoot( fs.getPath( "" ).toAbsolutePath() ).toUri(); }
public static Path createFile( Path root, byte[] content, String one, String... names ) { Path ret = root.resolve( one ); for( String name : names ) { ret = ret.resolve( name ); } Filess.createDirectories( childGetParent( ret)); Filess.write( ret, content ); return ret; }
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 ReadonlyPlayground<T> set( Path root ) { descr.removeTopic( Writable.class ); descr.props.put( "playground", root ); if( !root.isAbsolute() ) { throw new IllegalArgumentException( "readonly root must be absolute " + root ); } if( !absoluteGetRoot( root ).equals( absoluteGetRoot( root.getFileSystem().getPath( "" ).toAbsolutePath() ) ) ) { descr.removeTopic( WorkingDirectoryInPlaygroundTree.class ); } return this; }
public FSElsewhere( Path root, UUID uuid ) { if ( !root.isAbsolute()) { throw new IllegalArgumentException( "fselwhere root must be absolute " + root ); } if ( !isRoot( root ) && Files.exists( childGetParent( root))) { Filess.createDirectories( root ); } this.root = root; this.uuid = uuid; }
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 URI toURIWithoutPath( FileSystem fs ) { Path root = absoluteGetRoot( fs.getPath( "" ).toAbsolutePath() ); return URI.create( Strings.withoutSuffix( root.toUri().toString(), root.toString().replace( '\\', '/' ) ) ); }
@Test public void testNonExistingAbsolutePathIsNotADirectoryEvenIfParent() throws IOException { assertThat( Files.isDirectory( childGetParent( getNonExistingPath().resolve( "child" ) ) ) ).isFalse(); }
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 ); }
public Path otherFSAbsA() throws IOException { FileSystem fs = description.get( Path.class, SecondFS.PLAYGROUND2 ).getFileSystem(); return PathIKWID.absoluteGetRoot( fs.getPath( "" ).toAbsolutePath()).resolve( nameA() ); } public Path otherFSAbsAB() throws IOException {
@Test @Category( { Writable.class, Move.class } ) public void testRenamingAFileRemovesNameFromParentsDirStream() throws IOException { Path file = srcFile(); Files.move( file, childGetParent( file ).resolve( "tgt" ) ); assertThat( isKid( childGetParent( file ), file ) ).isFalse(); }
public T set( Path root ) { descr.removeTopic( Readonly.class ); descr.props.put( "playground", root ); if( !root.isAbsolute() ) { throw new IllegalArgumentException( "root path must be nonull and absolute " + root ); } if( !absoluteGetRoot( root ).equals( absoluteGetRoot( root.getFileSystem().getPath( "" ).toAbsolutePath() ))) { descr.removeTopic( WorkingDirectoryInPlaygroundTree.class ); } if( root.getFileSystem().equals( FileSystems.getDefault() ) ) { descr.removeTopic( NotDefaultFileSystem.class ); } return t; }
@Test @Category( { Writable.class, Delete.class } ) public void testDeleteEmptiedDir() throws IOException { Path file = fileTAB(); Files.delete( file ); Files.delete( childGetParent( file )); assertThat( childGetParent( file )).doesNotExist(); }
public Playgrounds<T> std( Path root ) { descr.removeTopic( Readonly.class ); descr.props.put( "playground", root ); if( !root.isAbsolute() ) { throw new IllegalArgumentException( "root path must be nonnull and absolute " + root ); } if( !absoluteGetRoot( root ).equals( absoluteGetRoot( root.getFileSystem().getPath( "" ).toAbsolutePath() ))) { descr.removeTopic( WorkingDirectoryInPlaygroundTree.class ); } if( root.getFileSystem().equals( FileSystems.getDefault() ) ) { descr.removeTopic( NotDefaultFileSystem.class ); } return this; }