summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/deps_log.cc7
-rw-r--r--src/deps_log_test.cc6
2 files changed, 13 insertions, 0 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc
index 9866540..8dc6e69 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -242,6 +242,11 @@ bool DepsLog::Recompact(const string& path, string* err) {
printf("Recompacting deps...\n");
string temp_path = path + ".recompact";
+
+ // OpenForWrite() opens for append. Make sure it's not appending to a
+ // left-over file from a previous recompaction attempt that crashed somehow.
+ unlink(temp_path.c_str());
+
DepsLog new_log;
if (!new_log.OpenForWrite(temp_path, err))
return false;
@@ -255,6 +260,8 @@ bool DepsLog::Recompact(const string& path, string* err) {
// Write out all deps again.
for (int old_id = 0; old_id < (int)deps_.size(); ++old_id) {
Deps* deps = deps_[old_id];
+ if (!deps) continue; // If nodes_[old_id] is a leaf, it has no deps.
+
if (!new_log.RecordDeps(nodes_[old_id], deps->mtime,
deps->node_count, deps->nodes)) {
new_log.Close();
diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc
index b3d6b74..14f1572 100644
--- a/src/deps_log_test.cc
+++ b/src/deps_log_test.cc
@@ -137,6 +137,12 @@ TEST_F(DepsLogTest, Recompact) {
deps.push_back(state.GetNode("foo.h"));
deps.push_back(state.GetNode("bar.h"));
log.RecordDeps(state.GetNode("out.o"), 1, deps);
+
+ deps.clear();
+ deps.push_back(state.GetNode("foo.h"));
+ deps.push_back(state.GetNode("baz.h"));
+ log.RecordDeps(state.GetNode("other_out.o"), 1, deps);
+
log.Close();
struct stat st;