/**
  * Recover an unlinked tmp file on datanode restart. If the original block does not exist, then
  * the tmp file is renamed to be the original file name and the original name is returned;
  * otherwise the tmp file is deleted and null is returned.
  */
 File recoverTempUnlinkedBlock(File unlinkedTmp) throws IOException {
   File blockFile = FsDatasetUtil.getOrigFile(unlinkedTmp);
   if (blockFile.exists()) {
     // If the original block file still exists, then no recovery is needed.
     if (!unlinkedTmp.delete()) {
       throw new IOException("Unable to cleanup unlinked tmp file " + unlinkedTmp);
     }
     return null;
   } else {
     if (!unlinkedTmp.renameTo(blockFile)) {
       throw new IOException("Unable to rename unlinked tmp file " + unlinkedTmp);
     }
     return blockFile;
   }
 }