mirror of https://github.com/apache/jclouds.git
JCLOUDS-1137: Handle TOCTOU during blobMetadata
A similar issue exists when getting a blob payload when a caller simultaneously removes the blob.
This commit is contained in:
parent
08e78c979e
commit
4874a1eb18
|
@ -32,6 +32,7 @@ import static org.jclouds.filesystem.util.Utils.setPublic;
|
|||
import static org.jclouds.util.Closeables2.closeQuietly;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -389,6 +390,8 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
|
|||
.contentLength(byteSource.size())
|
||||
.contentMD5(byteSource.hash(Hashing.md5()).asBytes());
|
||||
}
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
|
|
|
@ -245,18 +245,21 @@ public final class LocalBlobStore implements BlobStore {
|
|||
return storageStrategy.blobExists(containerName, key);
|
||||
}
|
||||
});
|
||||
SortedSet<StorageMetadata> contents = newTreeSet(transform(blobBelongingToContainer,
|
||||
new Function<String, StorageMetadata>() {
|
||||
SortedSet<StorageMetadata> contents = newTreeSet(FluentIterable.from(blobBelongingToContainer)
|
||||
.transform(new Function<String, StorageMetadata>() {
|
||||
@Override
|
||||
public StorageMetadata apply(String key) {
|
||||
Blob oldBlob = loadBlob(containerName, key);
|
||||
checkState(oldBlob != null, "blob " + key + " is not present although it was in the list of "
|
||||
+ containerName);
|
||||
if (oldBlob == null) {
|
||||
return null;
|
||||
}
|
||||
checkState(oldBlob.getMetadata() != null, "blob " + containerName + "/" + key + " has no metadata");
|
||||
MutableBlobMetadata md = BlobStoreUtils.copy(oldBlob.getMetadata());
|
||||
md.setSize(oldBlob.getMetadata().getSize());
|
||||
return md;
|
||||
}
|
||||
}));
|
||||
})
|
||||
.filter(Predicates.<StorageMetadata>notNull()));
|
||||
|
||||
String marker = null;
|
||||
if (options != null) {
|
||||
|
|
Loading…
Reference in New Issue