From 92f48ca30762447864ef808cf62ccd1ca76cd23d Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 29 Apr 2013 00:42:21 -0700 Subject: Make sure that recompaction writes a pristine new depslog. ...even if a prior run of DepsLog::Recompact() exited without cleaning up, for example due to a crash or because someone added a `return true;` in the middle of the function while debugging. Or because someone hits ctrl-c during deps log recompaction. No test, because I can't think of a way to trigger this scenario programmatically. Part of issue #554. --- src/deps_log.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/deps_log.cc b/src/deps_log.cc index c52503b..d0d0202 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -244,6 +244,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; -- cgit v0.12