Skip to content

Commit 3185091

Browse files
committed
Unify Lima user home inside guest for all platforms
Signed-off-by: Arthur Sengileyev <[email protected]>
1 parent 0625d0b commit 3185091

File tree

1 file changed

+2
-38
lines changed

1 file changed

+2
-38
lines changed

pkg/osutil/user.go

+2-38
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ import (
77
"fmt"
88
"os/exec"
99
"os/user"
10-
"path"
11-
"path/filepath"
1210
"regexp"
1311
"runtime"
1412
"strconv"
1513
"strings"
1614
"sync"
1715

18-
"github.com/lima-vm/lima/pkg/ioutilx"
1916
. "github.com/lima-vm/lima/pkg/must"
2017
"github.com/lima-vm/lima/pkg/version/versionutil"
2118
"github.com/sirupsen/logrus"
@@ -115,9 +112,8 @@ func LimaUser(limaVersion string, warn bool) *user.User {
115112
warnings = append(warnings, warning)
116113
limaUser.Username = fallbackUser
117114
}
118-
if runtime.GOOS != "windows" {
119-
limaUser.HomeDir = "/home/{{.User}}.linux"
120-
} else {
115+
limaUser.HomeDir = "/home/{{.User}}.linux"
116+
if runtime.GOOS == "windows" {
121117
idu, err := call([]string{"id", "-u"})
122118
if err != nil {
123119
logrus.Debug(err)
@@ -146,38 +142,6 @@ func LimaUser(limaVersion string, warn bool) *user.User {
146142
warnings = append(warnings, warning)
147143
limaUser.Gid = formatUidGid(gid)
148144
}
149-
home, err := ioutilx.WindowsSubsystemPath(limaUser.HomeDir)
150-
if err != nil {
151-
logrus.Debug(err)
152-
} else {
153-
// Trim mount prefix within Subsystem
154-
// cygwin/msys2 cygpath could have prefix for drive mounts configured via /etc/fstab
155-
// wsl wslpath could have prefix for drive mounts configured via [automount] section in wsl.conf
156-
drivePath, err := ioutilx.WindowsSubsystemPath(filepath.VolumeName(limaUser.HomeDir) + "/")
157-
if err != nil {
158-
logrus.Debug(err)
159-
} else {
160-
prefix := path.Dir(strings.TrimSuffix(drivePath, "/"))
161-
if prefix != "/" {
162-
home = strings.TrimPrefix(home, prefix)
163-
}
164-
home += ".linux"
165-
}
166-
}
167-
if home == "" {
168-
drive := filepath.VolumeName(limaUser.HomeDir)
169-
home = filepath.ToSlash(limaUser.HomeDir)
170-
// replace C: with /c
171-
prefix := strings.ToLower(fmt.Sprintf("/%c", drive[0]))
172-
home = strings.Replace(home, drive, prefix, 1)
173-
home += ".linux"
174-
}
175-
if !regexPath.MatchString(limaUser.HomeDir) {
176-
warning := fmt.Sprintf("local home %q is not a valid Linux path (must match %q); using %q home instead",
177-
limaUser.HomeDir, regexPath.String(), home)
178-
warnings = append(warnings, warning)
179-
limaUser.HomeDir = home
180-
}
181145
}
182146
})
183147
if warn {

0 commit comments

Comments
 (0)