/** * Copy specified file into a temporary file. Then rename the temporary file to the original name. * This will cause any hardlinks to the original file to be removed. The temporary files are * created in the same directory. The temporary files will be recovered (especially on Windows) on * datanode restart. */ private void unlinkFile(File file, Block b) throws IOException { File tmpFile = DatanodeUtil.createTmpFile(b, DatanodeUtil.getUnlinkTmpFile(file)); try { FileInputStream in = new FileInputStream(file); try { FileOutputStream out = new FileOutputStream(tmpFile); try { IOUtils.copyBytes(in, out, 16 * 1024); } finally { out.close(); } } finally { in.close(); } if (file.length() != tmpFile.length()) { throw new IOException( "Copy of file " + file + " size " + file.length() + " into file " + tmpFile + " resulted in a size of " + tmpFile.length()); } FileUtil.replaceFile(tmpFile, file); } catch (IOException e) { boolean done = tmpFile.delete(); if (!done) { DataNode.LOG.info("detachFile failed to delete temporary file " + tmpFile); } throw e; } }
/** * Get the full path of this replica's meta file * * @return the full path of this replica's meta file */ public File getMetaFile() { return new File(getDir(), DatanodeUtil.getMetaName(getBlockName(), getGenerationStamp())); }