Exemple #1
0
  /** 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();
  }
Exemple #2
0
 int numItemsInTree() {
   int total = 0;
   for (Iterator it = children.values().iterator(); it.hasNext(); ) {
     INode child = (INode) it.next();
     total += child.numItemsInTree();
   }
   return total + 1;
 }