Skip to content

Commit

Permalink
fix: go list保底
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhaoxuan authored and iseki0 committed Jan 7, 2025
1 parent 3338b06 commit 469b062
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
9 changes: 8 additions & 1 deletion module/go_mod/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ func (Inspector) CheckDir(dir string) bool {
}

func (Inspector) InspectProject(ctx context.Context) error {
if err := buildScan(ctx); err != nil {
task := model.UseInspectionTask(ctx)
if task.IsNoBuild() {
if err := baseScan(ctx); err != nil {
return err
}
} else {
if err := buildScan(ctx); err != nil {
if err := baseScan(ctx); err != nil {
return err
}
}
}
return nil
}
Expand Down
14 changes: 14 additions & 0 deletions module/go_mod/gotree.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,25 @@ import (
"golang.org/x/mod/modfile"
)

func goModTidy(path string) error {
_, err := os.Stat(path)
if err != nil {
cmd := exec.Command("go", "mod", "tidy")
if err := cmd.Start(); err != nil {
return err
}
}
return nil
}
func buildScan(ctx context.Context) error {
task := model.UseInspectionTask(ctx)
logger := logctx.Use(ctx)
modFilePath := filepath.Join(task.Dir(), "go.mod")
logger.Debug("Reading go.mod", zap.String("path", modFilePath))
if err := goModTidy(filepath.Join(task.Dir(), "go.sum")); err != nil {
logger.Error("go mod tidy error :", zap.Error(err))
return err
}
modName, err := getModInfo(modFilePath)
if err != nil {
logger.Error("get mod info error :", zap.Error(err))
Expand Down
24 changes: 0 additions & 24 deletions module/go_mod/setPrivatePath.go

This file was deleted.

0 comments on commit 469b062

Please sign in to comment.