Make startup deletion check more robust
This commit is contained in:
parent
8f97e8e656
commit
45f9f37d0f
2 changed files with 32 additions and 4 deletions
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue