code: public static boolean renamePathHandleLocalFSRace(FileSystem fs, Path src, Path dst) throws IOException {
      if (DecoratorUtils.resolveUnderlyingObject(fs) instanceof LocalFileSystem && fs.isDirectory(src)) {
        LocalFileSystem localFs = (LocalFileSystem) DecoratorUtils.resolveUnderlyingObject(fs);
        File srcFile = localFs.pathToFile(src);
        File dstFile = localFs.pathToFile(dst);
  
        return srcFile.renameTo(dstFile);
      }
      else {
        return fs.rename(src, dst);
      }
    }
docs: Renames a src {@link Path} on fs {@link FileSystem} to a dst {@link Path}. If fs is a {@link LocalFileSystem} and
  src is a directory then {@link File#renameTo} is called directly to avoid a directory rename race condition where
  {@link org.apache.hadoop.fs.RawLocalFileSystem#rename} copies the conflicting src directory into dst resulting in
  an extra nested level, such as /root/a/b/c/e/e where e is repeated.
  
  @param fs the {@link FileSystem} where the src {@link Path} exists
  @param src the source {@link Path} which will be renamed
  @param dst the {@link Path} to rename to
  @return true if rename succeeded, false if rename failed.
  @throws IOException if rename failed for reasons other than target exists.