Repository: jclouds
Updated Branches:
  refs/heads/master be96b9f27 -> 9feeee834


Set xattr before rename to make blob create atomic

Previously concurrent operations could expose an object before put had
completed.  Note that the temporary file is still exposed to the
client.


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/9feeee83
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/9feeee83
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/9feeee83

Branch: refs/heads/master
Commit: 9feeee834772e27bdb345ba7c7dd4717ae8158f0
Parents: be96b9f
Author: Andrew Gaul <[email protected]>
Authored: Tue Feb 2 21:56:24 2016 -0800
Committer: Andrew Gaul <[email protected]>
Committed: Thu Feb 4 23:14:54 2016 -0800

----------------------------------------------------------------------
 .../internal/FilesystemStorageStrategyImpl.java | 21 +++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/9feeee83/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java
----------------------------------------------------------------------
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 fc4a8aa..644159f 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
@@ -456,8 +456,9 @@ public class FilesystemStorageStrategyImpl implements 
LocalStorageStrategy {
       }
       File outputFile = getFileForBlobKey(containerName, blobKey);
       // TODO: should we use a known suffix to filter these out during list?
-      File tmpFile = getFileForBlobKey(containerName, blobKey + "-" + 
UUID.randomUUID());
-      Path outputPath = outputFile.toPath();
+      String tmpBlobName = blobKey + "-" + UUID.randomUUID();
+      File tmpFile = getFileForBlobKey(containerName, tmpBlobName);
+      Path tmpPath = tmpFile.toPath();
       HashingInputStream his = null;
       try {
          Files.createParentDirs(tmpFile);
@@ -480,20 +481,22 @@ public class FilesystemStorageStrategyImpl implements 
LocalStorageStrategy {
             delete(outputFile);
          }
 
-         if (!tmpFile.renameTo(outputFile)) {
-            throw new RuntimeException("Could not rename file " + tmpFile + " 
to " + outputFile);
-         }
-
-         UserDefinedFileAttributeView view = 
getUserDefinedFileAttributeView(outputPath);
+         UserDefinedFileAttributeView view = 
getUserDefinedFileAttributeView(tmpPath);
          if (view != null) {
             try {
                view.write(XATTR_CONTENT_MD5, 
ByteBuffer.wrap(actualHashCode.asBytes()));
                writeCommonMetadataAttr(view, blob);
             } catch (IOException e) {
-               logger.debug("xattrs not supported on %s", outputPath);
+               logger.debug("xattrs not supported on %s", tmpPath);
             }
          }
-         setBlobAccess(containerName, blobKey, BlobAccess.PRIVATE);
+
+         setBlobAccess(containerName, tmpBlobName, BlobAccess.PRIVATE);
+
+         if (!tmpFile.renameTo(outputFile)) {
+            throw new RuntimeException("Could not rename file " + tmpFile + " 
to " + outputFile);
+         }
+
          return base16().lowerCase().encode(actualHashCode.asBytes());
       } catch (IOException ex) {
          if (tmpFile != null) {

Reply via email to