Allow setting BlobAccess in LocalBlobStore.putBlob

This addresses a race condition with filesystem users.
This commit is contained in:
Andrew Gaul 2021-01-31 22:27:14 +09:00 committed by Andrew Gaul
parent 85666982ae
commit dabc0ab6a9
4 changed files with 18 additions and 5 deletions

View File

@ -522,6 +522,11 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
@Override
public String putBlob(final String containerName, final Blob blob) throws IOException {
return putBlob(containerName, blob, BlobAccess.PRIVATE);
}
@Override
public String putBlob(final String containerName, final Blob blob, BlobAccess access) throws IOException {
String blobKey = blob.getMetadata().getName();
Payload payload = blob.getPayload();
filesystemContainerNameValidator.validate(containerName);
@ -579,7 +584,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
}
}
setBlobAccess(containerName, tmpBlobName, BlobAccess.PRIVATE);
setBlobAccess(containerName, tmpBlobName, access);
if (!tmpFile.renameTo(outputFile)) {
throw new IOException("Could not rename file " + tmpFile + " to " + outputFile);

View File

@ -114,14 +114,18 @@ public interface LocalStorageStrategy {
*/
Blob getBlob(String containerName, String blobName);
@Deprecated
String putBlob(String containerName, Blob blob) throws IOException;
/**
* Write a {@link Blob} into a file
* @param container
* @param blob
* @param access
* @return etag of blob
* @throws IOException
*/
String putBlob(String containerName, Blob blob) throws IOException;
String putBlob(String containerName, Blob blob, BlobAccess access) throws IOException;
/**
* Remove blob named by the given key

View File

@ -165,6 +165,11 @@ public class TransientStorageStrategy implements LocalStorageStrategy {
@Override
public String putBlob(final String containerName, final Blob blob) throws IOException {
return putBlob(containerName, blob, BlobAccess.PRIVATE);
}
@Override
public String putBlob(final String containerName, final Blob blob, BlobAccess access) throws IOException {
byte[] payload;
HashCode actualHashCode;
HashingInputStream input = new HashingInputStream(Hashing.md5(), blob.getPayload().openStream());
@ -190,7 +195,7 @@ public class TransientStorageStrategy implements LocalStorageStrategy {
Map<String, Blob> map = containerToBlobs.get(containerName);
String blobName = newBlob.getMetadata().getName();
map.put(blobName, newBlob);
containerToBlobAccess.get(containerName).put(blobName, BlobAccess.PRIVATE);
containerToBlobAccess.get(containerName).put(blobName, access);
return base16().lowerCase().encode(actualHashCode.asBytes());
}

View File

@ -789,8 +789,7 @@ public final class LocalBlobStore implements BlobStore {
}
try {
String eTag = storageStrategy.putBlob(containerName, blob);
setBlobAccess(containerName, blobKey, options.getBlobAccess());
String eTag = storageStrategy.putBlob(containerName, blob, options.getBlobAccess());
return eTag;
} catch (IOException e) {
String message = e.getMessage();