summaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/tools/internal/imports
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-09-08 20:53:25 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-09-08 20:53:25 +0200
commita6429b5410062cb8067e6dbbc9999d7d579a751d (patch)
treec10458d8a5e41ec561b0d139d83547353fdb69bc /vendor/golang.org/x/tools/internal/imports
parent[bugfix] check for nil notification (#4417) (diff)
downloadgotosocial-a6429b5410062cb8067e6dbbc9999d7d579a751d.tar.xz
[chore] update dependencies (#4422)
- github.com/jackc/pgx/v5 v5.7.5 -> v5.7.6 - github.com/ncruces/go-sqlite3 v0.28.0 -> v0.29.0 - github.com/tdewolff/minify/v2 v2.24.2 -> v2.24.3 - golang.org/x/oauth2 v0.30.0 -> v0.31.0 - golang.org/x/sys v0.35.0 -> v0.36.0 - golang.org/x/text v0.28.0 -> v0.29.0 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4422 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/golang.org/x/tools/internal/imports')
-rw-r--r--vendor/golang.org/x/tools/internal/imports/source_modindex.go47
1 files changed, 22 insertions, 25 deletions
diff --git a/vendor/golang.org/x/tools/internal/imports/source_modindex.go b/vendor/golang.org/x/tools/internal/imports/source_modindex.go
index 05229f06c..ca745d4a1 100644
--- a/vendor/golang.org/x/tools/internal/imports/source_modindex.go
+++ b/vendor/golang.org/x/tools/internal/imports/source_modindex.go
@@ -15,6 +15,10 @@ import (
// This code is here rather than in the modindex package
// to avoid import loops
+// TODO(adonovan): this code is only used by a test in this package.
+// Can we delete it? Or is there a plan to call NewIndexSource from
+// cmd/goimports?
+
// implements Source using modindex, so only for module cache.
//
// this is perhaps over-engineered. A new Index is read at first use.
@@ -22,8 +26,8 @@ import (
// is read if the index changed. It is not clear the Mutex is needed.
type IndexSource struct {
modcachedir string
- mutex sync.Mutex
- ix *modindex.Index
+ mu sync.Mutex
+ index *modindex.Index // (access via getIndex)
expires time.Time
}
@@ -39,13 +43,14 @@ func (s *IndexSource) LoadPackageNames(ctx context.Context, srcDir string, paths
}
func (s *IndexSource) ResolveReferences(ctx context.Context, filename string, missing References) ([]*Result, error) {
- if err := s.maybeReadIndex(); err != nil {
+ index, err := s.getIndex()
+ if err != nil {
return nil, err
}
var cs []modindex.Candidate
for pkg, nms := range missing {
for nm := range nms {
- x := s.ix.Lookup(pkg, nm, false)
+ x := index.Lookup(pkg, nm, false)
cs = append(cs, x...)
}
}
@@ -74,30 +79,22 @@ func (s *IndexSource) ResolveReferences(ctx context.Context, filename string, mi
return ans, nil
}
-func (s *IndexSource) maybeReadIndex() error {
- s.mutex.Lock()
- defer s.mutex.Unlock()
-
- var readIndex bool
- if time.Now().After(s.expires) {
- ok, err := modindex.Update(s.modcachedir)
- if err != nil {
- return err
- }
- if ok {
- readIndex = true
- }
- }
+func (s *IndexSource) getIndex() (*modindex.Index, error) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
- if readIndex || s.ix == nil {
- ix, err := modindex.ReadIndex(s.modcachedir)
+ // (s.index = nil => s.expires is zero,
+ // so the first condition is strictly redundant.
+ // But it makes the postcondition very clear.)
+ if s.index == nil || time.Now().After(s.expires) {
+ index, err := modindex.Update(s.modcachedir)
if err != nil {
- return err
+ return nil, err
}
- s.ix = ix
- // for now refresh every 15 minutes
- s.expires = time.Now().Add(time.Minute * 15)
+ s.index = index
+ s.expires = index.ValidAt.Add(15 * time.Minute) // (refresh period)
}
+ // Inv: s.index != nil
- return nil
+ return s.index, nil
}