@@ -13,6 +13,7 @@ import (
1313 "sort"
1414
1515 "github.com/goforj/wire/internal/cachepaths"
16+ "github.com/goforj/wire/internal/cachepolicy"
1617)
1718
1819type discoveryCacheEntry struct {
@@ -32,7 +33,7 @@ type discoveryLocalPackage struct {
3233type discoveryFileMeta struct {
3334 Path string
3435 Size int64
35- ModTime int64 // deprecated: kept for gob compat, not used for matching
36+ ModTime int64
3637 ContentHash string // sha256 of file content
3738 IsDir bool
3839}
@@ -47,7 +48,7 @@ type discoveryFileFingerprint struct {
4748 Hash string
4849}
4950
50- const discoveryCacheVersion = 4
51+ const discoveryCacheVersion = 5
5152
5253func readDiscoveryCache (req goListRequest ) (map [string ]* packageMeta , bool ) {
5354 entry , err := loadDiscoveryCacheEntry (req )
@@ -62,6 +63,7 @@ func readDiscoveryCache(req goListRequest) (map[string]*packageMeta, bool) {
6263
6364func buildDiscoveryCacheEntry (req goListRequest , meta map [string ]* packageMeta ) (* discoveryCacheEntry , error ) {
6465 workspace := detectModuleRoot (req .WD )
66+ useFileContent := cachepolicy .UseFileContent ()
6567 entry := & discoveryCacheEntry {
6668 Version : discoveryCacheVersion ,
6769 Meta : meta ,
@@ -73,7 +75,7 @@ func buildDiscoveryCacheEntry(req goListRequest, meta map[string]*packageMeta) (
7375 filepath .Join (workspace , "go.work.sum" ),
7476 }
7577 for _ , name := range global {
76- if fm , ok := statDiscoveryFile (name ); ok {
78+ if fm , ok := statDiscoveryFile (name , useFileContent ); ok {
7779 entry .Global = append (entry .Global , fm )
7880 }
7981 }
@@ -106,8 +108,9 @@ func validateDiscoveryCacheEntry(entry *discoveryCacheEntry) bool {
106108 if entry == nil || entry .Version != discoveryCacheVersion {
107109 return false
108110 }
111+ useFileContent := cachepolicy .UseFileContent ()
109112 for _ , fm := range entry .Global {
110- if ! matchesDiscoveryFile (fm ) {
113+ if ! matchesDiscoveryFile (fm , useFileContent ) {
111114 return false
112115 }
113116 }
@@ -133,6 +136,7 @@ func discoveryCachePath(req goListRequest) (string, error) {
133136 }
134137 sumReq := struct {
135138 Version int
139+ CacheMode string
136140 WD string
137141 Tags string
138142 Patterns []string
@@ -141,6 +145,7 @@ func discoveryCachePath(req goListRequest) (string, error) {
141145 Go string
142146 }{
143147 Version : discoveryCacheVersion ,
148+ CacheMode : cachepolicy .ModeLabel (),
144149 WD : canonicalLoaderPath (req .WD ),
145150 Tags : req .Tags ,
146151 Patterns : append ([]string (nil ), req .Patterns ... ),
@@ -188,13 +193,13 @@ func saveDiscoveryCacheEntry(req goListRequest, entry *discoveryCacheEntry) erro
188193 return gob .NewEncoder (f ).Encode (entry )
189194}
190195
191- func statDiscoveryFile (path string ) (discoveryFileMeta , bool ) {
196+ func statDiscoveryFile (path string , useFileContent bool ) (discoveryFileMeta , bool ) {
192197 info , err := os .Stat (path )
193198 if err != nil {
194199 return discoveryFileMeta {}, false
195200 }
196201 h := ""
197- if ! info .IsDir () {
202+ if ! info .IsDir () && useFileContent {
198203 var err error
199204 h , err = hashFileContent (path )
200205 if err != nil {
@@ -204,17 +209,24 @@ func statDiscoveryFile(path string) (discoveryFileMeta, bool) {
204209 return discoveryFileMeta {
205210 Path : canonicalLoaderPath (path ),
206211 Size : info .Size (),
212+ ModTime : info .ModTime ().UnixNano (),
207213 ContentHash : h ,
208214 IsDir : info .IsDir (),
209215 }, true
210216}
211217
212- func matchesDiscoveryFile (fm discoveryFileMeta ) bool {
213- cur , ok := statDiscoveryFile (fm .Path )
218+ func matchesDiscoveryFile (fm discoveryFileMeta , useFileContent bool ) bool {
219+ cur , ok := statDiscoveryFile (fm .Path , useFileContent )
214220 if ! ok {
215221 return false
216222 }
217- return cur .ContentHash == fm .ContentHash && cur .IsDir == fm .IsDir
223+ if cur .IsDir != fm .IsDir {
224+ return false
225+ }
226+ if useFileContent {
227+ return cur .ContentHash == fm .ContentHash
228+ }
229+ return cur .Size == fm .Size && cur .ModTime == fm .ModTime
218230}
219231
220232func statDiscoveryDir (path string ) (discoveryDirMeta , bool ) {
0 commit comments