Skip to content
Permalink
Browse files
Allow setting BlobAccess in LocalBlobStore.putBlob
This addresses a race condition with filesystem users.
  • Loading branch information
gaul committed Feb 1, 2021
1 parent 8566698 commit dabc0ab6a9875f36697ddf1dfdc7c2a5a6241e7f
Showing 4 changed files with 18 additions and 5 deletions.
@@ -522,6 +522,11 @@ private String putDirectoryBlob(final String containerName, final Blob blob) thr

@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 String putBlob(final String containerName, final Blob blob) throws IOExce
}
}

setBlobAccess(containerName, tmpBlobName, BlobAccess.PRIVATE);
setBlobAccess(containerName, tmpBlobName, access);

if (!tmpFile.renameTo(outputFile)) {
throw new IOException("Could not rename file " + tmpFile + " to " + outputFile);
@@ -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
@@ -165,6 +165,11 @@ public Blob getBlob(final String containerName, final String blobName) {

@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 String putBlob(final String containerName, final Blob blob) throws IOExce
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());
}

@@ -789,8 +789,7 @@ public String putBlob(String containerName, Blob blob, PutOptions options) {
}

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();

0 comments on commit dabc0ab

Please sign in to comment.