diff options
author | Benjamin Peterson <bp@benjamin.pe> | 2017-04-07 09:40:11 +0000 |
---|---|---|
committer | Marcel Hlopko <hlopko@google.com> | 2017-04-07 16:44:26 +0200 |
commit | 184faf617c4c90adfc33b7217aac53aab98354b2 (patch) | |
tree | f15dfd52ff3b398d8e3c547c179a7b1789ae49b6 /src/main/java/com/google | |
parent | 300d7573c3162f814e75131f8fd9782de3cb6297 (diff) |
Do not trample the PersistentMap journal
This fixes https://github.com/bazelbuild/bazel/issues/2660. Basically,
if we elect to keep the journal during PersistentMap.save(), we
shouldn't stomp over it the next time save() is called.
In writeJournal(), we now check if the journal file exists, and open
it in append mode if it does. Alternatively, we could simply not close
(and thus forget about) the journal in save(), but that would leak the
journal file handle if save() was never called with keepJournal()
returning false.
Change-Id: Id00732f161c8b5a082a6c109aee115591ace2ea7
PiperOrigin-RevId: 152480978
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/util/PersistentMap.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/PersistentMap.java b/src/main/java/com/google/devtools/build/lib/util/PersistentMap.java index 4a7348645f..4e3ad87d9b 100644 --- a/src/main/java/com/google/devtools/build/lib/util/PersistentMap.java +++ b/src/main/java/com/google/devtools/build/lib/util/PersistentMap.java @@ -18,7 +18,6 @@ import com.google.common.collect.ForwardingMap; import com.google.common.io.ByteStreams; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; - import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; @@ -193,7 +192,15 @@ public abstract class PersistentMap<K, V> extends ForwardingMap<K, V> { private void writeJournal() { try { if (journalOut == null) { - journalOut = createMapFile(journalFile); + if (journalFile.exists()) { + // The journal file was left around after the last save() because + // keepJournal() was true. Append to it. + journalOut = + new DataOutputStream(new BufferedOutputStream(journalFile.getOutputStream(true))); + } else { + // Create new journal. + journalOut = createMapFile(journalFile); + } } writeEntries(journalOut, journal); journalOut.flush(); |