diff options
| author | Shulhan <ms@kilabit.info> | 2018-09-15 02:29:24 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-09-15 02:29:24 +0700 |
| commit | 3cce2fa79f6e34a9e57849fc5e454d5a720a4410 (patch) | |
| tree | 054e1b8392274d74581eca26cf70d05937fc3fb6 | |
| parent | 11103c19ce35e559ac068593515fa54399948a7b (diff) | |
| download | beku-3cce2fa79f6e34a9e57849fc5e454d5a720a4410.tar.xz | |
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.
| -rw-r--r-- | env.go | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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 } |
