You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2023/01/24 05:44:57 UTC

[jclouds] branch master updated: Atomically replace objects in filesystem putBlob

This is an automated email from the ASF dual-hosted git repository.

gaul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git


The following commit(s) were added to refs/heads/master by this push:
     new 12de6ef74d Atomically replace objects in filesystem putBlob
12de6ef74d is described below

commit 12de6ef74db4faf93f4a4326760e183e3a82433a
Author: Andrew Gaul <ga...@apache.org>
AuthorDate: Sat Jan 21 22:49:28 2023 +0900

    Atomically replace objects in filesystem putBlob
    
    Fixes gaul/s3proxy#490.  This fixes a regression from
    41ce90ec360a46cb7b03f7cb8b66e01a113aa5b6.  Continue to support
    Windows logic although it is unclear if this is necessary.
---
 .../strategy/internal/FilesystemStorageStrategyImpl.java         | 9 +++++----
 1 file changed, 5 insertions(+), 4 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 8b9ada1e4a..1a58fb59d1 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
@@ -24,6 +24,7 @@ import static com.google.common.io.BaseEncoding.base16;
 import static java.nio.file.Files.createDirectories;
 import static java.nio.file.Files.getFileAttributeView;
 import static java.nio.file.Files.getPosixFilePermissions;
+import static java.nio.file.Files.move;
 import static java.nio.file.Files.probeContentType;
 import static java.nio.file.Files.readAttributes;
 import static java.nio.file.Files.setPosixFilePermissions;
@@ -44,6 +45,7 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.AccessDeniedException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.NoSuchFileException;
+import java.nio.file.StandardCopyOption;
 import java.nio.file.Path;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.nio.file.attribute.PosixFilePermission;
@@ -583,7 +585,8 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
             eTag = actualHashCode.asBytes();
          }
 
-         if (outputFile.exists()) {
+         // TODO: is this necessary?
+         if (isWindows() && outputFile.exists()) {
             delete(outputFile);
          }
 
@@ -599,9 +602,7 @@ public class FilesystemStorageStrategyImpl implements LocalStorageStrategy {
 
          setBlobAccess(containerName, tmpBlobName, access);
 
-         if (!tmpFile.renameTo(outputFile)) {
-            throw new IOException("Could not rename file " + tmpFile + " to " + outputFile);
-         }
+         move(tmpPath, outputFile.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
          tmpFile = null;
 
          return base16().lowerCase().encode(eTag);