From ac76a4fd2afff48a0d5db84592babe5cabef3a2c Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 5 Nov 2020 18:26:55 +0300 Subject: Fix snapshot extraction for subproject symlinked from git submodule --- libbuild2/version/snapshot.cxx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'libbuild2/version') 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. // -- cgit v1.1