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; }
@Test @Category( { SlowTest.class, Writable.class, Attributes.class, LastModifiedTime.class } ) public void testCreateFileSetsModifiedTimeOfParent() throws IOException, InterruptedException { Path file = absTA(); FileTime created = Files.getLastModifiedTime( childGetParent( file ) ); waitForAttribute(); Files.write( file, CONTENT, standardOpen ); FileTime modified = Files.getLastModifiedTime( childGetParent( file ) ); assertThat( modified ).isGreaterThan( created ); }
@Test @Category( { SlowTest.class, Writable.class, Attributes.class } ) // changed attis are only relevant in writable cases public void testReadDirStreamDoesNotSetParentsLastAccessTime() throws Exception { Path dir = dirTA(); FileTime before = Files.readAttributes( childGetParent( dir ), BasicFileAttributes.class ).lastAccessTime(); waitForAttribute(); Files.list( dir ).forEach( p -> { } ); assertThat( Files.readAttributes( childGetParent( dir ), BasicFileAttributes.class ).lastAccessTime() ).isEqualTo( before ); }
@Test @Category( { Writable.class, Basic.class } ) public void testNewFileIsInDirStream() throws IOException { Path file = absTA(); Files.write( file, CONTENT, standardOpen ); assertThat( Files.list( childGetParent( file )).filter( file::equals ).findAny()).isPresent(); }
@Test @Category( { Writable.class, Move.class, MaxPath.class, LimitedPath.class } ) public void testMaxPathMoveTooLongThrows() throws IOException { Path loong = absTTooLongPath(); Files.createDirectories( childGetParent( loong )); assertThatThrownBy( () -> Files.move( fileTAB(), loong ) ).isInstanceOf( IOException.class ); }
@Test public void testNormalizeWildAbsPaths() { Path abs = absAB(); assertThat( abs.resolve( ".." + FS.getSeparator() + "bb" + FS.getSeparator() + ".." + FS.getSeparator() + "." ).normalize() ). isEqualTo( childGetParent( abs ) ); assertThat( relA().resolve( ".." ).normalize().toString() ).isEqualTo( "" ); }
protected Path otherProviderFileA() { Path ret = otherProviderAbsA(); if( !Files.exists( ret ) ) { Filess.createDirectories( childGetParent( ret ) ); Filess.write( ret, CONTENT ); } return ret; }
@Test @Category( { SlowTest.class, Writable.class, Delete.class, Attributes.class, CreationTime.class } ) public void testDeleteFileDoesNotChangeParentCreationTime() throws IOException, InterruptedException { Path file = fileTAB(); Path parent = childGetParent( file ); FileTime created = Files.readAttributes( parent, BasicFileAttributes.class ).creationTime(); waitForAttribute(); Files.delete( file ); assertThat( Files.readAttributes( parent, BasicFileAttributes.class ).creationTime() ).isEqualTo( created ); }
@Test @Category( { Writable.class, Move.class } ) public void testRenamingAFileAddsNameToParentsDirStream() throws IOException { Path tgt = childGetParent( src() ).resolve( "tgt" ); Files.move( srcFile(), tgt ); assertThat( isKid( src().getParent(), tgt )).isTrue(); }
@Test @Category( Windows.class ) public void testCaseRemembering() throws IOException { Path file = dirTA().resolve( nameD() ); // create file where last filename is mixed case Files.write( mixCase( file ), CONTENT ); try( DirectoryStream<Path> dstr = Files.newDirectoryStream( childGetParent( file ) ) ) { Path kid = dstr.iterator().next(); assertThat( kid ).isEqualTo( file ); assertThat( kid.toString() ).isNotEqualTo( file.toString() ); } }
@Test @Category( { SlowTest.class, Writable.class, Move.class, Attributes.class, LastModifiedTime.class } ) public void testMoveChangesModifiedTimeOfParent() throws IOException, InterruptedException { FileTime modi = Files.getLastModifiedTime( childGetParent( srcFile()) ); waitForAttribute(); Files.move( src(), tgt() ); assertThat( Files.getLastModifiedTime( childGetParent( src()) ) ).isGreaterThan( modi ); }
protected Path otherProviderTargetFile() { Path target = otherProviderAbsA().resolve( nameB() ); if( !Files.exists( target ) ) { Filess.createDirectories( childGetParent( target ) ); Filess.write( target, CONTENT ); } return target; }
@Test @Category( { HardLink.class, Writable.class, MaxPath.class, LimitedPath.class } ) public void testMaxPathHardLinkTooLongThrows() throws IOException { Path loong = absTTooLongPath(); Files.createDirectories( childGetParent( loong )); assertThatThrownBy( () -> Files.createLink( loong, fileTAB() ) ).isInstanceOf( IOException.class ); }
@Test @Category( { SlowTest.class, Writable.class, CreationTime.class } ) public void testCreateDirSetsCreationTime() throws IOException, InterruptedException { Path dir = absTA(); FileTime before = Files.getLastModifiedTime( childGetParent( dir ) ); waitForAttribute(); Files.createDirectory( dir ); BasicFileAttributes atti = Files.readAttributes( dir, BasicFileAttributes.class ); assertThat( atti.creationTime() ).isGreaterThan( before ); }
@Test public void testGetParentIsInverseOfResolve() throws Exception { assertThat( relA() ).isEqualTo( childGetParent( relA().resolve( relB() ) ) ); assertThat( relAB() ).isEqualTo( childGetParent( relAB() ).resolve( relB() ) ); }
@Test @Category( WorkingDirectoryInPlaygroundTree.class ) public void testKidsOfRelativeDirAreRelative() throws Exception { try( DirectoryStream<Path> kids = Files.newDirectoryStream( childGetParent( relativize( getNonEmptyDir() ) ) ) ) { for( Path kid : kids ) { assertThat( kid ).isRelative(); } } }
@Test @Category( { SlowTest.class, Writable.class, Attributes.class } ) public void testOverwriteDoesNotSetLastAccessTimeOfParent() throws IOException, InterruptedException { Path there = fileTA(); FileTime before = Files.readAttributes( childGetParent( there ), BasicFileAttributes.class ).lastAccessTime(); waitForAttribute(); Set<StandardOpenOption> options = asSet( WRITE, TRUNCATE_EXISTING ); try( SeekableByteChannel ch = FS.provider().newByteChannel( there, options ) ) { } assertThat( Files.readAttributes( there.getParent(), BasicFileAttributes.class ).lastAccessTime() ).isEqualTo( before ); }
public void removeFile( EightyPath path ) { throwIfNotStd( path ); PathContent parentPC = content.get( childGetParent( path ) ).orElseThrow( () -> new IllegalArgumentException( "paths parent does not exist " + path ) ); content.remove( path ); parentPC.kids.remove( path ); parentPC.attis.setLastAccessTime(); parentPC.attis.setLastModifiedTime(); }
@Test @Category( { SymLink.class } ) public void testSymLinkToUnnormalizedRelPath() throws IOException { Files.createSymbolicLink( symLink(), FS.getPath( nameA() ).resolve( ".." ) ); Files.createSymbolicLink( childGetParent( symLink() ).resolve( nameA() ), targetFile() ); // System.out.println( symLink().toRealPath()); // System.out.println( targetFile().getParent().toRealPath()); assertThat( Files.isSameFile( symLink(), targetFile().getParent() ) ).isTrue(); }
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 ); }