Make startup deletion check more robust

This commit is contained in:
Andras Schmelczer 2025-05-14 22:14:34 +01:00
parent 8f97e8e656
commit 45f9f37d0f
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 32 additions and 4 deletions

View file

@ -15,7 +15,27 @@ export class ObsidianFileSystemOperations implements FileSystemOperations {
) {}
public async listAllFiles(): Promise<RelativePath[]> {
return this.vault.getFiles().map((file) => file.path);
// Let's implement this by hand because vault.adapter.listAllFiles doesn't always return all files.
const allFiles = [];
const remainingFolders = [this.vault.getRoot().path];
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
const folder = remainingFolders.pop();
if (folder == undefined) {
break;
}
if (folder.includes(".obsidian")) {
continue;
}
const files = await this.vault.adapter.list(normalizePath(folder));
allFiles.push(...files.files);
remainingFolders.push(...files.folders);
}
return allFiles;
}
public async read(path: RelativePath): Promise<Uint8Array> {

View file

@ -1,6 +1,7 @@
import type {
Database,
DocumentId,
DocumentRecord,
RelativePath
} from "../persistence/database";
import type { SyncService } from "../services/sync-service";
@ -434,9 +435,16 @@ export class Syncer {
const allLocalFiles = await this.operations.listAllFiles();
let locallyPossiblyDeletedFiles = [
...this.database.resolvedDocuments
].filter(({ relativePath }) => !allLocalFiles.includes(relativePath));
let locallyPossiblyDeletedFiles: DocumentRecord[] = [];
for (const document of this.database.resolvedDocuments) {
if (
!document.isDeleted &&
!(await this.operations.exists(document.relativePath))
) {
locallyPossiblyDeletedFiles.push(document);
}
}
const updates = Promise.all(
allLocalFiles.map(async (relativePath) => {