mirror of
https://github.com/gopasspw/gopass.git
synced 2026-10-28 10:15:04 +01:00
* [chore] Migrate to golangci-lint v2 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issue Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Add more package comments. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix golangci-lint config and the remaining checks Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Use Go 1.24 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix container builds Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix more failing tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix test failure Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix another len assertion Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Move location tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most remaining lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Only run XDG specific tests on linux Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Attempt to address on source of flaky failures Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/gopasspw/gopass/pkg/appdir"
|
|
"github.com/gopasspw/gopass/pkg/debug"
|
|
"github.com/gopasspw/gopass/pkg/fsutil"
|
|
)
|
|
|
|
// configLocation returns the location of the config file
|
|
// (a YAML file that contains values such as the path to the password store).
|
|
func configLocation() string {
|
|
// First, check for the "GOPASS_CONFIG" environment variable.
|
|
if cf := os.Getenv("GOPASS_CONFIG"); cf != "" {
|
|
return cf
|
|
}
|
|
|
|
// Second, check for the "XDG_CONFIG_HOME" environment variable
|
|
// (which is part of the XDG Base Directory Specification for Linux and
|
|
// other Unix-like operating sytstems)
|
|
return filepath.Join(appdir.UserConfig(), "config.yml")
|
|
}
|
|
|
|
// PwStoreDir reads the password store dir from the environment
|
|
// or returns the default location if the env is not set.
|
|
func PwStoreDir(mount string) string {
|
|
if mount != "" {
|
|
cleanName := strings.ReplaceAll(mount, string(filepath.Separator), "-")
|
|
|
|
return fsutil.CleanPath(filepath.Join(appdir.UserData(), "stores", cleanName))
|
|
}
|
|
// PASSWORD_STORE_DIR support is discouraged.
|
|
if d := os.Getenv("PASSWORD_STORE_DIR"); d != "" {
|
|
debug.Log("using value of PASSWORD_STORE_DIR: %s", d)
|
|
|
|
return fsutil.CleanPath(d)
|
|
}
|
|
|
|
if ld := filepath.Join(appdir.UserHome(), ".password-store"); fsutil.IsDir(ld) {
|
|
debug.Log("re-using existing legacy dir for root store: %s", ld)
|
|
|
|
return ld
|
|
}
|
|
|
|
return fsutil.CleanPath(filepath.Join(appdir.UserData(), "stores", "root"))
|
|
}
|
|
|
|
// Directory returns the configuration directory for the gopass config file.
|
|
func Directory() string {
|
|
return filepath.Dir(configLocation())
|
|
}
|