From 4ca5a5bc2991438602d3b1fdb56b91d2b425c52d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 17 Jul 2020 17:17:55 +0200 Subject: Fix race in path/mtime assignment and file_rule::match() --- libbuild2/target.ixx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libbuild2/target.ixx') diff --git a/libbuild2/target.ixx b/libbuild2/target.ixx index 3d92c78..94c54c0 100644 --- a/libbuild2/target.ixx +++ b/libbuild2/target.ixx @@ -582,6 +582,21 @@ namespace build2 return mtime_target::load_mtime (path ()); } + inline const path& path_target:: + path_mtime (path_type p, timestamp mt) const + { + // Because we use the presence of mtime to indicate the special "trust me, + // this file exists" situation, the order in which we do things is + // important. In particular, the fallback file_rule::match() will skip + // assigning the path if there is a valid timestamp. As a result, with the + // wrong order we may end up in a situation where the rule is matched but + // the path is not assigned. + // + const path_type& r (path (move (p))); + mtime (mt); + return r; + } + // exe // inline auto exe:: -- cgit v1.1