Skip to content

Commit

Permalink
Fix: Remove no longer exsisting backupsets
Browse files Browse the repository at this point in the history
  • Loading branch information
JackGruber committed Jul 19, 2021
1 parent 54eefb4 commit 59c0fa5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Improved: Use of moments token
- Fix: #16 Prevent multiple simultaneous backup runs
- Add: #11 Make zip compression level selectable
- Fix: Delete old backup set information, if the backup set no longer exists

## v1.0.1 (2021-07-03)

Expand Down
14 changes: 14 additions & 0 deletions src/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,19 @@ class Backup {
backupPath: string,
backupRetention: number
) {
this.log.verbose("deleteOldBackupSets");
let info = JSON.parse(await joplinWrapper.settingsValue("backupInfo"));
let setOk = [];
for (let check of info) {
const folder = path.join(backupPath, check.name);
if (fs.existsSync(folder)) {
setOk.push(check);
} else {
this.log.verbose("Backup set " + folder + " no longer exist");
}
}
await joplinWrapper.settingsSetValue("backupInfo", JSON.stringify(setOk));
info = JSON.parse(await joplinWrapper.settingsValue("backupInfo"));
if (info.length > backupRetention) {
info.sort((a, b) => b.date - a.date);
}
Expand All @@ -914,6 +926,8 @@ class Backup {
const del = info.splice(backupRetention, 1);
const folder = path.join(backupPath, del[0].name);
if (fs.existsSync(folder)) {
this.log.verbose("Remove backup set " + folder);

try {
fs.rmdirSync(folder, {
recursive: true,
Expand Down

0 comments on commit 59c0fa5

Please sign in to comment.