diff options
author | Evan Martin <martine@danga.com> | 2013-01-07 19:04:24 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2013-04-08 22:01:39 (GMT) |
commit | afd206d99004d551afcfef55ec69ab65c4eb81d4 (patch) | |
tree | 56653ba4976d45a17aa5366a188010ec11ae13ae | |
parent | ab218230c4c6c3f0bb2a26215d1ac09e397e6065 (diff) | |
download | Ninja-afd206d99004d551afcfef55ec69ab65c4eb81d4.zip Ninja-afd206d99004d551afcfef55ec69ab65c4eb81d4.tar.gz Ninja-afd206d99004d551afcfef55ec69ab65c4eb81d4.tar.bz2 |
record and check depslog file version
Future-proofing against some change we may need to make later.
-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) |