| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "slices" |
| 5 | |
| 6 | "reasonix/desktop/internal/legacycleanup" |
| 7 | ) |
| 8 | |
| 9 | // Tombstones are global to the topic ID. A replay must not remove indexes in |
| 10 | // a different workspace or clear that tombstone over a newly occupied ID. |
| 11 | // Caller owns the cross-process projects writer lock. |
| 12 | func topicRemovalHasOtherOwner(file desktopProjectFile, item legacycleanup.Candidate) bool { |
| 13 | references := func(ids, pins []string, groups []desktopGroup) bool { |
| 14 | if slices.Contains(ids, item.TopicID) || slices.Contains(pins, item.TopicID) { |
| 15 | return true |
| 16 | } |
| 17 | for _, group := range groups { |
| 18 | if slices.Contains(group.TopicIDs, item.TopicID) { |
| 19 | return true |
| 20 | } |
| 21 | } |
| 22 | return false |
| 23 | } |
| 24 | if item.Topic.Scope != "global" && references(file.GlobalTopics, file.GlobalPinnedTopics, file.GlobalGroups) { |
| 25 | return true |
| 26 | } |
| 27 | for _, project := range file.Projects { |
| 28 | if item.Topic.Scope == "project" && sameProjectRoot(project.Root, item.Topic.WorkspaceRoot) { |
| 29 | continue |
| 30 | } |
| 31 | if references(project.Topics, project.PinnedTopics, project.Groups) { |
| 32 | return true |
| 33 | } |
| 34 | } |
| 35 | return false |
| 36 | } |
| 37 |