summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2013-07-24 21:07:12 (GMT)
committerNico Weber <thakis@chromium.org>2013-07-24 21:07:12 (GMT)
commit2eecb07bdaedca1a37cf499ce7d6e6491e2046c8 (patch)
tree6bf3cc720adc6b38aaa9305e53dfbbcda7a9ede5
parentf6f00aa40f0c541df06747228b1cc928d4972b3e (diff)
downloadNinja-2eecb07bdaedca1a37cf499ce7d6e6491e2046c8.zip
Ninja-2eecb07bdaedca1a37cf499ce7d6e6491e2046c8.tar.gz
Ninja-2eecb07bdaedca1a37cf499ce7d6e6491e2046c8.tar.bz2
Build log write error checking.
Like f6f00aa40f0c541df06, but for the build log instead of the deps log.
-rw-r--r--src/build.cc7
-rw-r--r--src/build_log.cc21
-rw-r--r--src/build_log.h4
3 files changed, 21 insertions, 11 deletions
diff --git a/src/build.cc b/src/build.cc
index 67e4634..45f6849 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -784,8 +784,11 @@ bool Builder::FinishCommand(CommandRunner::Result* result, string* err) {
disk_interface_->RemoveFile(rspfile);
if (scan_.build_log()) {
- scan_.build_log()->RecordCommand(edge, start_time, end_time,
- restat_mtime);
+ if (!scan_.build_log()->RecordCommand(edge, start_time, end_time,
+ restat_mtime)) {
+ *err = string("Error writing to build log: ") + strerror(errno);
+ return false;
+ }
}
if (!deps_type.empty() && !config_.dry_run) {
diff --git a/src/build_log.cc b/src/build_log.cc
index 6fb179a..1374bd0 100644
--- a/src/build_log.cc
+++ b/src/build_log.cc
@@ -136,7 +136,7 @@ bool BuildLog::OpenForWrite(const string& path, string* err) {
return true;
}
-void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time,
+bool BuildLog::RecordCommand(Edge* edge, int start_time, int end_time,
TimeStamp restat_mtime) {
string command = edge->EvaluateCommand(true);
uint64_t command_hash = LogEntry::HashCommand(command);
@@ -156,9 +156,12 @@ void BuildLog::RecordCommand(Edge* edge, int start_time, int end_time,
log_entry->end_time = end_time;
log_entry->restat_mtime = restat_mtime;
- if (log_file_)
- WriteEntry(log_file_, *log_entry);
+ if (log_file_) {
+ if (!WriteEntry(log_file_, *log_entry))
+ return false;
+ }
}
+ return true;
}
void BuildLog::Close() {
@@ -341,10 +344,10 @@ BuildLog::LogEntry* BuildLog::LookupByOutput(const string& path) {
return NULL;
}
-void BuildLog::WriteEntry(FILE* f, const LogEntry& entry) {
- fprintf(f, "%d\t%d\t%d\t%s\t%" PRIx64 "\n",
+bool BuildLog::WriteEntry(FILE* f, const LogEntry& entry) {
+ return fprintf(f, "%d\t%d\t%d\t%s\t%" PRIx64 "\n",
entry.start_time, entry.end_time, entry.restat_mtime,
- entry.output.c_str(), entry.command_hash);
+ entry.output.c_str(), entry.command_hash) > 0;
}
bool BuildLog::Recompact(const string& path, string* err) {
@@ -366,7 +369,11 @@ bool BuildLog::Recompact(const string& path, string* err) {
}
for (Entries::iterator i = entries_.begin(); i != entries_.end(); ++i) {
- WriteEntry(f, *i->second);
+ if (!WriteEntry(f, *i->second)) {
+ *err = strerror(errno);
+ fclose(f);
+ return false;
+ }
}
fclose(f);
diff --git a/src/build_log.h b/src/build_log.h
index 6eae89f..eeac5b3 100644
--- a/src/build_log.h
+++ b/src/build_log.h
@@ -37,7 +37,7 @@ struct BuildLog {
~BuildLog();
bool OpenForWrite(const string& path, string* err);
- void RecordCommand(Edge* edge, int start_time, int end_time,
+ bool RecordCommand(Edge* edge, int start_time, int end_time,
TimeStamp restat_mtime = 0);
void Close();
@@ -69,7 +69,7 @@ struct BuildLog {
LogEntry* LookupByOutput(const string& path);
/// Serialize an entry into a log file.
- void WriteEntry(FILE* f, const LogEntry& entry);
+ bool WriteEntry(FILE* f, const LogEntry& entry);
/// Rewrite the known log entries, throwing away old data.
bool Recompact(const string& path, string* err);