/** * Removes the deep sub element. * * @param element the element * @return true, if successful */ private boolean removeDeepSubElement(final FingerprintedElement element) { final File eFile = FileUtilities.findCanonicalLocation(element.cloneWorkspaceFile()); final String[] splitPath = FileUtilities.findSubPath(this.workspaceFile, eFile).substring(1).split("\\\\|\\/"); Container ptr = this; for (int i = 0; i < (splitPath.length - 1); i++) { ptr = (Container) ptr.getElement(splitPath[i]); if (ptr == null) return false; } return ptr.removeElement(element); }
/** * Specialized Constructor, which creates a clone of the given container. * * @param clonedContainer Container. * @throws org.hydra.core.InvalidElementException the invalid element exception */ public Container(final Container clonedContainer) throws InvalidElementException { this.fingerprint.setHash(clonedContainer.getFingerprint().getHash()); this.repositoryFile = new File(this.config.getFPStore(), this.fingerprint.getHash()); this.workspaceFile = new File(clonedContainer.cloneWorkspaceFile().getPath()); for (final FingerprintedElement e : clonedContainer.listElements()) { if (e instanceof Artifact) { this.elements.add(e); } else { this.elements.add(new Container((Container) e)); } } }
/** * Add a container and all if its contents found while searching recursively through the * directory. * * @param container Container. * @return success - boolean. */ public boolean addContainerAndContents(final Container container) { boolean success = this.addElement(container); for (final File subFile : container.cloneWorkspaceFile().listFiles(new FilterInFiles())) { try { if (!this.addElement(new Artifact(subFile))) { success = false; } } catch (final Exception e) { success = false; } } for (final File subDirectory : container.cloneWorkspaceFile().listFiles(new FilterInDirectories())) { try { if (!this.addContainerAndContents(new Container(subDirectory))) { success = false; } } catch (final Exception e) { success = false; } } return success; }
/** * Adds the deep sub element. * * @param element the element * @return true, if successful */ private boolean addDeepSubElement(final FingerprintedElement element) { final String SEPARATOR = File.separator; final File eFile = FileUtilities.findCanonicalLocation(element.cloneWorkspaceFile()); final String[] splitPath = FileUtilities.findSubPath(this.workspaceFile, eFile).substring(1).split("\\\\|\\/"); final StringBuilder sbPath = new StringBuilder(this.workspaceFile + SEPARATOR); Container ptr = this; for (int i = 0; i < (splitPath.length - 1); i++) { if (!splitPath[i].equals("")) { sbPath.append(splitPath[i] + SEPARATOR); if (ptr.getElement(splitPath[i]) == null) { try { ptr.addElement(new Container(new File(sbPath.toString()))); } catch (final Exception e) { this.logger.exception("Unable to Add Container [" + sbPath.toString() + "].", e); return false; } } ptr = (Container) ptr.getElement(splitPath[i]); } } return ptr.addElement(element); }