summaryrefslogtreecommitdiff
path: root/cache.go
blob: 0957b26dd5c9288ae1d9de3fe31ffe3e50e2c6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
//     go install go.wit.com/apps/autogenpb@latest
//
// This file was autogenerated with autogenpb:
//  autogenpb v0.5.25-2-g30e8de2    Built on  2025/10/16 09:16:09  (  3 m)
// Theese sort.pb.go and marshal.pb.go files are autogenerated
// The autogenpb sources have example .proto files with instructions
//

package forgepb

import (
	"errors"
	"os"
	"path/filepath"

	"go.wit.com/lib/config"
	"go.wit.com/lib/env"
	"go.wit.com/log"
)

func (f *Forge) configureCache(cacheName string) error {
	// construct the full file name
	fullname := config.MakeConfigFilename("forge", cacheName)

	// try to load the file
	f.cache = new(Cache)
	f.cache.Filename = fullname
	if env.Verbose() {
		log.Info("configCache() attempting to ReLoad()", fullname)
	}
	err := config.ReLoad(f.cache)
	if errors.Is(err, os.ErrNotExist) {
		// is a new file
		return os.ErrNotExist
	}
	if err != nil {
		log.Printf("patchesCacheLoad() failed err (%v) filename (%s)\n", err, f.cache.Filename)
		panic("failed to load patches")
	}
	if cacheName == "gosrc" {
		f.cache.Name = cacheName
		f.cache.Filename = fullname
		gosrc := filepath.Join(env.Get("homeDir"), "go/src")
		f.cache.Dirs = []string{gosrc}
		f.cache.Save()
	}
	env.SetGlobal("lib/forgepb", "cache", cacheName)
	env.SetGlobal("lib/forgepb", "cacheTEXT", f.cache.Filename)
	return err
}