diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-11-05 18:26:55 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2020-11-06 17:56:39 +0300 |
commit | ac76a4fd2afff48a0d5db84592babe5cabef3a2c (patch) | |
tree | b82daec56a48c17a0bc442238330a02de6e247f4 /libbuild2/version | |
parent | f63face55f8d1c2d2f53666399f16fa86ed33faa (diff) |
Fix snapshot extraction for subproject symlinked from git submodule
Diffstat (limited to 'libbuild2/version')
-rw-r--r-- | libbuild2/version/snapshot.cxx | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/libbuild2/version/snapshot.cxx b/libbuild2/version/snapshot.cxx index 9234460..3a885b5 100644 --- a/libbuild2/version/snapshot.cxx +++ b/libbuild2/version/snapshot.cxx @@ -19,10 +19,27 @@ namespace build2 snapshot extract_snapshot (const scope& rs) { - // Ignore errors when checking for existence since we may be iterating - // over directories past any reasonable project boundaries. + // Resolve the path symlink components to make sure that if we are + // extracting snapshot for a subproject which is symlinked from the git + // submodule, then we end up with a root of the git submodule repository + // rather than the containing repository root. // - for (dir_path d (rs.src_path ()); !d.empty (); d = d.directory ()) + dir_path d (rs.src_path ()); + + try + { + d.realize (); + } + catch (const invalid_path&) // Some component doesn't exist. + { + return snapshot (); + } + catch (const system_error& e) + { + fail << "unable to obtain real path for " << d << ": " << e; + } + + for (; !d.empty (); d = d.directory ()) { // .git can be either a directory or a file in case of a submodule. // |