Skip to content

Commit

Permalink
Fix: #61 On Jex backup, do not overwrite already exported notebooks i…
Browse files Browse the repository at this point in the history
…f the notebooks name differs only in special characters
  • Loading branch information
JackGruber committed Dec 3, 2023
1 parent 2c4b79a commit 424ac57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- Fix: #61 On Jex backup, do not overwrite already exported notebooks if the notebooks name differs only in special characters

## not released

## v1.3.3 (2023-07-08)
Expand Down
25 changes: 21 additions & 4 deletions src/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,13 @@ class Backup {
notebooks.info,
folderId
);
await this.exportNotebooks(
folderId,
path.join(this.activeBackupPath, notebookFile),
this.exportFormat

const file = await this.getNumberdFileNameIfExist(
path.join(this.activeBackupPath, notebookFile)
);
this.log.verbose(`Save as ${file}`);

await this.exportNotebooks(folderId, file, this.exportFormat);
} else {
this.log.verbose(
`Skip ${notebooks.info[folderId]["title"]} (${folderId}) since no notes in notebook`
Expand All @@ -728,6 +730,21 @@ class Backup {
}
}

private async getNumberdFileNameIfExist(file: string): Promise<string> {
const fileExt = path.parse(file).ext;
const fileDir = path.parse(file).dir;
const fileName = path.parse(file).name;

let indexNr = 1;
let checkFile = fileName;
while (fs.existsSync(path.join(fileDir, checkFile + fileExt))) {
checkFile = fileName + "_" + indexNr;
indexNr++;
}

return path.join(fileDir, checkFile + fileExt);
}

private async getNotebookFileName(
notebooks: any,
id: string
Expand Down

0 comments on commit 424ac57

Please sign in to comment.