@Override public boolean rename(Path path0, Path path1) throws IOException { this.acquirePermit("rename " + path0); return HadoopUtils.renamePathHandleLocalFSRace(this.underlyingFs, path0, path1); }
/** * Renames from to to if to doesn't exist in a non-thread-safe way. * * @param fs filesystem where rename will be executed. * @param from origin {@link Path}. * @param to target {@link Path}. * @return true if rename succeeded, false if the target already exists. * @throws IOException if rename failed for reasons other than target exists. */ 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; }