diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 5d22ee89..638e3f36 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -17,7 +17,7 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build-docker: + publish-docker: runs-on: self-hosted permissions: diff --git a/frontend/sync-client/src/persistence/database.ts b/frontend/sync-client/src/persistence/database.ts index c4ff6d82..5011fc85 100644 --- a/frontend/sync-client/src/persistence/database.ts +++ b/frontend/sync-client/src/persistence/database.ts @@ -21,6 +21,12 @@ export interface StoredDatabase { lastSeenUpdateId: VaultUpdateId | undefined; } +/** + * Represents a document in the database. + * + * It is mutable and its content should always represent the latest + * state of the document on disk based on the update events we have seen. + */ export interface DocumentRecord { relativePath: RelativePath; documentId: DocumentId; @@ -114,11 +120,8 @@ export class Database { this.save(); } - public setDocument( - { - parentVersionId, - hash - }: { + public updateDocumentMetadata( + metadata: { parentVersionId: VaultUpdateId; hash: string; }, @@ -128,10 +131,9 @@ export class Database { throw new Error("Document not found in database"); } - toUpdate.metadata = { parentVersionId, hash }; + toUpdate.metadata = metadata; this.save(); - return; } public removeDocumentPromise(promise: Promise): void { @@ -225,7 +227,7 @@ export class Database { const newDocument = this.getLatestDocumentByRelativePath(newRelativePath); - if (newDocument !== undefined && !newDocument.isDeleted) { + if (newDocument?.isDeleted === false) { throw new Error( `Document already exists at new location: ${newRelativePath}` ); diff --git a/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts b/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts index 8300f10b..e38af28c 100644 --- a/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts +++ b/frontend/sync-client/src/sync-operations/unrestricted-syncer.ts @@ -58,7 +58,7 @@ export class UnrestrictedSyncer { type: SyncType.CREATE }); - this.database.setDocument( + this.database.updateDocumentMetadata( { parentVersionId: response.vaultUpdateId, hash: contentHash @@ -92,7 +92,7 @@ export class UnrestrictedSyncer { type: SyncType.DELETE }); - this.database.setDocument( + this.database.updateDocumentMetadata( { parentVersionId: response.vaultUpdateId, hash: EMPTY_HASH @@ -190,7 +190,7 @@ export class UnrestrictedSyncer { }); this.database.delete(document.relativePath); - this.database.setDocument( + this.database.updateDocumentMetadata( { parentVersionId: response.vaultUpdateId, hash: EMPTY_HASH @@ -215,7 +215,7 @@ export class UnrestrictedSyncer { ); // this can throw FileNotFoundError } - this.database.setDocument( + this.database.updateDocumentMetadata( { parentVersionId: response.vaultUpdateId, hash: contentHash @@ -315,7 +315,7 @@ export class UnrestrictedSyncer { ); const [promise, resolve] = createPromise(); - this.database.setDocument( + this.database.updateDocumentMetadata( { parentVersionId: remoteVersion.vaultUpdateId, hash: hash(contentBytes)