diff --git a/cmd/pipe/main.go b/cmd/pipe/main.go index 45ef911..283417b 100644 --- a/cmd/pipe/main.go +++ b/cmd/pipe/main.go @@ -409,6 +409,11 @@ func main() { isName = true } + // An explicit `pipe -get` must always fetch fresh — drop any stale + // disk cache for this URL (see object.InvalidateModuleCache; the + // cache is otherwise never invalidated). + object.InvalidateModuleCache(target) + modDir := object.ModuleCacheDir() _, content, err := object.ResolveImport(target) if err != nil { diff --git a/pkg/object/import.go b/pkg/object/import.go index 363b857..4d02425 100644 --- a/pkg/object/import.go +++ b/pkg/object/import.go @@ -234,6 +234,18 @@ func fetchURLModule(url string) (string, string, error) { return url, resp, nil } +// InvalidateModuleCache removes the disk-cached copy of a module URL, so a +// subsequent ResolveImport/fetchURLModule re-downloads it. Used by `pipe -get` +// for an always-fresh explicit fetch — without this, `pipe -get ` served +// a stale module forever (the cache was only ever written, never invalidated, +// live-observed when a freshly published sqlite v0.8.6 still resolved to the +// old pre-ALTER copy). Runtime imports deliberately keep the cache to avoid a +// network hit on every program run. +func InvalidateModuleCache(url string) { + cachePath := filepath.Join(moduleCacheDir, urlToCacheKey(url)) + os.Remove(cachePath) +} + func urlToCacheKey(url string) string { // Convert URL to a safe filename: replace special chars url = strings.ReplaceAll(url, "https://", "")