Skip to content

Commit 4390f8a

Browse files
committed
chore: factorize fileHash
1 parent 03efcb3 commit 4390f8a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

internal/cache/cache.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ func (c *Cache) packageHash(pkg *packages.Package, mode HashMode) (string, error
147147

148148
fmt.Fprintf(key, "pkgpath %s\n", pkg.PkgPath)
149149
for _, f := range pkg.CompiledGoFiles {
150-
c.ioSem <- struct{}{}
151-
h, fErr := cache.FileHash(f)
152-
<-c.ioSem
150+
h, fErr := c.fileHash(f)
153151
if fErr != nil {
154152
return "", fmt.Errorf("failed to calculate file %s hash: %w", f, fErr)
155153
}
@@ -236,6 +234,20 @@ func (c *Cache) getBytes(actionID cache.ActionID) ([]byte, error) {
236234
return cachedData, nil
237235
}
238236

237+
func (c *Cache) fileHash(f string) ([cache.HashSize]byte, error) {
238+
c.ioSem <- struct{}{}
239+
240+
h, err := cache.FileHash(f)
241+
242+
<-c.ioSem
243+
244+
if err != nil {
245+
return [cache.HashSize]byte{}, err
246+
}
247+
248+
return h, nil
249+
}
250+
239251
func (c *Cache) encode(data any) (*bytes.Buffer, error) {
240252
buf := &bytes.Buffer{}
241253
err := c.sw.TrackStageErr("gob", func() error {

0 commit comments

Comments
 (0)