Skip to content

Commit

Permalink
ignore sync requests for deleted documents
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed May 24, 2024
1 parent c8f441b commit 3de6fb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
7 changes: 6 additions & 1 deletion Sources/AutomergeRepo/Repo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))")
}
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 0 additions & 29 deletions Tests/AutomergeRepoTests/TwoReposWithInMemoryNetworkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3de6fb4

Please # to comment.