List of usage examples for org.apache.hadoop.fs Path isRoot
public boolean isRoot()
From source file:com.facebook.presto.hive.metastore.file.FileHiveMetastore.java
License:Apache License
private static boolean isChildDirectory(Path parentDirectory, Path childDirectory) { if (parentDirectory.equals(childDirectory)) { return true; }//from w w w.j ava2 s .c om if (childDirectory.isRoot()) { return false; } return isChildDirectory(parentDirectory, childDirectory.getParent()); }
From source file:gobblin.source.extractor.extract.google.GoogleDriveFileSystem.java
License:Apache License
/** * 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./*from w ww.j a v a2 s. c o m*/ * * @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()); }
From source file:org.apache.gobblin.util.PathUtils.java
License:Apache License
/** * Returns the root path for the specified path. * * @see Path//from w ww.j a va 2 s. c om */ public static Path getRootPath(Path path) { if (path.isRoot()) { return path; } return getRootPath(path.getParent()); }
From source file:org.apache.impala.common.FileSystemUtil.java
License:Apache License
/** * Returns true if Path 'p' is a descendant of Path 'parent', false otherwise. * This function relies on Path.equals() which requires paths to have the same * schema and authority to compare equal. So both 'p' and 'parent' should either * be qualified or unqualified paths for this function to behave as expected. *///from w ww .j a v a2 s. co m public static boolean isDescendantPath(Path p, Path parent) { if (p == null || parent == null) return false; while (!p.isRoot() && p.depth() != parent.depth()) p = p.getParent(); if (p.isRoot()) return false; boolean result = p.equals(parent); if (!result && LOG.isTraceEnabled()) { // Add a message to the log if 'p' and 'parent' have inconsistent qualification. URI pUri = p.toUri(); URI parentUri = parent.toUri(); boolean sameScheme = Objects.equal(pUri.getScheme(), parentUri.getScheme()); boolean sameAuthority = Objects.equal(pUri.getAuthority(), parentUri.getAuthority()); if (!sameScheme || !sameAuthority) { LOG.trace("Inconsistent schema or authority for paths: " + p.toString() + " " + parent.toString()); } } return result; }
From source file:org.apache.slider.test.ContractTestUtils.java
License:Apache License
/** * Block any operation on the root path. This is a safety check * @param path path in the filesystem/* w w w.j a v a 2 s . c o m*/ * @param allowRootOperation can the root directory be manipulated? * @throws IOException if the operation was rejected */ public static void rejectRootOperation(Path path, boolean allowRootOperation) throws IOException { if (path.isRoot() && !allowRootOperation) { throw new IOException("Root directory operation rejected: " + path); } }
From source file:org.datacleaner.windows.HdfsUrlChooser.java
License:Open Source License
private Path getRoot() { Path path = getCurrentDirectory(); while (!path.isRoot()) { path = path.getParent();//from w w w. j ava2s. com } return path; }
From source file:org.shaf.server.controller.ActionFsController.java
License:Apache License
/** * Shows all directories and files defined under the specified directory. * //www.j a v a2 s.c o m * @param path * the base directory for listing content. * @return the view model. * @throws Exception * is the view constructing has failed. */ @RequestMapping(value = "/dir/{path}", method = RequestMethod.GET) public ModelAndView onDir(@PathVariable String path) throws Exception { LOG.debug("CALL: /fs/action/dir/{" + UriUtils.decodeArguments(path) + "}"); Path location = new Path(UriUtils.decodeArguments(path)); String current = location.toString(); String parent = location.isRoot() ? null : location.getParent().toString(); TextMatrix content = OPER.getDirContent(current); return ViewFileSystem.getDirView().addCurrentPath(current).addParentPath(parent).addDirContent(content) .info(super.getListDescription(content, "entity")); }
From source file:org.shaf.server.controller.ActionFsController.java
License:Apache License
/** * Shows a content of the specified file. * // w w w . j av a 2 s.c o m * @param path * the path to the file which content needs to be shown. * @return the view model. * @throws Exception * is the view constructing has failed. */ @RequestMapping(value = "/file/{path}", method = RequestMethod.GET) public ModelAndView onFile(@PathVariable String path) throws Exception { LOG.debug("CALL: /fs/action/file/{" + UriUtils.decodeArguments(path) + "}"); Path location = new Path(UriUtils.decodeArguments(path)); String current = location.toString(); String parent = location.isRoot() ? null : location.getParent().toString(); return ViewFileSystem.getFileView().addCurrentPath(current).addParentPath(parent) .addFileContent(OPER.getFileContent(current)).info("The file content."); }