@Override public void renameFile( File from, File to, CopyOption... copyOptions ) throws IOException { delegate.renameFile( from, to, copyOptions ); }
@Override public void renameFile( File from, File to, CopyOption... copyOptions ) throws IOException { fs.renameFile( from, to, copyOptions ); }
@Override public void rename( File to, CopyOption... options ) throws IOException { File parentFile = file.getParentFile(); File canonicalTarget = to.getCanonicalFile(); fs.mkdirs( canonicalTarget.getParentFile() ); fs.renameFile( file, canonicalTarget, options ); removeEmptyParent( parentFile ); }
private void moveAwayFile() throws IOException { File to; do { to = timestampedFile(); } while ( fs.fileExists( to ) ); fs.renameFile( file, to ); }
@Override public void markAsMigrated() throws IOException { super.markAsMigrated(); // Clears all cached data // Rename the file File destinationFile = FileRepository.getMigratedFile( authFile ); fileSystem.renameFile( authFile, destinationFile, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES ); } }
@Override public void renameFile( File from, File to, CopyOption... copyOptions ) throws IOException { adversary.injectFailure( FileNotFoundException.class, SecurityException.class ); delegate.renameFile( from, to, copyOptions ); }
@Override public void renameFile( File from, File to, CopyOption... copyOptions ) throws IOException { chooseFileSystem( from ).renameFile( from, to, copyOptions ); }
private void write() { // Write to a .tmp file File tmpFile = dbDirectoryStructure.file( TMP_INDEX_DB_FILE_NAME ); write( tmpFile ); // Make sure the .old file doesn't exist, then rename the current one to .old fileSystem.deleteFile( oldFile ); try { if ( fileSystem.fileExists( file ) ) { fileSystem.renameFile( file, oldFile ); } } catch ( IOException e ) { throw new RuntimeException( "Couldn't rename " + file + " -> " + oldFile, e ); } // Rename the .tmp file to the current name try { fileSystem.renameFile( tmpFile, this.file ); } catch ( IOException e ) { throw new RuntimeException( "Couldn't rename " + tmpFile + " -> " + file, e ); } fileSystem.deleteFile( oldFile ); }
private void shiftArchivedOutputFiles() throws IOException { for ( int i = lastArchivedOutputFileNumber( fileSystem, outputFile ); i > 0; --i ) { File archive = archivedOutputFile( outputFile, i ); if ( i >= maxArchives ) { fileSystem.deleteFile( archive ); } else { fileSystem.renameFile( archive, archivedOutputFile( outputFile, i + 1 ) ); } } }
public void saveRecordsToFile( FileSystemAbstraction fileSystem, File recordsFile, Collection<S> records ) throws IOException { File tempFile = getTempFile( fileSystem, recordsFile ); try { writeToFile( fileSystem, tempFile, serialize( records ) ); fileSystem.renameFile( tempFile, recordsFile, ATOMIC_MOVE, REPLACE_EXISTING ); } catch ( Throwable e ) { fileSystem.deleteFile( tempFile ); throw e; } }
@Test void shouldNotifyListenerOnRotationErrorDuringRotationIO() throws Exception { RotationListener rotationListener = mock( RotationListener.class ); FileSystemAbstraction fs = spy( fileSystem ); RotatingFileOutputStreamSupplier supplier = new RotatingFileOutputStreamSupplier( fs, logFile, 10, 0, 10, DIRECT_EXECUTOR, rotationListener ); OutputStream outputStream = supplier.get(); IOException exception = new IOException( "text exception" ); doThrow( exception ).when( fs ).renameFile( any( File.class ), any( File.class ) ); write( supplier, "A string longer than 10 bytes" ); assertThat( supplier.get(), is( outputStream ) ); verify( rotationListener ).rotationError( eq( exception ), any( OutputStream.class ) ); }
fileSystem.renameFile( outputFile, archivedOutputFile( outputFile, 1 ) );
@Test public void shouldNotErrorIfOnlyTheUnmodifiedDefaultNeo4jUserAlreadyExists() throws Throwable { // Given // Create an `auth` file with the default neo4j user tool.execute( homeDir.toPath(), confDir.toPath(), SET_PASSWORD, UserManager.INITIAL_PASSWORD ); File authFile = getAuthFile( "auth" ); fileSystem.mkdirs( authFile.getParentFile() ); fileSystem.renameFile( getAuthFile( "auth.ini" ), authFile ); // When tool.execute( homeDir.toPath(), confDir.toPath(), SET_PASSWORD, "should-not-be-ignored" ); // Then assertAuthIniFile( "should-not-be-ignored" ); verify( out, times( 2 ) ).stdOutLine( "Changed password for user 'neo4j'." ); }
@Test public void shouldErrorIfRealUsersAlreadyExistV2() throws Throwable { // Given // Create an `auth` file with the default neo4j user, but not the default password tool.execute( homeDir.toPath(), confDir.toPath(), SET_PASSWORD, "not-the-default-password" ); File authFile = getAuthFile( "auth" ); fileSystem.mkdirs( authFile.getParentFile() ); fileSystem.renameFile( getAuthFile( "auth.ini" ), authFile ); // When tool.execute( homeDir.toPath(), confDir.toPath(), SET_PASSWORD, "will-be-ignored" ); // Then assertNoAuthIniFile(); verify( out, times( 1 ) ) .stdErrLine( "command failed: the provided initial password was not set because existing Neo4j users were " + "detected at `" + authFile.getAbsolutePath() + "`. Please remove the existing `auth` file if you " + "want to reset your database to only have a default user with the provided password." ); verify( out ).exit( 1 ); verify( out, times( 1 ) ).stdOutLine( "Changed password for user 'neo4j'." ); // This is from the initial setup }
@Override public void rename( File to, CopyOption... options ) throws IOException { File parentFile = file.getParentFile(); File canonicalTarget = to.getCanonicalFile(); fs.mkdirs( canonicalTarget.getParentFile() ); fs.renameFile( file, canonicalTarget, options ); removeEmptyParent( parentFile ); }
private void moveAwayFile() throws IOException { File to; do { to = timestampedFile(); } while ( fs.fileExists( to ) ); fs.renameFile( file, to ); }
@Override public void markAsMigrated() throws IOException { super.markAsMigrated(); // Clears all cached data // Rename the file File destinationFile = FileRepository.getMigratedFile( authFile ); fileSystem.renameFile( authFile, destinationFile, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES ); } }
private void write() { // Write to a .tmp file File tmpFile = dbDirectoryStructure.file( TMP_INDEX_DB_FILE_NAME ); write( tmpFile ); // Make sure the .old file doesn't exist, then rename the current one to .old fileSystem.deleteFile( oldFile ); try { if ( fileSystem.fileExists( file ) ) { fileSystem.renameFile( file, oldFile ); } } catch ( IOException e ) { throw new RuntimeException( "Couldn't rename " + file + " -> " + oldFile, e ); } // Rename the .tmp file to the current name try { fileSystem.renameFile( tmpFile, this.file ); } catch ( IOException e ) { throw new RuntimeException( "Couldn't rename " + tmpFile + " -> " + file, e ); } fileSystem.deleteFile( oldFile ); }
public void saveRecordsToFile( FileSystemAbstraction fileSystem, File recordsFile, Collection<S> records ) throws IOException { File tempFile = getTempFile( fileSystem, recordsFile ); try { writeToFile( fileSystem, tempFile, serialize( records ) ); fileSystem.renameFile( tempFile, recordsFile, ATOMIC_MOVE, REPLACE_EXISTING ); } catch ( Throwable e ) { fileSystem.deleteFile( tempFile ); throw e; } }
private void shiftArchivedOutputFiles() throws IOException { for ( int i = lastArchivedOutputFileNumber( fileSystem, outputFile ); i > 0; --i ) { File archive = archivedOutputFile( outputFile, i ); if ( i >= maxArchives ) { fileSystem.deleteFile( archive ); } else { fileSystem.renameFile( archive, archivedOutputFile( outputFile, i + 1 ) ); } } }