mirror of
https://github.com/containers/podman.git
synced 2025-06-02 02:26:52 +08:00
refactor: improve get ssh path duplicate code
Signed-off-by: Black-Hole1 <bh@bugs.cc>
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user