private void moveNativeIndexFile( DatabaseLayout storeStructure, File nativeLabelIndex ) throws IOException { Optional<FileHandle> nativeIndexFileHandle = fileSystem.streamFilesRecursive( nativeLabelIndex ).findFirst(); if ( nativeIndexFileHandle.isPresent() ) { nativeIndexFileHandle.get().rename( storeStructure.labelScanStore() ); } }
private boolean isNativeLabelScanStoreMigrationRequired( DatabaseLayout directoryStructure ) throws IOException { return fileSystem.streamFilesRecursive( directoryStructure.labelScanStore() ) .noneMatch( Predicates.alwaysTrue() ); }
@Test void streamFilesRecursiveFilePathsMustBeCanonical() throws Exception { File sub = existingDirectory( "sub" ); File a = new File( new File( new File( sub, ".." ), "sub" ), "a" ); ensureExists( a ); Stream<FileHandle> stream = fsa.streamFilesRecursive( sub.getParentFile() ); List<File> filepaths = stream.map( FileHandle::getFile ).collect( toList() ); assertThat( filepaths, containsInAnyOrder( a.getCanonicalFile() ) );// file in our sub directory }
@Test void streamFilesRecursiveMustBeEmptyForEmptyBaseDirectory() throws Exception { File dir = existingDirectory( "dir" ); assertThat( fsa.streamFilesRecursive( dir ).count(), Matchers.is( 0L ) ); }
@Test void streamFilesRecursiveRenameMustCanonicaliseTargetFile() throws Exception { // File 'b' should canonicalise from 'b/poke/..' to 'b', which is a file that doesn't exists. // Thus, this should not throw a NoSuchFileException for the 'poke' directory. File a = existingFile( "a" ); File b = new File( new File( new File( path, "b" ), "poke" ), ".." ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( b ); }
@Test void shouldHandlePathThatLooksVeryDifferentWhenCanonicalized() throws Exception { File dir = existingDirectory( "/././home/.././././home/././.././././././././././././././././././home/././" ); File a = existingFile( "/home/a" ); List<File> filepaths = fsa.streamFilesRecursive( dir ).map( FileHandle::getRelativeFile ).collect( toList() ); assertThat( filepaths, containsInAnyOrder( new File( a.getName() ) ) ); }
@Test void streamFilesRecursiveMustBeAbleToGivePathRelativeToBase() throws Exception { File sub = existingDirectory( "sub" ); File a = existingFile( "a" ); File b = new File( sub, "b" ); ensureExists( b ); File base = a.getParentFile(); Set<File> set = fsa.streamFilesRecursive( base ).map( FileHandle::getRelativeFile ).collect( toSet() ); assertThat( "Files relative to base directory " + base, set, containsInAnyOrder( new File( "a" ), new File( "sub" + File.separator + "b" ) ) ); }
@Test void streamFilesRecursiveMustListAllFilesInBaseDirectory() throws Exception { File a = existingFile( "a" ); File b = existingFile( "b" ); File c = existingFile( "c" ); Stream<FileHandle> stream = fsa.streamFilesRecursive( a.getParentFile() ); List<File> filepaths = stream.map( FileHandle::getFile ).collect( toList() ); assertThat( filepaths, containsInAnyOrder( a.getCanonicalFile(), b.getCanonicalFile(), c.getCanonicalFile() ) ); }
@Test void streamFilesRecursiveListedSingleFileMustHaveCanonicalPath() throws Exception { File sub = existingDirectory( "sub" ); existingFile( "sub/x" ); // we query specifically for 'a', so this must not be listed File a = existingFile( "a" ); File queryForA = new File( new File( sub, ".." ), "a" ); Stream<FileHandle> stream = fsa.streamFilesRecursive( queryForA ); List<File> filepaths = stream.map( FileHandle::getFile ).collect( toList() ); assertThat( filepaths, containsInAnyOrder( a.getCanonicalFile() ) ); // note that we don't go into 'sub' }
@Test void streamFilesRecursiveRenameMustCanonicaliseSourceFile() throws Exception { // File 'a' should canonicalise from 'a/poke/..' to 'a', which is a file that exists. // Thus, this should not throw a NoSuchFileException. File a = new File( new File( existingFile( "a" ), "poke" ), ".." ); File b = nonExistingFile( "b" ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( b ); // must not throw }
@Test void streamFilesRecursiveMustListSingleFileGivenAsBase() throws Exception { existingDirectory( "sub" ); // must not be observed existingFile( "sub/x" ); // must not be observed File a = existingFile( "a" ); Stream<FileHandle> stream = fsa.streamFilesRecursive( a ); List<File> filepaths = stream.map( FileHandle::getFile ).collect( toList() ); assertThat( filepaths, containsInAnyOrder( a ) ); // note that we don't go into 'sub' }
@Test void streamFilesRecursiveMustReturnEmptyStreamForNonExistingBasePath() throws Exception { File nonExisting = new File( "nonExisting" ); assertFalse( fsa.streamFilesRecursive( nonExisting ).anyMatch( Predicates.alwaysTrue() ) ); }
@Test void streamFilesRecursiveMustNotThrowWhenTargetFileOfRenameAlreadyExistsAndUsingReplaceExisting() throws Exception { File a = existingFile( "a" ); File b = existingFile( "b" ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( b, StandardCopyOption.REPLACE_EXISTING ); }
@Test void streamFilesRecursiveMustThrowWhenDeletingNonExistingFile() throws Exception { File a = existingFile( "a" ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); fsa.deleteFile( a ); assertThrows( NoSuchFileException.class, handle::delete ); }
@Test void streamFilesRecursiveMustCreateMissingPathDirectoriesImpliedByFileRename() throws Exception { File a = existingFile( "a" ); File sub = new File( path, "sub" ); // does not exists File target = new File( sub, "b" ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( target ); assertTrue( fsa.isDirectory( sub ) ); assertTrue( fsa.fileExists( target ) ); }
@Test void streamFilesRecursiveRenameTargetFileMustBeRenamed() throws Exception { File a = existingFile( "a" ); File b = nonExistingFile( "b" ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( b ); assertTrue( fsa.fileExists( b ) ); }
@Test void streamFilesRecursiveSourceFileMustNotBeMappableAfterRename() throws Exception { File a = existingFile( "a" ); File b = nonExistingFile( "b" ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( b ); assertFalse( fsa.fileExists( a ) ); }
@Test void streamFilesRecursiveRenameMustNotChangeSourceFileContents() throws Exception { File a = existingFile( "a" ); File b = nonExistingFile( "b" ); generateFileWithRecords( a, recordCount ); FileHandle handle = fsa.streamFilesRecursive( a ).findAny().get(); handle.rename( b ); verifyRecordsInFile( b, recordCount ); }
@Test void streamFilesRecursiveMustDeleteSubDirectoriesEmptiedByFileDelete() throws Exception { File sub = existingDirectory( "sub" ); File x = new File( sub, "x" ); ensureExists( x ); fsa.streamFilesRecursive( sub ).forEach( HANDLE_DELETE ); assertFalse( fsa.isDirectory( sub ) ); assertFalse( fsa.fileExists( sub ) ); }
@Test void streamFilesRecursiveMustDeleteFiles() throws Exception { File a = existingFile( "a" ); File b = existingFile( "b" ); File c = existingFile( "c" ); File base = a.getParentFile(); fsa.streamFilesRecursive( base ).forEach( HANDLE_DELETE ); assertFalse( fsa.fileExists( a ) ); assertFalse( fsa.fileExists( b ) ); assertFalse( fsa.fileExists( c ) ); }