/** * Checks if the given path is properly formed. * * @param path The path to check * @throws InvalidPathException If the path is not properly formed */ public static void validatePath(String path) throws InvalidPathException { boolean invalid = (path == null || path.isEmpty()); if (!OSUtils.isWindows()) { invalid = (invalid || !path.startsWith(AlluxioURI.SEPARATOR)); } if (invalid) { throw new InvalidPathException(ExceptionMessage.PATH_INVALID.getMessage(path)); } }
fileInfo.setFileBlockInfos(getFileBlockInfoListInternal(inodePath)); } catch (InvalidPathException e) { throw new FileDoesNotExistException(e.getMessage(), e); resolution = mMountTable.resolve(uri); } catch (InvalidPathException e) { throw new FileDoesNotExistException(e.getMessage(), e);
return response; } catch (InvalidPathException e) { response.setInvalidPathError("Error: Invalid Path " + e.getLocalizedMessage()); return response; } catch (UnavailableException e) { return response; } catch (InvalidPathException e) { response.setInvalidPathException("Error: invalid path " + e.getMessage()); return response; } catch (AccessControlException e) {
throw new InvalidPathException(ExceptionMessage.DELETE_ROOT_DIRECTORY.getMessage()); LOG.warn("Failed to delete path from UFS: {}", e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); } catch (InvalidPathException e) { request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getLocalizedMessage()); getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); } catch (AlluxioException e) {
private void traverseWithoutLocking() throws InvalidPathException { if (mExistingInodes.isEmpty()) { mExistingInodes.add(mRoot); } for (int i = mExistingInodes.size(); i < mPathComponents.length; i++) { Inode lastInode = mExistingInodes.get(i - 1); if (lastInode.isFile()) { throw new InvalidPathException(String.format( "Traversal failed for path %s. Component %s(%s) is a file, not a directory.", mUri, i - 1, lastInode.getName())); } Optional<Inode> nextInode = mInodeStore.getChild(lastInode.asDirectory(), mPathComponents[i]); if (!nextInode.isPresent()) { return; } mExistingInodes.add(nextInode.get()); } }
/** * Tests {@link PathUtils#subtractPaths(String, String)} throws the right exception if an input * path is invalid or the second argument isn't a prefix of the first. */ @Test public void subtractPathsException() throws InvalidPathException { try { PathUtils.subtractPaths("", "/"); fail("\"\" should throw an InvalidPathException"); } catch (InvalidPathException e) { assertEquals(ExceptionMessage.PATH_INVALID.getMessage(""), e.getMessage()); } try { PathUtils.subtractPaths("/", "noslash"); fail("noslash should be an invalid path"); } catch (InvalidPathException e) { assertEquals(ExceptionMessage.PATH_INVALID.getMessage("noslash"), e.getMessage()); } try { PathUtils.subtractPaths("/a", "/not/a/prefix"); fail("subtractPaths should complain about the prefix not being a prefix"); } catch (RuntimeException e) { String expectedMessage = "Cannot subtract /not/a/prefix from /a because it is not a prefix"; assertEquals(expectedMessage, e.getMessage()); } }
return; } catch (InvalidPathException e) { request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getLocalizedMessage()); getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); return; } catch (InvalidPathException e) { request.setAttribute("InvalidPathException", "Error: invalid path " + e.getMessage()); getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response); } catch (AccessControlException e) {
File dstFile = new File(dstPath.getPath()); if (dstFile.exists() && !dstFile.isDirectory()) { throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
fail("Should not have been able to delete the root"); } catch (InvalidPathException e) { assertEquals(ExceptionMessage.DELETE_ROOT_DIRECTORY.getMessage(), e.getMessage());
@Override public MountPointInfo getMountPointInfo(AlluxioURI path) throws InvalidPathException { if (!mMountTable.isMountPoint(path)) { throw new InvalidPathException( ExceptionMessage.PATH_MUST_BE_MOUNT_POINT.getMessage(path)); } return getMountPointInfo(mMountTable.getMountTable().get(path.toString())); }
fail("Renaming to root should fail."); } catch (InvalidPathException e) { assertEquals(ExceptionMessage.RENAME_CANNOT_BE_TO_ROOT.getMessage(), e.getMessage()); fail("Should not be able to rename root"); } catch (InvalidPathException e) { assertEquals(ExceptionMessage.ROOT_CANNOT_BE_RENAMED.getMessage(), e.getMessage());
private void checkBucketIsAlluxioDirectory(String bucketPath) throws S3Exception { try { URIStatus status = mFileSystem.getStatus(new AlluxioURI(bucketPath)); if (!status.isFolder()) { throw new InvalidPathException("Bucket name is not a valid Alluxio directory."); } } catch (Exception e) { throw toBucketS3Exception(e, bucketPath); } }
.getMessage("hdfs://localhost", "hdfs://localhost"), e.getMessage()); .getMessage("s3a://localhost", "s3a://localhost"), e.getMessage());
/** * Creates a directory in the Alluxio filesystem space. It will not throw any exception if the * destination directory already exists. * * @param dstPath the {@link AlluxioURI} of the destination directory which will be created */ private void createDstDir(AlluxioURI dstPath) throws AlluxioException, IOException { try { mFileSystem.createDirectory(dstPath); } catch (FileAlreadyExistsException e) { // it's fine if the directory already exists } URIStatus dstStatus = mFileSystem.getStatus(dstPath); if (!dstStatus.isFolder()) { throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage()); } }
/** * Attempts to delete the file or directory with the specified path. * * @param cPath path to delete * @param recursive if true, will attempt to delete all children of the path * @return true if one or more files/directories were deleted; false otherwise * @throws IOException if the path failed to be deleted due to some constraint (ie. non empty * directory with recursive flag disabled) */ @Override public boolean delete(Path cPath, boolean recursive) throws IOException { LOG.info("delete({}, {})", cPath, recursive); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI path = new AlluxioURI(HadoopUtils.getPathWithoutScheme(cPath)); DeleteOptions options = DeleteOptions.defaults().setRecursive(recursive); try { mFileSystem.delete(path, options); return true; } catch (InvalidPathException e) { LOG.info("delete failed: {}", e.getMessage()); return false; } catch (FileDoesNotExistException e) { LOG.info("delete failed: {}", e.getMessage()); return false; } catch (AlluxioException e) { throw new IOException(e); } }
/** * Set the operation mode the given physical ufs. * * @param journalContext the journal context * @param ufsPath the physical ufs path (scheme and authority only) * @param ufsMode the ufs operation mode * @throws InvalidPathException if no managed ufs covers the given path */ public synchronized void setUfsMode(Supplier<JournalContext> journalContext, AlluxioURI ufsPath, UfsMode ufsMode) throws InvalidPathException { LOG.info("Set ufs mode for {} to {}", ufsPath, ufsMode); String root = ufsPath.getRootPath(); if (!mUfsRoots.contains(root)) { LOG.warn("No managed ufs for physical ufs path {}", root); throw new InvalidPathException(String.format("Unknown Ufs path %s", root)); } mState.applyAndJournal(journalContext, UpdateUfsModeEntry.newBuilder() .setUfsPath(ufsPath.getRootPath()) .setUfsMode(File.UfsMode.valueOf(ufsMode.name())) .build()); }
.equals(e.getMessage())) { throw e;
throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
fileInfo.setFileBlockInfos(getFileBlockInfoListInternal(inodePath)); } catch (InvalidPathException e) { throw new FileDoesNotExistException(e.getMessage(), e); resolution = mMountTable.resolve(uri); } catch (InvalidPathException e) { throw new FileDoesNotExistException(e.getMessage(), e);