From 310452542b26cb0fa96e214b3d8f8dc1da1a9895 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 5 Oct 2024 00:34:34 -0400 Subject: [PATCH] lang: gapi: Rebase to the common path prefix When the modules dir is not within the main base, we don't correctly choose the common base path. As a result, we should choose something common for our internal path representation. --- lang/gapi/gapi.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lang/gapi/gapi.go b/lang/gapi/gapi.go index ca90ac46..e297028c 100644 --- a/lang/gapi/gapi.go +++ b/lang/gapi/gapi.go @@ -384,9 +384,27 @@ func (obj *GAPI) Cli(info *gapi.Info) (*gapi.Deploy, error) { //} //logf("tree:\n%s", tree) - dst, err := util.Rebase(src, output.Base, "/") + commonBase := util.CommonPathPrefix(src, output.Base) + //logf("src:\n%s", src) + //logf("base:\n%s", output.Base) + //logf("common:\n%s", commonBase) + //commonBase = output.Base // old method! + // NOTE: Instead of commonBase, we used to use output.Base here, + // but it seems this breaks if the modules path is not inside + // the normal code base. Such as if the src is: + // /etc/mgmt/modules/github.com/purpleidea/mgmt/modules/misc/main.mcl + // and the base is: /etc/mgmt/main/ if we run the mgmt binary + // with: mgmt run lang --module-path '/etc/mgmt/modules/' /etc/mgmt/main/ + // for example. + // NOTE: We could possibly always rebase onto "/", but we'd like + // to eliminate the local path structure from our deploys for a + // weak kind of privacy of that users directory structure. + dst, err := util.Rebase(src, commonBase, "/") if err != nil { // possible programming error + logf("src:\n%s", src) + logf("base:\n%s", output.Base) + logf("common:\n%s", commonBase) return nil, errwrap.Wrapf(err, "malformed source file path: `%s`", src) }