MCPcopy Index your code
hub / github.com/celer-pkg/celer / readOrCreate

Method readOrCreate

configs/celer_update.go:17–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func (c *Celer) readOrCreate() error {
18 celerPath := filepath.Join(dirs.WorkspaceDir, "celer.toml")
19 if !fileio.PathExists(celerPath) {
20 // Create conf directory.
21 if err := os.MkdirAll(filepath.Dir(celerPath), os.ModePerm); err != nil {
22 return err
23 }
24
25 if c.Main.Jobs == 0 {
26 c.Main.Jobs = runtime.NumCPU()
27 }
28
29 if c.Main.BuildType == "" {
30 c.Main.BuildType = "release"
31 }
32
33 bytes, err := toml.Marshal(c)
34 if err != nil {
35 return err
36 }
37 if err := os.WriteFile(celerPath, bytes, os.ModePerm); err != nil {
38 return err
39 }
40 } else {
41 // Read celer.toml.
42 bytes, err := os.ReadFile(celerPath)
43 if err != nil {
44 return err
45 }
46 if err := toml.Unmarshal(bytes, c); err != nil {
47 return err
48 }
49
50 if c.Main.Jobs == 0 {
51 c.Main.Jobs = runtime.NumCPU()
52 }
53
54 if c.Main.BuildType == "" {
55 c.Main.BuildType = "release"
56 }
57 }
58
59 return nil
60}
61
62func (c *Celer) save() error {
63 bytes, err := toml.Marshal(c)

Callers 15

SetBuildTypeMethod · 0.95
SetDownloadsMethod · 0.95
SetJobsMethod · 0.95
SetPlatformMethod · 0.95
SetProjectMethod · 0.95
SetOfflineMethod · 0.95
SetVerboseMethod · 0.95
SetPkgCacheDirMethod · 0.95
SetPkgCacheWritableMethod · 0.95
CacheArtifactsMethod · 0.95
CacheDownloadsMethod · 0.95
SetProxyHostMethod · 0.95

Calls 3

PathExistsFunction · 0.92
MkdirAllMethod · 0.80
WriteFileMethod · 0.80

Tested by

no test coverage detected