fix: go work duplicate prefix get err (#4487)

This commit is contained in:
godLei6
2024-12-19 09:17:50 +08:00
committed by GitHub
parent fd07a9c6e4
commit 9c4ed394a7
2 changed files with 58 additions and 2 deletions

View File

@@ -82,13 +82,15 @@ func getRealModule(workDir string, execRun execx.RunFunc) (*Module, error) {
if err != nil {
return nil, err
}
if workDir[len(workDir)-1] != os.PathSeparator {
workDir = workDir + string(os.PathSeparator)
}
for _, m := range modules {
realDir, err := pathx.ReadLink(m.Dir)
if err != nil {
return nil, fmt.Errorf("failed to read go.mod, dir: %s, error: %w", m.Dir, err)
}
realDir += string(os.PathSeparator)
if strings.HasPrefix(workDir, realDir) {
return &m, nil
}