diff options
author | Nico Weber <nicolasweber@gmx.de> | 2013-04-30 16:11:09 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2013-05-01 18:07:31 (GMT) |
commit | 1eaacc8ccf26363ae3a820675721164873a31f3d (patch) | |
tree | aafcbd40e4faa4da866c95dbe2a64a3889719f3f /src/deps_log.cc | |
parent | f70a90edc6681fef7e75c7bc7f2860d40c2490ee (diff) | |
download | Ninja-1eaacc8ccf26363ae3a820675721164873a31f3d.zip Ninja-1eaacc8ccf26363ae3a820675721164873a31f3d.tar.gz Ninja-1eaacc8ccf26363ae3a820675721164873a31f3d.tar.bz2 |
Keep a DepsLog's data valid after a call to DepsLog::Recompact().
Previously, a DepsLog would become invalid after Recompact() was called,
due to Recompact() making all node ids refer to a temporary DepsLog
object constructed in Recompact().
Diffstat (limited to 'src/deps_log.cc')
-rw-r--r-- | src/deps_log.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/deps_log.cc b/src/deps_log.cc index fd7d107..7dbd5b2 100644 --- a/src/deps_log.cc +++ b/src/deps_log.cc @@ -250,12 +250,11 @@ bool DepsLog::Recompact(const string& path, string* err) { if (!new_log.OpenForWrite(temp_path, err)) return false; - // Clear all known ids so that new ones can be reassigned. - for (vector<Node*>::iterator i = nodes_.begin(); - i != nodes_.end(); ++i) { + // Clear all known ids so that new ones can be reassigned. The new indices + // will refer to the ordering in new_log, not in the current log. + for (vector<Node*>::iterator i = nodes_.begin(); i != nodes_.end(); ++i) (*i)->set_id(-1); - } - + // Write out all deps again. for (int old_id = 0; old_id < (int)deps_.size(); ++old_id) { Deps* deps = deps_[old_id]; @@ -270,6 +269,10 @@ bool DepsLog::Recompact(const string& path, string* err) { new_log.Close(); + // All nodes now have ids that refer to new_log, so steal its data. + deps_.swap(new_log.deps_); + nodes_.swap(new_log.nodes_); + if (unlink(path.c_str()) < 0) { *err = strerror(errno); return false; |