This commit is contained in:
Andras Schmelczer 2025-03-16 11:07:39 +00:00
commit 61e4f43131
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
3 changed files with 16 additions and 14 deletions

View file

@ -17,7 +17,7 @@ env:
IMAGE_NAME: ${{ github.repository }} IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
build-docker: publish-docker:
runs-on: self-hosted runs-on: self-hosted
permissions: permissions:

View file

@ -21,6 +21,12 @@ export interface StoredDatabase {
lastSeenUpdateId: VaultUpdateId | undefined; 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 { export interface DocumentRecord {
relativePath: RelativePath; relativePath: RelativePath;
documentId: DocumentId; documentId: DocumentId;
@ -114,11 +120,8 @@ export class Database {
this.save(); this.save();
} }
public setDocument( public updateDocumentMetadata(
{ metadata: {
parentVersionId,
hash
}: {
parentVersionId: VaultUpdateId; parentVersionId: VaultUpdateId;
hash: string; hash: string;
}, },
@ -128,10 +131,9 @@ export class Database {
throw new Error("Document not found in database"); throw new Error("Document not found in database");
} }
toUpdate.metadata = { parentVersionId, hash }; toUpdate.metadata = metadata;
this.save(); this.save();
return;
} }
public removeDocumentPromise(promise: Promise<void>): void { public removeDocumentPromise(promise: Promise<void>): void {
@ -225,7 +227,7 @@ export class Database {
const newDocument = const newDocument =
this.getLatestDocumentByRelativePath(newRelativePath); this.getLatestDocumentByRelativePath(newRelativePath);
if (newDocument !== undefined && !newDocument.isDeleted) { if (newDocument?.isDeleted === false) {
throw new Error( throw new Error(
`Document already exists at new location: ${newRelativePath}` `Document already exists at new location: ${newRelativePath}`
); );

View file

@ -58,7 +58,7 @@ export class UnrestrictedSyncer {
type: SyncType.CREATE type: SyncType.CREATE
}); });
this.database.setDocument( this.database.updateDocumentMetadata(
{ {
parentVersionId: response.vaultUpdateId, parentVersionId: response.vaultUpdateId,
hash: contentHash hash: contentHash
@ -92,7 +92,7 @@ export class UnrestrictedSyncer {
type: SyncType.DELETE type: SyncType.DELETE
}); });
this.database.setDocument( this.database.updateDocumentMetadata(
{ {
parentVersionId: response.vaultUpdateId, parentVersionId: response.vaultUpdateId,
hash: EMPTY_HASH hash: EMPTY_HASH
@ -190,7 +190,7 @@ export class UnrestrictedSyncer {
}); });
this.database.delete(document.relativePath); this.database.delete(document.relativePath);
this.database.setDocument( this.database.updateDocumentMetadata(
{ {
parentVersionId: response.vaultUpdateId, parentVersionId: response.vaultUpdateId,
hash: EMPTY_HASH hash: EMPTY_HASH
@ -215,7 +215,7 @@ export class UnrestrictedSyncer {
); // this can throw FileNotFoundError ); // this can throw FileNotFoundError
} }
this.database.setDocument( this.database.updateDocumentMetadata(
{ {
parentVersionId: response.vaultUpdateId, parentVersionId: response.vaultUpdateId,
hash: contentHash hash: contentHash
@ -315,7 +315,7 @@ export class UnrestrictedSyncer {
); );
const [promise, resolve] = createPromise(); const [promise, resolve] = createPromise();
this.database.setDocument( this.database.updateDocumentMetadata(
{ {
parentVersionId: remoteVersion.vaultUpdateId, parentVersionId: remoteVersion.vaultUpdateId,
hash: hash(contentBytes) hash: hash(contentBytes)