refactor: improve get ssh path duplicate code

Signed-off-by: Black-Hole1 <bh@bugs.cc>
This commit is contained in:
Black-Hole1
2023-05-31 16:27:19 +08:00
parent e91f6f16bf
commit c7a8d29f12
7 changed files with 42 additions and 49 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/containers/podman/v4/pkg/rootless"
"github.com/containers/podman/v4/pkg/signal"
"github.com/containers/storage/pkg/directory"
"github.com/containers/storage/pkg/homedir"
"github.com/containers/storage/pkg/idtools"
stypes "github.com/containers/storage/types"
securejoin "github.com/cyphar/filepath-securejoin"
@ -473,17 +474,8 @@ func ExitCode(err error) int {
return 126
}
// HomeDir returns the home directory for the current user.
func HomeDir() (string, error) {
home := os.Getenv("HOME")
if home == "" {
usr, err := user.LookupId(fmt.Sprintf("%d", rootless.GetRootlessUID()))
if err != nil {
return "", fmt.Errorf("unable to resolve HOME directory: %w", err)
}
home = usr.HomeDir
}
return home, nil
func GetIdentityPath(name string) string {
return filepath.Join(homedir.Get(), ".ssh", name)
}
func Tmpdir() string {