| 203 | } |
| 204 | |
| 205 | func configureRuntimeLayout(runtime *app.Runtime, kinds ...config.PathKind) error { |
| 206 | if err := hydrateRuntimeLayoutFromConfig(runtime); err != nil { |
| 207 | return err |
| 208 | } |
| 209 | |
| 210 | missing := make([]config.PathKind, 0, len(kinds)) |
| 211 | for _, kind := range kinds { |
| 212 | dir, err := runtime.Layout.Dir(kind) |
| 213 | if err != nil { |
| 214 | return err |
| 215 | } |
| 216 | if dir == "" { |
| 217 | missing = append(missing, kind) |
| 218 | } |
| 219 | } |
| 220 | if len(missing) == 0 { |
| 221 | return nil |
| 222 | } |
| 223 | if runtime.Config != nil && !runtime.ConfigManaged { |
| 224 | return fmt.Errorf("%w: missing %v", errIncompleteRuntimeLayout, missing) |
| 225 | } |
| 226 | |
| 227 | if runtime.LayoutResolver == nil { |
| 228 | runtime.LayoutResolver = config.NewSystemResolver("") |
| 229 | } |
| 230 | layout, err := runtime.LayoutResolver.Resolve(missing...) |
| 231 | if err != nil { |
| 232 | return err |
| 233 | } |
| 234 | for _, kind := range missing { |
| 235 | dir, dirErr := layout.Dir(kind) |
| 236 | if dirErr != nil { |
| 237 | return dirErr |
| 238 | } |
| 239 | switch kind { |
| 240 | case config.PathKindConfig: |
| 241 | runtime.Layout.ConfigDir = dir |
| 242 | runtime.Layout.ExplicitConfig = layout.ExplicitConfig |
| 243 | case config.PathKindData: |
| 244 | runtime.Layout.DataDir = dir |
| 245 | runtime.Layout.ExplicitData = layout.ExplicitData |
| 246 | case config.PathKindState: |
| 247 | runtime.Layout.StateDir = dir |
| 248 | runtime.Layout.ExplicitState = layout.ExplicitState |
| 249 | case config.PathKindCache: |
| 250 | runtime.Layout.CacheDir = dir |
| 251 | runtime.Layout.ExplicitCache = layout.ExplicitCache |
| 252 | } |
| 253 | } |
| 254 | runtime.Layout.UsesXDG = runtime.Layout.UsesXDG || layout.UsesXDG |
| 255 | runtime.Layout.UsesXDGState = runtime.Layout.UsesXDGState || layout.UsesXDGState |
| 256 | return nil |
| 257 | } |
| 258 | |
| 259 | func runtimeKeyringBackendInfo(runtime *app.Runtime) (secrets.KeyringBackendInfo, error) { |
| 260 | if runtime == nil || runtime.KeyringOptions == nil { |