From dabc0ab6a9875f36697ddf1dfdc7c2a5a6241e7f Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 31 Jan 2021 22:27:14 +0900 Subject: [PATCH] Allow setting BlobAccess in LocalBlobStore.putBlob This addresses a race condition with filesystem users. --- .../strategy/internal/FilesystemStorageStrategyImpl.java | 7 ++++++- .../java/org/jclouds/blobstore/LocalStorageStrategy.java | 6 +++++- .../org/jclouds/blobstore/TransientStorageStrategy.java | 7 ++++++- .../java/org/jclouds/blobstore/config/LocalBlobStore.java | 3 +-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java index 90876df214..1c438df999 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java @@ -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); diff --git a/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java b/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java index 1a0ebd899f..3a1ef50c52 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/LocalStorageStrategy.java @@ -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 diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java index 66e15834c7..9780926e4d 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java @@ -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 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()); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java index 20f5fc2c63..6921827350 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java @@ -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();