| 1 | package vmname |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | |
| 6 | "github.com/lima-vm/lima/v2/pkg/limatype/filenames" |
| 7 | "github.com/lima-vm/lima/v2/pkg/osutil" |
| 8 | ) |
| 9 | |
| 10 | |
| 11 | |
| 12 | func HomeLimit(home string, logical bool) Limit { |
| 13 | real, rest := home, "" |
| 14 | for !logical { |
| 15 | if p, err := filepath.EvalSymlinks(real); err == nil { |
| 16 | real = filepath.Join(p, rest) |
| 17 | break |
| 18 | } |
| 19 | parent := filepath.Dir(real) |
| 20 | if parent == real { |
| 21 | real = home |
| 22 | break |
| 23 | } |
| 24 | rest = filepath.Join(filepath.Base(real), rest) |
| 25 | real = parent |
| 26 | } |
| 27 | |
| 28 | n := osutil.UnixPathMax - 1 - len(real) - len("/") - len("/"+filenames.LongestSock) |
| 29 | return Limit(max(1, min(n, 76))) |
| 30 | } |