From 98bb8487f62e55aed311fc36ce371884c1344764 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Sat, 23 Apr 2011 11:36:49 +0100 Subject: [PATCH] Close() and unlink() files in ways that make Windows happy This will make the build log compaction work on Windows. It will also make the tests no longer leave a temp log file around. --- src/build_log.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/build_log.cc b/src/build_log.cc index 9add945..6943550 100644 --- a/src/build_log.cc +++ b/src/build_log.cc @@ -37,6 +37,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) { return true; // Do nothing, report success. if (needs_recompaction_) { + Close(); if (!Recompact(path, err)) return false; } @@ -129,6 +130,8 @@ bool BuildLog::Load(const string& path, string* err) { if (total_entry_count > unique_entry_count * kCompactionRatio) needs_recompaction_ = true; + fclose(file); + return true; } @@ -159,6 +162,10 @@ bool BuildLog::Recompact(const string& path, string* err) { } fclose(f); + if (unlink(path.c_str()) < 0) { + *err = strerror(errno); + return false; + } if (rename(temp_path.c_str(), path.c_str()) < 0) { *err = strerror(errno); -- 2.7.4