Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomically replace objects in filesystem putBlob #162

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -574,7 +576,8 @@ public String putBlob(final String containerName, final Blob blob, BlobAccess ac
eTag = actualHashCode.asBytes();
}

if (outputFile.exists()) {
// TODO: is this necessary?
if (isWindows() && outputFile.exists()) {
delete(outputFile);
}

Expand All @@ -590,9 +593,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);
Expand Down