| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | |
| 8 | "reasonix/internal/pathidentity" |
| 9 | ) |
| 10 | |
| 11 | func cleanDesktopPath(path string) string { |
| 12 | path = strings.TrimSpace(path) |
| 13 | if path == "" { |
| 14 | return "" |
| 15 | } |
| 16 | if abs, err := filepath.Abs(path); err == nil { |
| 17 | path = abs |
| 18 | } |
| 19 | return filepath.Clean(path) |
| 20 | } |
| 21 | |
| 22 | func sameDesktopPath(a, b string) bool { |
| 23 | same, err := sameDesktopPathStrict(a, b) |
| 24 | return err == nil && same |
| 25 | } |
| 26 | |
| 27 | func sameDesktopPathStrict(a, b string) (bool, error) { |
| 28 | a, b = cleanDesktopPath(a), cleanDesktopPath(b) |
| 29 | if a == "" || b == "" { |
| 30 | return false, &pathidentity.Error{Kind: pathidentity.ErrorInvalid, Stage: "input", Err: errors.New("desktop path is empty")} |
| 31 | } |
| 32 | return pathidentity.Same(a, b, pathidentity.Options{FollowLeaf: true}) |
| 33 | } |
| 34 | |
| 35 | func projectRootKey(root string) string { |
| 36 | root = cleanDesktopPath(root) |
| 37 | if root == "" { |
| 38 | return "" |
| 39 | } |
| 40 | identity, err := pathidentity.Resolve(root, pathidentity.Options{FollowLeaf: true}) |
| 41 | if err != nil { |
| 42 | return "" |
| 43 | } |
| 44 | return identity.Key |
| 45 | } |
| 46 |