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 f34b3aaf7c7..66a95baa920 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 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.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; @@ -574,10 +576,6 @@ public String putBlob(final String containerName, final Blob blob, BlobAccess ac eTag = actualHashCode.asBytes(); } - if (outputFile.exists()) { - delete(outputFile); - } - UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(tmpPath); if (view != null) { try { @@ -590,9 +588,7 @@ public String putBlob(final String containerName, final Blob blob, BlobAccess ac 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);