aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/containers/common/pkg/unshare/unshare.go
blob: 1eff82e8e05406b21dff8efba30caface7b673dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package unshare

import (
	"fmt"
	"os"
	"os/user"

	"github.com/pkg/errors"
)

// 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", GetRootlessUID()))
		if err != nil {
			return "", errors.Wrapf(err, "unable to resolve HOME directory")
		}
		home = usr.HomeDir
	}
	return home, nil
}