mirror of https://github.com/apache/jclouds.git
Allow setting BlobAccess in LocalBlobStore.putBlob
This addresses a race condition with filesystem users.
This commit is contained in:
parent
85666982ae
commit
dabc0ab6a9
|
@ -522,6 +522,11 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String putBlob(final String containerName, final Blob blob) throws IOException {
|
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();
|
String blobKey = blob.getMetadata().getName();
|
||||||
Payload payload = blob.getPayload();
|
Payload payload = blob.getPayload();
|
||||||
filesystemContainerNameValidator.validate(containerName);
|
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)) {
|
if (!tmpFile.renameTo(outputFile)) {
|
||||||
throw new IOException("Could not rename file " + tmpFile + " to " + outputFile);
|
throw new IOException("Could not rename file " + tmpFile + " to " + outputFile);
|
||||||
|
|
|
@ -114,14 +114,18 @@ public interface LocalStorageStrategy {
|
||||||
*/
|
*/
|
||||||
Blob getBlob(String containerName, String blobName);
|
Blob getBlob(String containerName, String blobName);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
String putBlob(String containerName, Blob blob) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a {@link Blob} into a file
|
* Write a {@link Blob} into a file
|
||||||
* @param container
|
* @param container
|
||||||
* @param blob
|
* @param blob
|
||||||
|
* @param access
|
||||||
* @return etag of blob
|
* @return etag of blob
|
||||||
* @throws IOException
|
* @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
|
* Remove blob named by the given key
|
||||||
|
|
|
@ -165,6 +165,11 @@ public class TransientStorageStrategy implements LocalStorageStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String putBlob(final String containerName, final Blob blob) throws IOException {
|
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;
|
byte[] payload;
|
||||||
HashCode actualHashCode;
|
HashCode actualHashCode;
|
||||||
HashingInputStream input = new HashingInputStream(Hashing.md5(), blob.getPayload().openStream());
|
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);
|
Map<String, Blob> map = containerToBlobs.get(containerName);
|
||||||
String blobName = newBlob.getMetadata().getName();
|
String blobName = newBlob.getMetadata().getName();
|
||||||
map.put(blobName, newBlob);
|
map.put(blobName, newBlob);
|
||||||
containerToBlobAccess.get(containerName).put(blobName, BlobAccess.PRIVATE);
|
containerToBlobAccess.get(containerName).put(blobName, access);
|
||||||
return base16().lowerCase().encode(actualHashCode.asBytes());
|
return base16().lowerCase().encode(actualHashCode.asBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -789,8 +789,7 @@ public final class LocalBlobStore implements BlobStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String eTag = storageStrategy.putBlob(containerName, blob);
|
String eTag = storageStrategy.putBlob(containerName, blob, options.getBlobAccess());
|
||||||
setBlobAccess(containerName, blobKey, options.getBlobAccess());
|
|
||||||
return eTag;
|
return eTag;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
|
|
Loading…
Reference in New Issue