// Set type of file as name of the element private void setType(Element element, Path path) { if (Files.isDirectory(path)) { element.setLocalName(FileType.DIR.getName()); return; } else if (Files.isRegularFile(path)) { element.setLocalName(FileType.FILE.getName()); return; } else if (Files.isSymbolicLink(path)) { element.setLocalName(FileType.SYMLINK.getName()); return; } else element.setLocalName(FileType.OTHER.getName()); }
public synchronized void addToDirectory(PseudoPath dir, FSImage child) { if (!getType(dir).equals(FileType.DIR.getName())) { throw new IllegalArgumentException("Can add files only to directories."); } Element parent = getElement(dir); Element newChild = new Element(child.fileTree); String nameOfChildRoot = child.fileTree.getAttributeValue("name"); PseudoPath pathToChild = dir.resolve(nameOfChildRoot); Element oldChild = getElement(pathToChild); if (oldChild != null) { parent.replaceChild(oldChild, newChild); } else { parent.appendChild(newChild); } }