/** * Moves a file from one directory to another, by a rename op. * * @param fs the {@link FileSystemAbstraction} the file exist on * @param fileName base filename of the file to move, not the complete path * @param fromDirectory directory currently containing filename * @param toDirectory directory to host filename - must be in the same disk partition as filename * @throws IOException if the file couldn't be moved */ @Override public void perform( FileSystemAbstraction fs, String fileName, File fromDirectory, boolean skipNonExistentFromFile, File toDirectory, ExistingTargetStrategy existingTargetStrategy ) throws IOException { File fromFile = fromFile( fs, fromDirectory, fileName, skipNonExistentFromFile ); if ( fromFile != null ) { if ( toFile( fs, toDirectory, fileName, existingTargetStrategy ) != null ) { fs.moveToDirectory( fromFile, toDirectory ); } } } },
@Override public void moveToDirectory( File file, File toDirectory ) throws IOException { fs.moveToDirectory( file, toDirectory ); }
@Override public void moveToDirectory( File file, File toDirectory ) throws IOException { delegate.moveToDirectory( file, toDirectory ); }
@Override public void moveMigratedFiles( DatabaseLayout migrationLayout, DatabaseLayout directoryLayout, String versionToMigrateFrom, String versionToMigrateTo ) throws IOException { if ( explicitIndexMigrated ) { fileSystem.deleteRecursively( originalExplicitIndexesRoot ); fileSystem.moveToDirectory( migrationExplicitIndexesRoot, originalExplicitIndexesRoot.getParentFile() ); } }
@Override public void moveToDirectory( File file, File toDirectory ) throws IOException { chooseFileSystem( file ).moveToDirectory( file, toDirectory ); }
@Override public void moveToDirectory( File file, File toDirectory ) throws IOException { adversary.injectFailure( SecurityException.class, IllegalArgumentException.class, FileNotFoundException.class, NullPointerException.class, IOException.class ); delegate.moveToDirectory( file, toDirectory ); }
@Test public void skipEmptyIndexStorageMigration() throws IOException { when( fs.listFiles( originalIndexStore ) ).thenReturn( null ); ExplicitIndexProvider indexProviders = getExplicitIndexProvider(); ExplicitIndexMigrator indexMigrator = new TestExplicitIndexMigrator( fs, indexProviders, logProvider, true ); indexMigrator.migrate( storeLayout, migrationLayout, progressMonitor, StandardV2_3.STORE_VERSION, StandardV3_0.STORE_VERSION ); verify( fs, never() ).deleteRecursively( originalIndexStore ); verify( fs, never() ).moveToDirectory( migratedIndexStore, storeLayout.databaseDirectory() ); }
@Test public void transferMigratedIndexesToStoreDirectory() throws IOException { ExplicitIndexProvider indexProviders = getExplicitIndexProvider(); ExplicitIndexMigrator indexMigrator = new TestExplicitIndexMigrator( fs, indexProviders, logProvider, true ); indexMigrator.migrate( storeLayout, migrationLayout, progressMonitor, StandardV2_3.STORE_VERSION, StandardV3_0.STORE_VERSION ); reset( fs ); indexMigrator.moveMigratedFiles( migrationLayout, storeLayout, "any", "any" ); verify( fs ).deleteRecursively( originalIndexStore ); verify( fs ).moveToDirectory( migratedIndexStore, storeLayout.databaseDirectory() ); }
@Test void moveToDirectoryMustMoveFile() throws Exception { File source = new File( path, "source" ); File target = new File( path, "target" ); File file = new File( source, "file" ); File fileAfterMove = new File( target, "file" ); fsa.mkdirs( source ); fsa.mkdirs( target ); fsa.create( file ).close(); assertTrue( fsa.fileExists( file ) ); assertFalse( fsa.fileExists( fileAfterMove ) ); fsa.moveToDirectory( file, target ); assertFalse( fsa.fileExists( file ) ); assertTrue( fsa.fileExists( fileAfterMove ) ); }
/** * Moves a file from one directory to another, by a rename op. * * @param fs the {@link FileSystemAbstraction} the file exist on * @param fileName base filename of the file to move, not the complete path * @param fromDirectory directory currently containing filename * @param toDirectory directory to host filename - must be in the same disk partition as filename * @throws IOException if the file couldn't be moved */ @Override public void perform( FileSystemAbstraction fs, String fileName, File fromDirectory, boolean skipNonExistentFromFile, File toDirectory, ExistingTargetStrategy existingTargetStrategy ) throws IOException { File fromFile = fromFile( fs, fromDirectory, fileName, skipNonExistentFromFile ); if ( fromFile != null ) { if ( toFile( fs, toDirectory, fileName, existingTargetStrategy ) != null ) { fs.moveToDirectory( fromFile, toDirectory ); } } } },
@Override public void moveMigratedFiles( DatabaseLayout migrationLayout, DatabaseLayout directoryLayout, String versionToMigrateFrom, String versionToMigrateTo ) throws IOException { if ( explicitIndexMigrated ) { fileSystem.deleteRecursively( originalExplicitIndexesRoot ); fileSystem.moveToDirectory( migrationExplicitIndexesRoot, originalExplicitIndexesRoot.getParentFile() ); } }
void moveTo( File source, File target ) throws IOException { for ( File candidate : fs.listFiles( source, STORE_FILE_FILTER ) ) { fs.moveToDirectory( candidate, target ); } } }
/** * The cluster state directory was previously badly placed under the * store directory, and this method takes care of the migration path from * that. It will now reside under the data directory. */ private void migrateIfNeeded( FileSystemAbstraction fs ) throws ClusterStateException { File oldStateDir = new File( storeDir, CLUSTER_STATE_DIRECTORY_NAME ); if ( !fs.fileExists( oldStateDir ) || oldStateDir.equals( stateDir ) ) { return; } if ( fs.fileExists( stateDir ) ) { throw new ClusterStateException( "Cluster state exists in both old and new locations" ); } try { fs.moveToDirectory( oldStateDir, stateDir.getParentFile() ); } catch ( IOException e ) { throw new RuntimeException( "Failed to migrate cluster state directory", e ); } }
public void moveTo( File source, File target, LogFiles logFiles ) throws IOException { fs.mkdirs( logFiles.logFilesDirectory() ); for ( File candidate : fs.listFiles( source, fileFilter ) ) { File destination = logFiles.isLogFile( candidate) ? logFiles.logFilesDirectory() : target; fs.moveToDirectory( candidate, destination ); } Iterable<FileHandle> fileHandles = acceptedPageCachedFiles( source )::iterator; for ( FileHandle fh : fileHandles ) { fh.rename( new File( target, fh.getRelativeFile().getPath() ), StandardCopyOption.REPLACE_EXISTING ); } }