diff options
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 854e7d7733..768dbb5910 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -103,3 +103,4 @@ Yue Gan <yueg@google.com> Yun Peng <pcloudy@google.com> Dmitry Babkin <dbabkin@google.com> Klaus Aehlig <aehlig@google.com> +Robin Nabel <rnabel@ucdavis.edu> diff --git a/src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java b/src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java index 2dbd3208a7..011431013b 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java +++ b/src/main/java/com/google/devtools/build/lib/remote/blobstore/OnDiskBlobStore.java @@ -54,6 +54,11 @@ public final class OnDiskBlobStore implements SimpleBlobStore { @Override public void put(String key, long length, InputStream in) throws IOException { + Path target = toPath(key); + if (target.exists()) { + return; + } + // Write a temporary file first, and then rename, to avoid data corruption in case of a crash. Path temp = toPath(UUID.randomUUID().toString()); try (OutputStream out = temp.getOutputStream()) { @@ -61,8 +66,7 @@ public final class OnDiskBlobStore implements SimpleBlobStore { } // TODO(ulfjack): Fsync temp here before we rename it to avoid data loss in the case of machine // crashes (the OS may reorder the writes and the rename). - Path f = toPath(key); - temp.renameTo(f); + temp.renameTo(target); } @Override |