-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Nio check access #18095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nio check access #18095
Changes from all commits
8d06f25
c0dc3dc
ffd7465
ba91298
1bab6e0
64e1a7b
e4d7198
22ecb7f
45c20a9
81b5ad2
bd31b45
82ddd75
5f16848
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import java.net.HttpURLConnection; | ||
| import java.net.URI; | ||
| import java.nio.channels.SeekableByteChannel; | ||
| import java.nio.file.AccessDeniedException; | ||
| import java.nio.file.AccessMode; | ||
| import java.nio.file.CopyOption; | ||
| import java.nio.file.DirectoryNotEmptyException; | ||
|
|
@@ -268,7 +269,7 @@ public Path getPath(URI uri) { | |
| @Override | ||
| public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> set, | ||
| FileAttribute<?>... fileAttributes) throws IOException { | ||
| throw new UnsupportedOperationException(); | ||
| throw LoggingUtility.logError(logger, new UnsupportedOperationException()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -366,14 +367,16 @@ public OutputStream newOutputStream(Path path, OpenOption... options) throws IOE | |
| StandardOpenOption.TRUNCATE_EXISTING); | ||
| for (OpenOption option : optionsList) { | ||
| if (!supportedOptions.contains(option)) { | ||
| throw new UnsupportedOperationException("Unsupported option: " + option.toString()); | ||
| throw LoggingUtility.logError(logger, new UnsupportedOperationException("Unsupported option: " | ||
| + option.toString())); | ||
| } | ||
| } | ||
|
|
||
| // Write and truncate must be specified | ||
| if (!optionsList.contains(StandardOpenOption.WRITE) | ||
| || !optionsList.contains(StandardOpenOption.TRUNCATE_EXISTING)) { | ||
| throw new IllegalArgumentException("Write and TruncateExisting must be specified to open an OutputStream"); | ||
| throw LoggingUtility.logError(logger, | ||
| new IllegalArgumentException("Write and TruncateExisting must be specified to open an OutputStream")); | ||
| } | ||
|
|
||
| AzureResource resource = new AzureResource(path); | ||
|
|
@@ -742,7 +745,7 @@ public void copy(Path source, Path destination, CopyOption... copyOptions) throw | |
| */ | ||
| @Override | ||
| public void move(Path path, Path path1, CopyOption... copyOptions) throws IOException { | ||
| throw new UnsupportedOperationException(); | ||
| throw LoggingUtility.logError(logger, new UnsupportedOperationException()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -754,7 +757,7 @@ public void move(Path path, Path path1, CopyOption... copyOptions) throws IOExce | |
| */ | ||
| @Override | ||
| public boolean isSameFile(Path path, Path path1) throws IOException { | ||
| throw new UnsupportedOperationException(); | ||
| throw LoggingUtility.logError(logger, new UnsupportedOperationException()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -781,15 +784,18 @@ public boolean isHidden(Path path) throws IOException { | |
| */ | ||
| @Override | ||
| public FileStore getFileStore(Path path) throws IOException { | ||
| throw new UnsupportedOperationException(); | ||
| throw LoggingUtility.logError(logger, new UnsupportedOperationException()); | ||
| } | ||
|
|
||
| /** | ||
| * Unsupported. | ||
| * Checks the existence, and optionally the accessibility, of a file. | ||
| * <p> | ||
| * This method may only be used to check the existence of a file. It is not possible to determine the permissions | ||
| * granted to a given client, so if any mode argument is specified, an {@link UnsupportedOperationException} will be | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be UnsupportedOperationException or AccessDeniedException?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AccessDenied
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (per the jdk docs for this method: "the requested access would be denied or the access cannot be determined because the Java virtual machine has insufficient privileges or other reasons." I think it's reasonable to put this under access cannot be determined) |
||
| * thrown. | ||
| * | ||
| * @param path path | ||
| * @param accessModes accessMode | ||
| * @throws UnsupportedOperationException Operation is not supported. | ||
| * @param path the path to the file to check | ||
| * @param accessModes The access modes to check; may have zero elements | ||
| * @throws NoSuchFileException if a file does not exist | ||
| * @throws java.nio.file.AccessDeniedException the requested access would be denied or the access cannot be | ||
| * determined because the Java virtual machine has insufficient privileges or other reasons | ||
|
|
@@ -798,7 +804,32 @@ public FileStore getFileStore(Path path) throws IOException { | |
| */ | ||
| @Override | ||
| public void checkAccess(Path path, AccessMode... accessModes) throws IOException { | ||
| throw new UnsupportedOperationException(); | ||
| if (accessModes != null && accessModes.length != 0) { | ||
| throw LoggingUtility.logError(logger, new AccessDeniedException("The access cannot be determined.")); | ||
| } | ||
| AzurePath.ensureFileSystemOpen(path); | ||
|
|
||
| /* | ||
| Some static utility methods in the jdk require checking access on a root. ReadAttributes is not supported on | ||
| roots as they are containers. Furthermore, we always assume that roots exist as they are verified at creation | ||
| and cannot be deleted by the file system. Thus, we prefer a short circuit for roots. | ||
| */ | ||
| if (path instanceof AzurePath && ((AzurePath) path).isRoot()) { | ||
| return; | ||
| } | ||
|
|
||
| // Read attributes already wraps BlobStorageException in an IOException. | ||
| try { | ||
| readAttributes(path, BasicFileAttributes.class); | ||
| } catch (IOException e) { | ||
| Throwable cause = e.getCause(); | ||
| if (cause instanceof BlobStorageException | ||
| && BlobErrorCode.BLOB_NOT_FOUND.equals(((BlobStorageException) cause).getErrorCode())) { | ||
| throw LoggingUtility.logError(logger, new NoSuchFileException(path.toString())); | ||
| } else { | ||
| throw LoggingUtility.logError(logger, e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -858,7 +889,7 @@ public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type | |
| } else if (type == AzureBlobFileAttributes.class) { | ||
| view = AzureBlobFileAttributeView.class; | ||
| } else { | ||
| throw new UnsupportedOperationException(); | ||
| throw LoggingUtility.logError(logger, new UnsupportedOperationException()); | ||
| } | ||
|
|
||
| /* | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.