/** Save the contents of the FS image */ void saveFSImage(File fullimage, File edits) throws IOException { File curFile = new File(fullimage, FS_IMAGE); File newFile = new File(fullimage, NEW_FS_IMAGE); File oldFile = new File(fullimage, OLD_FS_IMAGE); // // Write out data // DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newFile))); try { out.writeInt(rootDir.numItemsInTree() - 1); rootDir.saveImage("", out); } finally { out.close(); } // // Atomic move sequence // // 1. Move cur to old curFile.renameTo(oldFile); // 2. Move new to cur newFile.renameTo(curFile); // 3. Remove pending-edits file (it's been integrated with newFile) edits.delete(); // 4. Delete old oldFile.delete(); }
void saveImage(String parentPrefix, DataOutputStream out) throws IOException { String fullName = ""; if (parent != null) { fullName = parentPrefix + "/" + name; new UTF8(fullName).write(out); if (blocks == null) { out.writeInt(0); } else { out.writeInt(blocks.length); for (int i = 0; i < blocks.length; i++) { blocks[i].write(out); } } } for (Iterator it = children.values().iterator(); it.hasNext(); ) { INode child = (INode) it.next(); child.saveImage(fullName, out); } }