Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blob-nio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release History

## 12.0.0-beta.3 (Unreleased)
- Added support for FileSystemProvider.checkAccess method
- Added support for file key on AzureBasicFileAttributes and AzureBlobFileAttributes

## 12.0.0-beta.2 (2020-08-13)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

package com.azure.storage.blob.nio;

import com.azure.core.util.logging.ClientLogger;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributeView;
Expand All @@ -18,6 +20,7 @@
* {@link #setTimes(FileTime, FileTime, FileTime)} is not supported.
*/
public final class AzureBasicFileAttributeView implements BasicFileAttributeView {
private final ClientLogger logger = new ClientLogger(AzureBasicFileAttributeView.class);

static final String NAME = "azureBasic";

Expand Down Expand Up @@ -61,6 +64,6 @@ public AzureBasicFileAttributes readAttributes() throws IOException {
*/
@Override
public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException {
throw new UnsupportedOperationException();
throw LoggingUtility.logError(logger, new UnsupportedOperationException());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@ public void setTier(AccessTier tier) throws IOException {
*/
@Override
public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException {
throw new UnsupportedOperationException();
throw LoggingUtility.logError(logger, new UnsupportedOperationException());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Path next() {

@Override
public void remove() {
throw new UnsupportedOperationException();
throw LoggingUtility.logError(logger, new UnsupportedOperationException());
}

private Path getNextListResult(BlobItem blobItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> a
*/
@Override
public Object getAttribute(String s) throws IOException {
throw new UnsupportedOperationException("FileStoreAttributeViews aren't supported.");
throw LoggingUtility.logError(logger, new UnsupportedOperationException("FileStoreAttributeViews aren't"
+ " supported."));
}

BlobContainerClient getContainerClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public final class AzureFileSystem extends FileSystem {
this.fileStores = this.initializeFileStores(config);
} catch (RuntimeException e) {
throw LoggingUtility.logError(logger, new IllegalArgumentException("There was an error parsing the "
+ "configurations map. Please ensure all fields are set to a legal value of the correct type."));
+ "configurations map. Please ensure all fields are set to a legal value of the correct type.", e));
} catch (IOException e) {
throw LoggingUtility.logError(logger,
new IOException("Initializing FileStores failed. FileSystem could not be opened.", e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be UnsupportedOperationException or AccessDeniedException?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AccessDenied

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand All @@ -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);
}
}
}

/**
Expand Down Expand Up @@ -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());
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ BlobClient toBlobClient() throws IOException {

String blobName = this.withoutRoot();
if (blobName.isEmpty()) {
throw new IOException("Cannot get a blob client to a path that only contains the root or is an empty path");
throw LoggingUtility.logError(logger, new IOException("Cannot get a blob client to a path that only "
+ "contains the root or is an empty path"));
}

return containerClient.getBlobClient(blobName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class APISpec extends Specification {

interceptorManager.close()
}

static Mono<ByteBuffer> collectBytesInBuffer(Flux<ByteBuffer> content) {
return FluxUtil.collectBytesInByteBufferStream(content).map { bytes -> ByteBuffer.wrap(bytes) }
}
Expand Down Expand Up @@ -372,13 +372,17 @@ class APISpec extends Specification {
}
}

Map<String, Object> initializeConfigMap() {
Map<String, Object> initializeConfigMap(HttpPipelinePolicy... policies) {
def config = [:]
config[AzureFileSystem.AZURE_STORAGE_HTTP_CLIENT] = getHttpClient()
def policyList = []
for (HttpPipelinePolicy policy : policies) {
policyList.push(policy)
}
if (testMode == TestMode.RECORD) {
config[AzureFileSystem.AZURE_STORAGE_HTTP_POLICIES] =
[interceptorManager.getRecordPolicy()] as HttpPipelinePolicy[]
policyList.push(interceptorManager.getRecordPolicy())
}
config[AzureFileSystem.AZURE_STORAGE_HTTP_POLICIES] = policyList as HttpPipelinePolicy[]
config[AzureFileSystem.AZURE_STORAGE_USE_HTTPS] = defaultEndpointTemplate.startsWith("https")
return config as Map<String, Object>
}
Expand Down
Loading