private boolean isRootFolder(String targetBackupDir) { Path p = new Path(targetBackupDir); return p.isRoot(); }
private static boolean isChildDirectory(Path parentDirectory, Path childDirectory) { if (parentDirectory.equals(childDirectory)) { return true; } if (childDirectory.isRoot()) { return false; } return isChildDirectory(parentDirectory, childDirectory.getParent()); } }
/** * Returns the root path for the specified path. * * @see Path */ public static Path getRootPath(Path path) { if (path.isRoot()) { return path; } return getRootPath(path.getParent()); }
/** * * @param path * @return return full path including the chroot */ protected Path fullPath(final Path path) { super.checkPath(path); return new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString) + path.toUri().getPath()); }
/** Returns true if the target is an ancestor of the source. */ private boolean isAncestor(PathData source, PathData target) { for (Path parent = source.path; (parent != null) && !parent.isRoot(); parent = parent.getParent()) { if (parent.equals(target.path)) { return true; } } return false; }
/** * @param path * @return full path including the chroot */ protected Path fullPath(final Path path) { super.checkPath(path); return path.isAbsolute() ? new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString) + path.toUri().getPath()) : new Path(chRootPathPartString + workingDir.toUri().getPath(), path); }
/** * Strip out the root from the path. * @param p - fully qualified path p * @return - the remaining path without the beginning / * @throws IOException if the p is not prefixed with root */ String stripOutRoot(final Path p) throws IOException { try { checkPath(p); } catch (IllegalArgumentException e) { throw new IOException("Internal Error - path " + p + " should have been with URI: " + myUri); } String pathPart = p.toUri().getPath(); return (pathPart.length() == chRootPathPartString.length()) ? "" : pathPart .substring(chRootPathPartString.length() + (chRootPathPart.isRoot() ? 0 : 1)); }
/** * org.apache.hadoop.fs.Path assumes that there separator in file system naming and "/" is the separator. * When org.apache.hadoop.fs.Path sees "/" in path String, it splits into parent and name. As fileID is a random * String determined by Google and it can contain "/" itself, this method check if parent and name is separated and * restore "/" back to file ID. * * @param p * @return */ public static String toFileId(Path p) { if (p.isRoot()) { return ""; } final String format = "%s" + Path.SEPARATOR + "%s"; if (p.getParent() != null && StringUtils.isEmpty(p.getParent().getName())) { return p.getName(); } return String.format(format, toFileId(p.getParent()), p.getName()); }
/** * * Strip out the root from the path. * * @param p - fully qualified path p * @return - the remaining path without the beginning / */ public String stripOutRoot(final Path p) { try { checkPath(p); } catch (IllegalArgumentException e) { throw new RuntimeException("Internal Error - path " + p + " should have been with URI" + myUri); } String pathPart = p.toUri().getPath(); return (pathPart.length() == chRootPathPartString.length()) ? "" : pathPart.substring(chRootPathPartString.length() + (chRootPathPart.isRoot() ? 0 : 1)); }
/** * Create the output folder and optionally set ownership. */ private void createOutputPath(final Path path) throws IOException { if (filesUser == null && filesGroup == null) { outputFs.mkdirs(path); } else { Path parent = path.getParent(); if (!outputFs.exists(parent) && !parent.isRoot()) { createOutputPath(parent); } outputFs.mkdirs(path); if (filesUser != null || filesGroup != null) { // override the owner when non-null user/group is specified outputFs.setOwner(path, filesUser, filesGroup); } if (filesMode > 0) { outputFs.setPermission(path, new FsPermission(filesMode)); } } }
if (wlPath.isRoot()) { return(true);
/** * Validate that the file status cache contains all and only entries for a * given set of paths up to a common parent. * * @param statCache the cache * @param top the common parent at which to stop digging * @param paths the paths to compare against the cache */ private void checkCacheEntries(Map<URI, FileStatus> statCache, Path top, Path... paths) { Set<URI> expected = new HashSet<>(); for (Path path : paths) { Path p = fs.makeQualified(path); while (!p.isRoot() && !p.equals(top)) { expected.add(p.toUri()); p = p.getParent(); } expected.add(p.toUri()); } Set<URI> uris = statCache.keySet(); Set<URI> missing = new HashSet<>(uris); Set<URI> extra = new HashSet<>(expected); missing.removeAll(expected); extra.removeAll(uris); assertTrue("File status cache does not contain an entries for " + missing, missing.isEmpty()); assertTrue("File status cache contains extra extries: " + extra, extra.isEmpty()); }
/** * * @param path * @return return full path including the chroot */ protected Path fullPath(final Path path) { super.checkPath(path); return new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString) + path.toUri().getPath()); }
/** Returns true if the target is an ancestor of the source. */ private boolean isAncestor(PathData source, PathData target) { for (Path parent = source.path; (parent != null) && !parent.isRoot(); parent = parent.getParent()) { if (parent.equals(target.path)) { return true; } } return false; }
/** Returns true if the target is an ancestor of the source. */ private boolean isAncestor(PathData source, PathData target) { for (Path parent = source.path; (parent != null) && !parent.isRoot(); parent = parent.getParent()) { if (parent.equals(target.path)) { return true; } } return false; }
/** * * @param path * @return return full path including the chroot */ protected Path fullPath(final Path path) { super.checkPath(path); return new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString) + path.toUri().getPath()); }
/** * @param path * @return full path including the chroot */ protected Path fullPath(final Path path) { super.checkPath(path); return path.isAbsolute() ? new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString) + path.toUri().getPath()) : new Path(chRootPathPartString + workingDir.toUri().getPath(), path); }
/** * @param path * @return full path including the chroot */ protected Path fullPath(final Path path) { super.checkPath(path); return path.isAbsolute() ? new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString) + path.toUri().getPath()) : new Path(chRootPathPartString + workingDir.toUri().getPath(), path); }
/** * @param path * @return full path including the chroot */ protected Path fullPath(final Path path) { super.checkPath(path); return path.isAbsolute() ? new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString) + path.toUri().getPath()) : new Path(chRootPathPartString + workingDir.toUri().getPath(), path); }
/** * Recursive discovery of path depth * @param path path to measure. * @return depth, where "/" == 0. */ int depth(Path path) { if (path.isRoot()) { return 0; } else { return 1 + depth(path.getParent()); } }