| 1 | package workspacelease |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | ) |
| 8 | |
| 9 | // Freeze the pre-native-resolver workspace lock spelling. In particular, older |
| 10 | // Windows builds can retain a junction alias even when the new physical root is |
| 11 | // on another drive. Deriving both keys from the new physical root would silently |
| 12 | // stop taking the lock held by those existing writers. |
| 13 | func legacyWorkspaceIdentity(root string) (string, error) { |
| 14 | absolute, err := filepath.Abs(root) |
| 15 | if err != nil { |
| 16 | return "", err |
| 17 | } |
| 18 | absolute = filepath.Clean(absolute) |
| 19 | if resolved, err := filepath.EvalSymlinks(absolute); err == nil { |
| 20 | absolute = filepath.Clean(resolved) |
| 21 | } else if !os.IsNotExist(err) { |
| 22 | return "", fmt.Errorf("resolve legacy workspace identity: %w", err) |
| 23 | } |
| 24 | return compatibilityIdentityPath(nearestGitWorktreeRoot(absolute)), nil |
| 25 | } |
| 26 |