Double check before delete
This commit is contained in:
parent
6e9558f13e
commit
b4b4680422
3 changed files with 15 additions and 1 deletions
|
|
@ -7,6 +7,8 @@ export interface FileOperations {
|
|||
|
||||
getFileSize: (path: RelativePath) => Promise<number>;
|
||||
|
||||
exists: (path: RelativePath) => Promise<boolean>;
|
||||
|
||||
getModificationTime: (path: RelativePath) => Promise<Date>;
|
||||
|
||||
// Create and write the file if it doesn't exist. Otherwise, it has the same behavior as write.
|
||||
|
|
|
|||
|
|
@ -39,6 +39,11 @@ export class ObsidianFileOperations implements FileOperations {
|
|||
return new Date((await this.statFile(path)).mtime);
|
||||
}
|
||||
|
||||
public async exists(path: RelativePath): Promise<boolean> {
|
||||
Logger.getInstance().debug(`Checking existance of ${path}`);
|
||||
return this.vault.adapter.exists(normalizePath(path));
|
||||
}
|
||||
|
||||
public async create(
|
||||
path: RelativePath,
|
||||
newContent: Uint8Array
|
||||
|
|
@ -108,7 +113,7 @@ export class ObsidianFileOperations implements FileOperations {
|
|||
public async remove(path: RelativePath): Promise<void> {
|
||||
Logger.getInstance().debug(`Removing file: ${path}`);
|
||||
if (await this.vault.adapter.exists(normalizePath(path))) {
|
||||
return this.vault.adapter.remove(normalizePath(path));
|
||||
await this.vault.adapter.trashSystem(normalizePath(path));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,13 @@ export class Syncer {
|
|||
`Document ${relativePath} has been deleted locally, scheduling sync to delete it`
|
||||
);
|
||||
|
||||
if (await this.operations.exists(relativePath)) {
|
||||
Logger.getInstance().debug(
|
||||
`Document ${relativePath} actually exists locally, skipping`
|
||||
);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return this.internalSyncLocallyDeletedFile(relativePath);
|
||||
})
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue