(pkgs []string)
| 13 | ) |
| 14 | |
| 15 | func SyncLockfiles(pkgs []string) error { |
| 16 | lockfilePaths, err := collectLockfiles() |
| 17 | if err != nil { |
| 18 | return err |
| 19 | } |
| 20 | |
| 21 | latestPackages, err := latestPackages(lockfilePaths) |
| 22 | if err != nil { |
| 23 | return err |
| 24 | } |
| 25 | |
| 26 | pkgMap := make(map[string]bool) |
| 27 | for _, pkg := range pkgs { |
| 28 | pkgMap[pkg] = true |
| 29 | } |
| 30 | |
| 31 | for _, lockfilePath := range lockfilePaths { |
| 32 | var lockFile lock.File |
| 33 | if err := cuecfg.ParseFile(lockfilePath, &lockFile); err != nil { |
| 34 | return err |
| 35 | } |
| 36 | |
| 37 | changed := false |
| 38 | for key, latestPkg := range latestPackages { |
| 39 | if pkg, exists := lockFile.Packages[key]; exists { |
| 40 | name, _, found := searcher.ParseVersionedPackage(key) |
| 41 | if len(pkgMap) > 0 && (!pkgMap[key] && (found && !pkgMap[name])) { |
| 42 | continue |
| 43 | } |
| 44 | if pkg.LastModified != latestPkg.LastModified { |
| 45 | lockFile.Packages[key].AllowInsecure = latestPkg.AllowInsecure |
| 46 | lockFile.Packages[key].LastModified = latestPkg.LastModified |
| 47 | // PluginVersion is intentionally omitted |
| 48 | lockFile.Packages[key].Resolved = latestPkg.Resolved |
| 49 | lockFile.Packages[key].Source = latestPkg.Source |
| 50 | lockFile.Packages[key].Version = latestPkg.Version |
| 51 | lockFile.Packages[key].Systems = latestPkg.Systems |
| 52 | changed = true |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if changed { |
| 58 | if err = cuecfg.WriteFile(lockfilePath, lockFile); err != nil { |
| 59 | return err |
| 60 | } |
| 61 | fmt.Printf("Updated: %s\n", lockfilePath) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | func latestPackages(lockfilePaths []string) (map[string]*lock.Package, error) { |
| 69 | latestPackages := make(map[string]*lock.Package) |
no test coverage detected