Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep .sum files for modules #101

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,7 @@ func validateNewName(versions []string, old, new string) error {
}

func cleanGoGetTmpFiles(modDir string) error {
// Remove all sum and tmp files
if err := removeAllGlob(filepath.Join(modDir, "*.sum")); err != nil {
return err
}
// Remove all tmp files
if err := removeAllGlob(filepath.Join(modDir, "*.*.tmp.*")); err != nil {
return err
}
Expand Down Expand Up @@ -545,6 +542,8 @@ func getPackage(ctx context.Context, logger *log.Logger, c installPackageConfig,
tmpModFilePath = filepath.Join(c.modDir, fmt.Sprintf("%s.%d.tmp.mod", name, i))
}

outSumFile := strings.TrimSuffix(outModFile, ".mod") + ".sum"

// If we don't have all information or update is set, resolve version.
var fetchedDirectives bingo.NonRequireDirectives
if target.Module.Version == "" || !strings.HasPrefix(target.Module.Version, "v") || target.Module.Path == "" || c.update != runner.NoUpdatePolicy {
Expand Down Expand Up @@ -603,7 +602,10 @@ func getPackage(ctx context.Context, logger *log.Logger, c installPackageConfig,

// We were working on tmp file, do atomic rename.
if err := os.Rename(tmpModFile.FileName(), outModFile); err != nil {
return errors.Wrap(err, "rename")
return errors.Wrap(err, "rename mod file")
}
if err := os.Rename(tmpModFile.SumFileName(), outSumFile); err != nil {
return errors.Wrap(err, "rename sum file")
}
return nil
}
Expand Down Expand Up @@ -731,6 +733,7 @@ const gitignore = `
# But not these files:
!.gitignore
!*.mod
!*.sum
!README.md
!Variables.mk
!variables.env
Expand Down
13 changes: 13 additions & 0 deletions pkg/bingo/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func CreateFromExistingOrNew(ctx context.Context, r *runner.Runner, logger *log.
if err := copyFile(existingFile, modFile); err != nil {
return nil, err
}
existingSumFile := sumFilePath(existingFile)
sumFile := sumFilePath(modFile)
if err := copyFile(existingSumFile, sumFile); err != nil && !os.IsNotExist(err) {
return nil, err
}
return OpenModFile(modFile)
}
logger.Printf("bingo tool module file %v is malformed; it will be recreated; err: %v\n", existingFile, err)
Expand All @@ -150,6 +155,10 @@ func CreateFromExistingOrNew(ctx context.Context, r *runner.Runner, logger *log.
return OpenModFile(modFile)
}

func sumFilePath(modFilePath string) string {
return strings.TrimSuffix(modFilePath, ".mod") + ".sum"
}

func copyFile(src, dst string) error {
source, err := os.Open(src)
if err != nil {
Expand Down Expand Up @@ -184,6 +193,10 @@ func (mf *ModFile) FileName() string {
return mf.filename
}

func (mf *ModFile) SumFileName() string {
return sumFilePath(mf.filename)
}

func (mf *ModFile) IsDirectivesAutoFetchDisabled() bool {
return mf.directivesAutoFetchDisabled
}
Expand Down