diff --git a/Sources/AutomergeRepo/Repo.swift b/Sources/AutomergeRepo/Repo.swift index f96ffbd..933621b 100644 --- a/Sources/AutomergeRepo/Repo.swift +++ b/Sources/AutomergeRepo/Repo.swift @@ -402,6 +402,11 @@ public final class Repo { _ = try await resolveDocHandle(id: docId) } guard let handle = handles[docId] else { fatalError("HANDLE DOESN'T EXIST") } + if handle.state == .deleted { + // if the handle is marked as `deleted`, then the document has been removed from this + // repository and shouldn't be updated or re-created. + return + } if logLevel(.repo).canTrace() { Logger.repo.trace("REPO: - working on handle for \(docId), state: \(String(describing: handle.state))") } @@ -452,7 +457,7 @@ public final class Repo { ) return } - if handles[docId] != nil { + if let internalHandle = handles[docId], internalHandle.state != .deleted { // If we have the document, see if we're agreeable to sending a copy if await sharePolicy.share(peer: msg.senderId, docId: docId) { do { diff --git a/Tests/AutomergeRepoTests/TwoReposWithInMemoryNetworkTests.swift b/Tests/AutomergeRepoTests/TwoReposWithInMemoryNetworkTests.swift index 1878d40..93c6232 100644 --- a/Tests/AutomergeRepoTests/TwoReposWithInMemoryNetworkTests.swift +++ b/Tests/AutomergeRepoTests/TwoReposWithInMemoryNetworkTests.swift @@ -271,35 +271,6 @@ final class TwoReposWithInMemoryNetworkTests: XCTestCase { print(errMsg) } } -// -// func testDelete() async throws { -// let myId = DocumentId() -// let _ = try await repo.create(id: myId) -// var knownIds = await repo.documentIds() -// XCTAssertEqual(knownIds.count, 1) -// -// try await repo.delete(id: myId) -// knownIds = await repo.documentIds() -// XCTAssertEqual(knownIds.count, 0) -// -// do { -// let _ = try await repo.find(id: DocumentId()) -// XCTFail() -// } catch {} -// } -// -// func testClone() async throws { -// let myId = DocumentId() -// let handle = try await repo.create(id: myId) -// XCTAssertEqual(myId, handle.id) -// -// let clonedHandle = try await repo.clone(id: myId) -// XCTAssertNotEqual(handle.id, clonedHandle.id) -// XCTAssertNotEqual(handle.doc.actor, clonedHandle.doc.actor) -// -// let knownIds = await repo.documentIds() -// XCTAssertEqual(knownIds.count, 2) -// } // TBD: // - func storageIdForPeer(peerId) -> StorageId