@Override public int hashCode() { return getPath().hashCode(); }
/** @return the last path segment (or an empty string for the root node */ public String getName() { String path; path = getPath(); // ok for -1: return path.substring(path.lastIndexOf(Filesystem.SEPARATOR_CHAR) + 1); }
private boolean isManifest(Node node) { return manifest != null && MANIFEST.equals(node.getPath()); }
/** * Creates an absolute link dest pointing to this. The signature of this method resembles the copy method. * * @param dest link to be created * @return dest; */ public T link(T dest) throws LinkException { if (!getClass().equals(dest.getClass())) { throw new IllegalArgumentException(this.getClass() + " vs " + dest.getClass()); } try { checkExists(); } catch (IOException e) { throw new LinkException(this, e); } // TODO: getRoot() for ssh root ... dest.mklink(Filesystem.SEPARATOR_STRING + this.getPath()); return dest; }
/** @return kind of a path, with . and .. where appropriate. */ public String getRelative(Node base) { String startfilepath; String destpath; String common; StringBuilder result; int len; int ups; int i; if (base.equals(this)) { return "."; } startfilepath = base.join("foo").getPath(); destpath = getPath(); common = Strings.getCommon(startfilepath, destpath); common = common.substring(0, common.lastIndexOf(Filesystem.SEPARATOR_CHAR) + 1); // ok for idx == -1 len = common.length(); startfilepath = startfilepath.substring(len); destpath = destpath.substring(len); result = new StringBuilder(); ups = Strings.count(startfilepath, Filesystem.SEPARATOR_STRING); for (i = 0; i < ups; i++) { result.append("..").append(Filesystem.SEPARATOR_STRING); } result.append(destpath); return result.toString(); }
/** @return image ids */ public List<String> imageList(Map<String, String> labels) throws IOException { String filters; Node node; JsonArray array; List<String> result; String id; node = root.join("images/json"); filters = labels.isEmpty()? "" : "&filters=" + enc("{\"label\" : [" + labelsToJsonArray(labels) + "] }"); node = node.getRoot().node(node.getPath(), "all=true" + filters); array = parser.parse(node.readString()).getAsJsonArray(); result = new ArrayList<>(array.size()); for (JsonElement element : array) { id = element.getAsJsonObject().get("Id").getAsString(); id = Strings.removeLeft(id, "sha256:"); result.add(id); } return result; }
public T getParent() { String path; int idx; path = getPath(); if ("".equals(path)) { return null; } idx = path.lastIndexOf(Filesystem.SEPARATOR_CHAR); if (idx == -1) { return getRoot().node("", null); } else { return getRoot().node(path.substring(0, idx), null); } }
/** * @param image may be null * @return container ids */ public List<String> containerList(String image) throws IOException { String filters; Node node; JsonArray array; List<String> result; String id; node = root.join("containers/json"); filters = image == null? "" : "&filters=" + enc("{\"ancestor\" : [\"" + image + "\"] }"); node = node.getRoot().node(node.getPath(), "all=true" + filters); array = parser.parse(node.readString()).getAsJsonArray(); result = new ArrayList<>(array.size()); for (JsonElement element : array) { id = element.getAsJsonObject().get("Id").getAsString(); result.add(id); } return result; }
public T join(List<String> paths) { Root<T> root; T result; root = getRoot(); result = root.node(root.getFilesystem().join(getPath(), paths), null); return result; }
/** * @return a normalized URI, not necessarily the URI this node was created from. Does not contain userInfo to avoid accidentialls * printing it. Use getUriWithUserInfo instead if you know what you're doing. */ public URI getUri() { return URI.create(getRoot().getFilesystem().getScheme() + ":" + getRoot().getId() + encodePath(getPath())); }
/** * Returns a String representation suitable for messages. * * CAUTION: don't use to convert to a string, use instead. */ @Override public String toString() { Node working; working = getWorld().getWorking(); if (working == null || !getRoot().equals(working.getRoot())) { return getUri().toString(); } else { if (hasAncestor(working)) { return getRelative(working); } else { return Filesystem.SEPARATOR_STRING + getPath(); } } }
if ("".equals(node.getPath())) { continue;