public static boolean unsafeRenameIfNotExists ( FileSystem fs , Path from , Path to ) throws IOException { if ( ! fs . exists ( to ) ) { if ( ! fs . exists ( to . getParent ( ) ) ) { fs . mkdirs ( to . getParent ( ) ) ; } if ( ! renamePathHandleLocalFSRace ( fs , from , to ) ) { if ( ! fs . exists ( to ) ) { throw new IOException ( String . format ( "Failed to rename %s to %s." , from , to ) ) ; } return false ; } return true ; } return false ; }
Renames from to to if to doesn t exist in a non - thread - safe way .