Atomically replace objects in filesystem putBlob

Fixes gaul/s3proxy#490.  This fixes a regression from
41ce90ec36.  Continue to support
Windows logic although it is unclear if this is necessary.
This commit is contained in:
Andrew Gaul 2023-01-21 22:49:28 +09:00 committed by Andrew Gaul
parent 62632c9db6
commit 12de6ef74d
1 changed files with 5 additions and 4 deletions

View File

@ -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);