MCPcopy
hub / github.com/kopia/kopia / LoadConfigFromFile

Function LoadConfigFromFile

repo/local_config.go:131–161  ·  view source on GitHub ↗

LoadConfigFromFile reads the local configuration from the specified file.

(fileName string)

Source from the content-addressed store, hash-verified

129
130// LoadConfigFromFile reads the local configuration from the specified file.
131func LoadConfigFromFile(fileName string) (*LocalConfig, error) {
132 f, err := os.Open(fileName) //nolint:gosec
133 if err != nil {
134 return nil, errors.Wrap(err, "error loading config file")
135 }
136 defer f.Close() //nolint:errcheck
137
138 var lc LocalConfig
139
140 if err := json.NewDecoder(f).Decode(&lc); err != nil {
141 return nil, errors.Wrap(err, "error decoding config json")
142 }
143
144 // cache directory is stored as relative to config file name, resolve it to absolute.
145 if lc.Caching != nil {
146 if lc.Caching.CacheDirectory != "" && !ospath.IsAbs(lc.Caching.CacheDirectory) {
147 lc.Caching.CacheDirectory = filepath.Join(filepath.Dir(fileName), lc.Caching.CacheDirectory)
148 }
149
150 // override cache directory from the environment variable.
151 if cd := os.Getenv("KOPIA_CACHE_DIRECTORY"); cd != "" && ospath.IsAbs(cd) {
152 lc.Caching.CacheDirectory = cd
153 }
154 }
155
156 if lc.PermissiveCacheLoading && os.Getenv("KOPIA_UPGRADE_LOCK_ENABLED") == "" {
157 return nil, errors.New("must have set KOPIA_UPGRADE_LOCK_ENABLED when connecting to repository with permissive cache loading")
158 }
159
160 return &lc, nil
161}

Callers 10

TestLocalConfig_notFoundFunction · 0.85
DisconnectFunction · 0.85
SetClientOptionsFunction · 0.85
GetCachingOptionsFunction · 0.85
SetCachingOptionsFunction · 0.85
OpenFunction · 0.85
openWithConfigFunction · 0.85

Calls 3

IsAbsFunction · 0.92
OpenMethod · 0.65
CloseMethod · 0.65

Tested by 3

TestLocalConfig_notFoundFunction · 0.68