diff options
Diffstat (limited to 'src/deps_log.cc')
-rw-r--r-- | src/deps_log.cc | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc index 0f10b5c..5706be4 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -24,6 +24,12 @@ #include "state.h" #include "util.h" +namespace { +const char kFileSignature[] = "# ninja deps v%d\n"; +const int kCurrentVersion = 1; +} // anonymous namespace + + bool DepsLog::OpenForWrite(const string& path, string* err) { file_ = fopen(path.c_str(), "ab"); if (!file_) { @@ -36,14 +42,12 @@ bool DepsLog::OpenForWrite(const string& path, string* err) { // end on Windows. Do that explicitly. fseek(file_, 0, SEEK_END); - /* XXX - if (ftell(log_file_) == 0) { - if (fprintf(log_file_, kFileSignature, kCurrentVersion) < 0) { + if (ftell(file_) == 0) { + if (fprintf(file_, kFileSignature, kCurrentVersion) < 0) { *err = strerror(errno); return false; } } - */ return true; } @@ -119,6 +123,22 @@ bool DepsLog::Load(const string& path, State* state, string* err) { return false; } + if (!fgets(buf, sizeof(buf), f)) { + *err = strerror(errno); + return false; + } + int version = 0; + if (sscanf(buf, kFileSignature, &version) != 1) { + *err = "unable to read file signature"; + return false; + } + if (version != kCurrentVersion) { + *err = "bad deps log version; starting over"; + // Don't report this as a failure. An empty deps log will cause + // us to rebuild the outputs anyway. + return true; + } + for (;;) { uint16_t size; if (fread(&size, 2, 1, f) < 1) |