private void prepDestination(File path, boolean directory) throws IOException { if (directory) { path.mkdirs(); } else { if (!path.getParentFile().exists()) { path.getParentFile().mkdirs(); } if(!path.getParentFile().canWrite()) { throw new AccessDeniedException( String.format("Could not get write permissions for '%s'", path.getParentFile().getAbsolutePath())); } } }
public IndexInput openInput() throws IOException { IndexInput local = this.content; if (local == null) { throw new AccessDeniedException("Can't open a file still open for writing: " + fileName); } return local.clone(); }
@NotNull public static String exeFileToExePath(@NotNull File file) throws FileNotFoundException, AccessDeniedException { String path; if (file.exists()) { if (file.canExecute()) { path = file.getAbsolutePath(); } else { throw new AccessDeniedException(file.getAbsolutePath(), null, " is not executable"); } } else { throw new FileNotFoundException(file.getAbsolutePath() + " does not exist"); } return path; } }
public static void checkWritableDirectory( Path directory ) throws FileSystemException { if ( !exists( directory ) ) { throw new NoSuchFileException( directory.toString() ); } if ( isRegularFile( directory ) ) { throw new FileSystemException( directory.toString() + ": Not a directory" ); } if ( !isWritable( directory ) ) { throw new AccessDeniedException( directory.toString() ); } }
/** * A wrapper for {@link File#list()}. This java.io API returns null * when a dir is not a directory or for any I/O error. Instead of having * null check everywhere File#list() is used, we will add utility API * to get around this problem. For the majority of cases where we prefer * an IOException to be thrown. * @param dir directory for which listing should be performed * @return list of file names or empty string list * @exception AccessDeniedException for unreadable directory * @exception IOException for invalid directory or for bad disk */ public static String[] list(File dir) throws IOException { if (!canRead(dir)) { throw new AccessDeniedException(dir.toString(), null, FSExceptionMessages.PERMISSION_DENIED); } String[] fileNames = dir.list(); if(fileNames == null) { throw new IOException("Invalid directory or I/O error occurred for dir: " + dir.toString()); } return fileNames; }
final AccessDeniedException accessDeniedException = new AccessDeniedException(committedReadOffsetFile.getAbsolutePath(), null, e.getMessage()); throw new RuntimeException(accessDeniedException);
public PathContentProvider(String contentType, Path filePath, int bufferSize) throws IOException { super(contentType); if (!Files.isRegularFile(filePath)) throw new NoSuchFileException(filePath.toString()); if (!Files.isReadable(filePath)) throw new AccessDeniedException(filePath.toString()); this.filePath = filePath; this.fileSize = Files.size(filePath); this.bufferSize = bufferSize; }
@Override public void checkAccess(Path path, AccessMode... modes) throws IOException { for (AccessMode mode : modes) { if (mode == AccessMode.WRITE) { throw readOnly(); } else if (mode == AccessMode.EXECUTE) { throw new AccessDeniedException("Resources are not executable."); } } }
public IndexInput openInput() throws IOException { IndexInput local = this.content; if (local == null) { throw new AccessDeniedException("Can't open a file still open for writing: " + fileName); } return local.clone(); }
void assertOwner() throws AccessDeniedException { UserPrincipal user = this.attributes.getCurrentUser(); if (!this.getOwner().equals(user)) { throw new AccessDeniedException(this.path.toString()); } }
@Override public void mkDirectory(ISourceLocation uri) throws IOException { if (uri.getScheme().endsWith("+readonly")) { throw new AccessDeniedException(uri.toString()); } }
public PathContentProvider(String contentType, Path filePath, int bufferSize) throws IOException { super(contentType); if (!Files.isRegularFile(filePath)) throw new NoSuchFileException(filePath.toString()); if (!Files.isReadable(filePath)) throw new AccessDeniedException(filePath.toString()); this.filePath = filePath; this.fileSize = Files.size(filePath); this.bufferSize = bufferSize; }
public PathContentProvider(Path filePath, int bufferSize) throws IOException { if (!Files.isRegularFile(filePath)) throw new NoSuchFileException(filePath.toString()); if (!Files.isReadable(filePath)) throw new AccessDeniedException(filePath.toString()); this.filePath = filePath; this.fileSize = Files.size(filePath); this.bufferSize = bufferSize; }
public PathContentProvider(Path filePath, int bufferSize) throws IOException { if (!Files.isRegularFile(filePath)) throw new NoSuchFileException(filePath.toString()); if (!Files.isReadable(filePath)) throw new AccessDeniedException(filePath.toString()); this.filePath = filePath; this.fileSize = Files.size(filePath); this.bufferSize = bufferSize; }
break; case 5: exception = new AccessDeniedException(file, other, reason); break; case 6:
public LocalFileScpTargetStreamResolver(Path path, ScpFileOpener opener) throws IOException { LinkOption[] linkOptions = IoUtils.getLinkOptions(true); this.status = IoUtils.checkFileExists(path, linkOptions); if (status == null) { throw new AccessDeniedException("Receive target file path existence status cannot be determined: " + path); } this.path = path; this.opener = (opener == null) ? DefaultScpFileOpener.INSTANCE : opener; }
@Nonnull private static FileNode asFile(@Nullable Node node, GitPath path) throws NoSuchFileException, AccessDeniedException { if(node == null) throw new NoSuchFileException(path.toString()); if(node instanceof FileNode) return (FileNode) node; throw new AccessDeniedException(path.toString()); }
@Override public void remove(ISourceLocation uri) throws IOException { if (uri.getScheme().endsWith("+readonly")) { throw new AccessDeniedException(uri.toString()); } fileSystem.getFileSystem().remove(uri.getPath()); } }
public static boolean copy(GitPath source, GitPath target, Set<CopyOption> options) throws IOException { Node sourceNode = getNode(source); if(source.equals(target)) return false; if(target.isRoot()) throw new AccessDeniedException(target.toString()); GitPath targetParent = getParent(target); DirectoryNode targetDirectory = findDirectory(targetParent); Node targetNode = sourceNode.clone(targetDirectory); if(!targetDirectory.addChild(getFileName(target), targetNode, options.contains(REPLACE_EXISTING))) throw new FileAlreadyExistsException(target.toString()); return true; }
public static void delete(GitPath file) throws IOException { if(file.isRoot()) throw new AccessDeniedException(file.toString()); GitPath parentPath = getParent(file); Node parent = findNode(getParent(file)); if(parent == null || !parent.isDirectory() || !asDirectory(parent, parentPath).removeChild(getFileName(file))) throw new NoSuchFileException(file.toString()); }