From a8aec556702a8cb3fd03562e79f53446fbc3cb26 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Thu, 25 Oct 2018 16:00:45 -0700 Subject: [PATCH] builder: improve isLocalBundle checks based on testing Some testcases showed these checks were incomplete and not handling corner cases. Improve the logic of these checks to comply with the new tests. Signed-off-by: Matthew Johnson --- builder/bundle_control.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/builder/bundle_control.go b/builder/bundle_control.go index 4544afa..61e9340 100644 --- a/builder/bundle_control.go +++ b/builder/bundle_control.go @@ -163,7 +163,13 @@ func (b *Builder) getBundlePath(bundle string) (string, error) { // isLocalBundle checks to see if a bundle filepath is a local bundle definition or package file func (b *Builder) isLocalBundle(path string) bool { - return strings.HasPrefix(path, b.Config.Mixer.LocalBundleDir) || b.isLocalPackagePath(path) + if strings.HasPrefix(path, b.Config.Mixer.LocalBundleDir) { + // the path must be longer than the localbundledir by at least + // 2 so a bundle name follows the localbundledir prefix after the + // slash (/) + return len(path)-len(b.Config.Mixer.LocalBundleDir) >= 2 + } + return b.isLocalPackagePath(path) } func getBundleSetKeys(set bundleSet) []string { @@ -184,7 +190,7 @@ func getBundleSetKeysSorted(set bundleSet) []string { // isLocalPackagePath checks if path is a local-packages definition file func (b *Builder) isLocalPackagePath(path string) bool { - return strings.HasSuffix(path, b.LocalPackagesFile) + return filepath.Base(path) == b.LocalPackagesFile } // isUpstreamPackagePath checks if path is an upstream packages definition file