From 3cce2fa79f6e34a9e57849fc5e454d5a720a4410 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 15 Sep 2018 02:29:24 +0700 Subject: env: fix get package from database that return first match by prefix In case two packages have the same prefix, for example "a" and "a-a", the GetPackageFromDB will always return "a" when the parameter importPath is "a-a". This commit move the package name match by prefix to second loop. --- env.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/env.go b/env.go index 6efe1fc..d0d284b 100644 --- a/env.go +++ b/env.go @@ -280,14 +280,20 @@ func (env *Env) GetLocalPackage(importPath string) (pkg *Package, err error) { // func (env *Env) GetPackageFromDB(importPath, remoteURL string) (int, *Package) { for x := 0; x < len(env.pkgs); x++ { - if strings.HasPrefix(importPath, env.pkgs[x].ImportPath) { + if remoteURL == env.pkgs[x].RemoteURL { return x, env.pkgs[x] } + if importPath == env.pkgs[x].ImportPath { + return x, env.pkgs[x] + } + } - if remoteURL == env.pkgs[x].RemoteURL { + for x := 0; x < len(env.pkgs); x++ { + if strings.HasPrefix(importPath, env.pkgs[x].ImportPath) { return x, env.pkgs[x] } } + return -1, nil } -- cgit v1.3