@@ -475,8 +475,6 @@ type Fetcher struct {
475475 sumState sumState
476476}
477477
478- var Fetcher_ * Fetcher = NewFetcher ()
479-
480478func NewFetcher () * Fetcher {
481479 f := new (Fetcher )
482480 f .lookupCache = new (par.Cache [lookupCacheKey , Repo ])
@@ -498,42 +496,42 @@ func (f *Fetcher) AddWorkspaceGoSumFile(file string) {
498496
499497// Reset resets globals in the modfetch package, so previous loads don't affect
500498// contents of go.sum files.
501- func Reset () {
502- SetState (NewFetcher ())
499+ func ( f * Fetcher ) Reset () {
500+ f . SetState (NewFetcher ())
503501}
504502
505503// SetState sets the global state of the modfetch package to the newState, and returns the previous
506504// global state. newState should have been returned by SetState, or be an empty State.
507505// There should be no concurrent calls to any of the exported functions of this package with
508506// a call to SetState because it will modify the global state in a non-thread-safe way.
509- func SetState (newState * Fetcher ) (oldState * Fetcher ) {
507+ func ( f * Fetcher ) SetState (newState * Fetcher ) (oldState * Fetcher ) {
510508 if newState .lookupCache == nil {
511509 newState .lookupCache = new (par.Cache [lookupCacheKey , Repo ])
512510 }
513511 if newState .downloadCache == nil {
514512 newState .downloadCache = new (par.ErrCache [module.Version , string ])
515513 }
516514
517- Fetcher_ .mu .Lock ()
518- defer Fetcher_ .mu .Unlock ()
515+ f .mu .Lock ()
516+ defer f .mu .Unlock ()
519517
520518 oldState = & Fetcher {
521- goSumFile : Fetcher_ .goSumFile ,
522- workspaceGoSumFiles : Fetcher_ .workspaceGoSumFiles ,
523- lookupCache : Fetcher_ .lookupCache ,
524- downloadCache : Fetcher_ .downloadCache ,
525- sumState : Fetcher_ .sumState ,
519+ goSumFile : f .goSumFile ,
520+ workspaceGoSumFiles : f .workspaceGoSumFiles ,
521+ lookupCache : f .lookupCache ,
522+ downloadCache : f .downloadCache ,
523+ sumState : f .sumState ,
526524 }
527525
528- Fetcher_ .SetGoSumFile (newState .goSumFile )
529- Fetcher_ .workspaceGoSumFiles = newState .workspaceGoSumFiles
526+ f .SetGoSumFile (newState .goSumFile )
527+ f .workspaceGoSumFiles = newState .workspaceGoSumFiles
530528 // Uses of lookupCache and downloadCache both can call checkModSum,
531529 // which in turn sets the used bit on goSum.status for modules.
532530 // Set (or reset) them so used can be computed properly.
533- Fetcher_ .lookupCache = newState .lookupCache
534- Fetcher_ .downloadCache = newState .downloadCache
531+ f .lookupCache = newState .lookupCache
532+ f .downloadCache = newState .downloadCache
535533 // Set, or reset all fields on goSum. If being reset to empty, it will be initialized later.
536- Fetcher_ .sumState = newState .sumState
534+ f .sumState = newState .sumState
537535
538536 return oldState
539537}
@@ -666,32 +664,32 @@ func HaveSum(f *Fetcher, mod module.Version) bool {
666664// The entry's hash must be generated with a known hash algorithm.
667665// mod.Version may have a "/go.mod" suffix to distinguish sums for
668666// .mod and .zip files.
669- func RecordedSum (mod module.Version ) (sum string , ok bool ) {
670- Fetcher_ .mu .Lock ()
671- defer Fetcher_ .mu .Unlock ()
672- inited , err := Fetcher_ .initGoSum ()
667+ func ( f * Fetcher ) RecordedSum (mod module.Version ) (sum string , ok bool ) {
668+ f .mu .Lock ()
669+ defer f .mu .Unlock ()
670+ inited , err := f .initGoSum ()
673671 foundSum := ""
674672 if err != nil || ! inited {
675673 return "" , false
676674 }
677- for _ , goSums := range Fetcher_ .sumState .w {
675+ for _ , goSums := range f .sumState .w {
678676 for _ , h := range goSums [mod ] {
679677 if ! strings .HasPrefix (h , "h1:" ) {
680678 continue
681679 }
682- if ! Fetcher_ .sumState .status [modSum {mod , h }].dirty {
680+ if ! f .sumState .status [modSum {mod , h }].dirty {
683681 if foundSum != "" && foundSum != h { // conflicting sums exist
684682 return "" , false
685683 }
686684 foundSum = h
687685 }
688686 }
689687 }
690- for _ , h := range Fetcher_ .sumState .m [mod ] {
688+ for _ , h := range f .sumState .m [mod ] {
691689 if ! strings .HasPrefix (h , "h1:" ) {
692690 continue
693691 }
694- if ! Fetcher_ .sumState .status [modSum {mod , h }].dirty {
692+ if ! f .sumState .status [modSum {mod , h }].dirty {
695693 if foundSum != "" && foundSum != h { // conflicting sums exist
696694 return "" , false
697695 }
@@ -977,14 +975,14 @@ Outer:
977975
978976// TidyGoSum returns a tidy version of the go.sum file.
979977// A missing go.sum file is treated as if empty.
980- func TidyGoSum (keep map [module.Version ]bool ) (before , after []byte ) {
981- Fetcher_ .mu .Lock ()
982- defer Fetcher_ .mu .Unlock ()
983- before , err := lockedfile .Read (Fetcher_ .goSumFile )
978+ func ( f * Fetcher ) TidyGoSum (keep map [module.Version ]bool ) (before , after []byte ) {
979+ f .mu .Lock ()
980+ defer f .mu .Unlock ()
981+ before , err := lockedfile .Read (f .goSumFile )
984982 if err != nil && ! errors .Is (err , fs .ErrNotExist ) {
985983 base .Fatalf ("reading go.sum: %v" , err )
986984 }
987- after = tidyGoSum (Fetcher_ , before , keep )
985+ after = tidyGoSum (f , before , keep )
988986 return before , after
989987}
990988
@@ -1041,23 +1039,23 @@ func sumInWorkspaceModulesLocked(f *Fetcher, m module.Version) bool {
10411039// keep is used to check whether a sum should be retained in go.mod. It should
10421040// have entries for both module content sums and go.mod sums (version ends
10431041// with "/go.mod").
1044- func TrimGoSum (keep map [module.Version ]bool ) {
1045- Fetcher_ .mu .Lock ()
1046- defer Fetcher_ .mu .Unlock ()
1047- inited , err := Fetcher_ .initGoSum ()
1042+ func ( f * Fetcher ) TrimGoSum (keep map [module.Version ]bool ) {
1043+ f .mu .Lock ()
1044+ defer f .mu .Unlock ()
1045+ inited , err := f .initGoSum ()
10481046 if err != nil {
10491047 base .Fatalf ("%s" , err )
10501048 }
10511049 if ! inited {
10521050 return
10531051 }
10541052
1055- for m , hs := range Fetcher_ .sumState .m {
1053+ for m , hs := range f .sumState .m {
10561054 if ! keep [m ] {
10571055 for _ , h := range hs {
1058- Fetcher_ .sumState .status [modSum {m , h }] = modSumStatus {used : false , dirty : true }
1056+ f .sumState .status [modSum {m , h }] = modSumStatus {used : false , dirty : true }
10591057 }
1060- Fetcher_ .sumState .overwrite = true
1058+ f .sumState .overwrite = true
10611059 }
10621060 }
10631061}
0 commit comments