delete history for deleted files

Similar to the "rename" case, I added an event handler to clean up the `vault-stats.json` when a file is deleted.

Moreover, I added a sanity check on the "rename" event handler.
This commit is contained in:
Davide Aversa 2023-01-25 10:03:48 +01:00
parent 6676fc69f4
commit da44785003

View file

@ -25,9 +25,17 @@ export default class StatsManager {
);
this.vault.on("rename", (new_name, old_path) => {
const content = this.vaultStats.modifiedFiles[old_path];
delete this.vaultStats.modifiedFiles[old_path];
this.vaultStats.modifiedFiles[new_name.path] = content;
if (this.vaultStats.modifiedFiles.hasOwnProperty(old_path)) {
const content = this.vaultStats.modifiedFiles[old_path];
delete this.vaultStats.modifiedFiles[old_path];
this.vaultStats.modifiedFiles[new_name.path] = content;
}
});
this.vault.on("delete", (deleted_file) => {
if (this.vaultStats.modifiedFiles.hasOwnProperty(deleted_file.path)) {
delete this.vaultStats.modifiedFiles[deleted_file.path];
}
});
this.vault.adapter.exists(STATS_FILE).then(async (exists) => {