FinchRootDir returns the path to the Finch root directory, which is %LOCALAPPDATA% on Windows. It also canonicalizes any environment variables that may be unexpanded in the path so that all paths based on it can be passed safely to other programs which may execute outside of the user's context.
(ffd FinchFinderDeps)
| 16 | // It also canonicalizes any environment variables that may be unexpanded in the path so that all |
| 17 | // paths based on it can be passed safely to other programs which may execute outside of the user's context. |
| 18 | func (Finch) FinchRootDir(ffd FinchFinderDeps) (string, error) { |
| 19 | appDir := ffd.Env("LOCALAPPDATA") |
| 20 | expandedPath, err := registry.ExpandString(appDir) |
| 21 | if err != nil { |
| 22 | return "", err |
| 23 | } |
| 24 | // reject any paths that contain unexpected characters |
| 25 | if strings.Contains(expandedPath, "&") || strings.Contains(expandedPath, `"`) { |
| 26 | return "", fmt.Errorf("unexpected LOCALAPPDATA path %q", expandedPath) |
| 27 | } |
| 28 | |
| 29 | return expandedPath, nil |
| 30 | } |