Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Sources/Pesty/Store/ClipboardStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,25 @@ final class ClipboardStore {
for item in removed { deleteImageFile(item) }
}

/// Deletes a clip from the collection currently on screen only. A Pinboard
/// is an independently saved collection: deleting a card from history must
/// not erase saved copies, and deleting a pinboard copy must not touch
/// history or other pinboards, even for legacy clips that share an id.
/// Deleting exactly what was removed also closes an image-file leak: the
/// old cross-container removal deleted entries under two file names but
/// cleaned up only one of them.
func delete(_ item: ClipItem) {
history.removeAll { $0.id == item.id }
for i in pinboards.indices { pinboards[i].items.removeAll { $0.id == item.id } }
deleteImageFile(item)
let removed: [ClipItem]
switch source {
case .history:
removed = history.filter { $0.id == item.id }
history.removeAll { $0.id == item.id }
case .pinboard(let boardID):
guard let boardIndex = pinboards.firstIndex(where: { $0.id == boardID }) else { return }
removed = pinboards[boardIndex].items.filter { $0.id == item.id }
pinboards[boardIndex].items.removeAll { $0.id == item.id }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate deletion of legacy pinboard copies

When CloudKit sync is enabled and a legacy clip shares its UUID between history and a pinboard, deleting the pinboard copy here leaves the history copy, so desiredRecords() rewrites the single UUID-keyed cloud record with container history. On another Mac, applyRemoteToHistory() inserts that history record without removing the existing same-ID pinboard copy; reconciliation then lets the pinboard copy win again, so the deletion never propagates and the pinned card remains. Ensure the retained history item gets a distinct record ID or make a remote move to history evict same-ID legacy pinboard copies.

Useful? React with 👍 / 👎.

}
for entry in removed { deleteImageFile(entry) }
if selectedID == item.id { selectFirst() }
scheduleSave()
}
Expand Down
Loading