@Override public boolean exists(GenericId id) { Path absolutePath = this.id2AbsolutePath(id); return Files.exists(absolutePath); }
@Override public boolean flagAsExisting(GenericId id) { Path path = this.id2AbsolutePath(id); try { FileUtils.createDirectory(path); } catch (IOException e) { FilebasedRepository.LOGGER.debug(e.toString()); return false; } return true; }
@Override public void forceDelete(GenericId id) { FileUtils.forceDelete(this.id2AbsolutePath(id)); }
/** * Converts the given reference to an absolute path of the underlying FileSystem */ public Path ref2AbsolutePath(RepositoryFileReference ref) { Path resultPath = this.id2AbsolutePath(ref.getParent()); final Optional<Path> subDirectory = ref.getSubDirectory(); if (subDirectory.isPresent()) { resultPath = resultPath.resolve(subDirectory.get()); } return resultPath.resolve(ref.getFileName()); }
public void forceDelete(Class<? extends DefinitionsChildId> definitionsChildIdClazz, Namespace namespace) { // instantiate new definitions child id with "ID" as id // this is used to get the absolute path DefinitionsChildId id = BackendUtils.getDefinitionsChildId(definitionsChildIdClazz, namespace.getEncoded(), "ID", true); Path path = this.id2AbsolutePath(id); // do not delete the id, delete the complete namespace // patrent folder is the namespace folder path = path.getParent(); FileUtils.forceDelete(path); }
@Override public <T extends ToscaElementId> SortedSet<T> getNestedIds(GenericId ref, Class<T> idClass) { Path dir = this.id2AbsolutePath(ref); SortedSet<T> res = new TreeSet<>(); if (!Files.exists(dir)) {
@Override public SortedSet<RepositoryFileReference> getContainedFiles(GenericId id) { Path dir = this.id2AbsolutePath(id); SortedSet<RepositoryFileReference> res = new TreeSet<>(); if (!Files.exists(dir)) { return res; } assert (Files.isDirectory(dir)); final OnlyNonHiddenFiles onlyNonHiddenFiles = new OnlyNonHiddenFiles(); try { Files.walk(dir).filter(f -> { try { return onlyNonHiddenFiles.accept(f); } catch (IOException e) { LOGGER.debug("Error during crawling", e); return false; } }).map(f -> { final Path relativePath = dir.relativize(f.getParent()); if (relativePath.toString().isEmpty()) { return new RepositoryFileReference(id, f.getFileName().toString()); } else { return new RepositoryFileReference(id, relativePath, f.getFileName().toString()); } }).forEach(ref -> res.add(ref)); } catch (IOException e1) { LOGGER.debug("Error during crawling", e1); } return res; }
File oldDir = this.id2AbsolutePath(oldRef.getParent()).toFile(); File newDir = this.id2AbsolutePath(newRef.getParent()).toFile();