/** Create directory entries for every item */ boolean mkdirs(String src) { src = normalizePath(new UTF8(src)); // Use this to collect all the dirs we need to construct Vector v = new Vector(); // The dir itself v.add(src); // All its parents String parent = DFSFile.getDFSParent(src); while (parent != null) { v.add(parent); parent = DFSFile.getDFSParent(parent); } // Now go backwards through list of dirs, creating along // the way boolean lastSuccess = false; int numElts = v.size(); for (int i = numElts - 1; i >= 0; i--) { String cur = (String) v.elementAt(i); INode inserted = unprotectedMkdir(cur); if (inserted != null) { logEdit(OP_MKDIR, new UTF8(inserted.computeName()), null); lastSuccess = true; } else { lastSuccess = false; } } return lastSuccess; }
/** Add the given filename to the fs. */ public boolean addFile(UTF8 src, Block blocks[]) { waitForReady(); // Always do an implicit mkdirs for parent directory tree mkdirs(DFSFile.getDFSParent(src.toString())); if (unprotectedAddFile(src, blocks)) { logEdit(OP_ADD, src, new ArrayWritable(Block.class, blocks)); return true; } else { return false; } }
INode addNode(String target, Block blks[]) { if (getNode(target) != null) { return null; } else { String parentName = DFSFile.getDFSParent(target); if (parentName == null) { return null; } INode parentNode = getNode(parentName); if (parentNode == null) { return null; } else { String targetName = new File(target).getName(); INode newItem = new INode(targetName, parentNode, blks); parentNode.children.put(targetName, newItem); return newItem; } } }