From a4e72972f7263e41fef936c099f8862dbb6d2802 Mon Sep 17 00:00:00 2001 From: Bartlomiej Plotka Date: Tue, 21 Dec 2021 18:57:16 +0100 Subject: [PATCH] Fixed support for +incompatible modules. (#107) Fixes https://github.com/bwplotka/bingo/issues/100 Signed-off-by: Bartlomiej Plotka --- CHANGELOG.md | 7 +++++++ get.go | 33 ++++++++++++++++++++++++--------- pkg/bingo/mod.go | 5 +++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c48763a..de10ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ We use *breaking* word for marking changes that are not backward compatible (rel ## Unreleased +## [v0.5.2](https://github.com/bwplotka/bingo/releases/tag/v0.5.2) - 2021.12.21 + +### Fixed + +* Fixed support for modules / packages with upper case in it and Go 1.17 logic. +* Fixed support for modules with +incompatible version. + ## [v0.5.1](https://github.com/bwplotka/bingo/releases/tag/v0.5.1) - 2021.07.20 ### Added diff --git a/get.go b/get.go index f95fc9a..5baa10f 100644 --- a/get.go +++ b/get.go @@ -476,13 +476,14 @@ func resolveInGoModCache(logger *log.Logger, verbose bool, update runner.GetUpda }() { modMetaDir := filepath.Join(modMetaCache, lookupModulePath, "@v") if _, err := os.Stat(modMetaDir); err != nil { - if os.IsNotExist(err) { - if verbose { - logger.Println("resolveInGoModCache:", modMetaDir, "directory does not exists") - } - continue + if !os.IsNotExist(err) { + return err } - return err + if verbose { + logger.Println("resolveInGoModCache:", modMetaDir, "directory does not exists") + } + continue + } if verbose { logger.Println("resolveInGoModCache: Found", modMetaDir, "directory") @@ -506,14 +507,28 @@ func resolveInGoModCache(logger *log.Logger, verbose bool, update runner.GetUpda // Look for .info files that have exact version or sha. if strings.HasPrefix(target.Module.Version, "v") { if _, err := os.Stat(filepath.Join(modMetaDir, target.Module.Version+".info")); err != nil { - if os.IsNotExist(err) { + if !os.IsNotExist(err) { + return err + } + + if verbose { + logger.Println("resolveInGoModCache:", filepath.Join(modMetaDir, target.Module.Version+".info"), + "file not exists. Looking for +incompatible info file") + } + + // Try +incompatible. + if _, err := os.Stat(filepath.Join(modMetaDir, target.Module.Version+"+incompatible.info")); err != nil { + if !os.IsNotExist(err) { + return err + } + if verbose { - logger.Println("resolveInGoModCache:", filepath.Join(modMetaDir, target.Module.Version+".info"), + logger.Println("resolveInGoModCache:", filepath.Join(modMetaDir, target.Module.Version+"+incompatible.info"), "file not exists. Looking for different module") } continue } - return err + target.Module.Version += "+incompatible" } target.Module.Path = modulePath target.RelPath = strings.TrimPrefix(strings.TrimPrefix(target.RelPath, target.Module.Path), "/") diff --git a/pkg/bingo/mod.go b/pkg/bingo/mod.go index 972fbc6..08085af 100644 --- a/pkg/bingo/mod.go +++ b/pkg/bingo/mod.go @@ -286,6 +286,11 @@ func (mf *ModFile) DirectPackage() *Package { // Flush saves all changes made to parsed syntax and reloads the parsed file. func (mf *ModFile) Flush() error { + if mf.m == nil { + // Nothing to flush. + // Happens when previous flush had errors. + return nil + } newB := modfile.Format(mf.m.Syntax) if err := mf.f.Truncate(0); err != nil { return errors.Wrap(err, "truncate")