on main help sign in
fix: prevent nil ptr
commitac782d1ff81f45a91bb34c0669deb2861b27f733 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateThu 24 Jul 2025, 11:51 (1 year ago) parent6975271
3 files changed+13−11
go.mod+2−1 internal/config/config.go+1−1 internal/config/init.go+10−9
go.mod+2−1
@@ -42,11 +42,12 @@ require (
4242 github.com/tidwall/sjson v1.2.5
4343 github.com/u-root/u-root v0.14.1-0.20250722142936-bf4e78a90dfc
4444 github.com/zeebo/xxh3 v1.0.2
45− golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
4645 gopkg.in/natefinch/lumberjack.v2 v2.2.1
4746 mvdan.cc/sh/v3 v3.11.0
4847)
4948
49+require golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
50+
5051require (
5152 cloud.google.com/go v0.116.0 // indirect
5253 cloud.google.com/go/auth v0.13.0 // indirect
internal/config/config.go+1−1
@@ -3,6 +3,7 @@ package config
33import (
44 "context"
55 "fmt"
6+ "log/slog"
67 "net/http"
78 "os"
89 "slices"
@@ -13,7 +14,6 @@ import (
1314 "github.com/charmbracelet/crush/internal/csync"
1415 "github.com/charmbracelet/crush/internal/env"
1516 "github.com/tidwall/sjson"
16− "golang.org/x/exp/slog"
1717)
1818
1919const (
internal/config/init.go+10−9
@@ -6,12 +6,9 @@ import (
66 "path/filepath"
77 "strings"
88 "sync"
9− "sync/atomic"
109)
1110
12−const (
13− InitFlagFilename = "init"
14−)
11+const InitFlagFilename = "init"
1512
1613type ProjectInitFlag struct {
1714 Initialized bool `json:"initialized"`
@@ -19,25 +16,29 @@ type ProjectInitFlag struct {
1916
2017// TODO: we need to remove the global config instance keeping it now just until everything is migrated
2118var (
22− instance atomic.Pointer[Config]
19+ instance *Config
2320 cwd string
24− once sync.Once // Ensures the initialization happens only once
21+ once sync.Once
22+ wg sync.WaitGroup
2523)
2624
2725func Init(workingDir string, debug bool) (*Config, error) {
2826 var err error
27+ wg.Add(1)
2928 once.Do(func() {
3029 cwd = workingDir
3130 var cfg *Config
3231 cfg, err = Load(cwd, debug)
33− instance.Store(cfg)
32+ instance = cfg
33+ wg.Done()
3434 })
3535
36− return instance.Load(), err
36+ return instance, err
3737}
3838
3939func Get() *Config {
40− return instance.Load()
40+ wg.Wait()
41+ return instance
4142}
4243
4344func ProjectNeedsInitialization() (bool, error) {