From f7fc145b0c8f378e76fe59b487dcbe90cd6d78cd Mon Sep 17 00:00:00 2001 From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com> Date: Mon, 12 Jul 2021 10:32:15 -0700 Subject: [PATCH] Set notebook path before moving. (#16055) * set the original path when moving a single notebook * save original file path before attempting to move in case of error_ ) --- extensions/notebook/src/book/bookTocManager.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/notebook/src/book/bookTocManager.ts b/extensions/notebook/src/book/bookTocManager.ts index 8615683f43..456f158679 100644 --- a/extensions/notebook/src/book/bookTocManager.ts +++ b/extensions/notebook/src/book/bookTocManager.ts @@ -130,8 +130,8 @@ export class BookTocManager implements IBookTocManager { while (await fs.pathExists(path.join(newFileName.concat(' - ', counter.toString())).concat(path.parse(dest).ext))) { counter++; } - await fs.move(src, path.join(newFileName.concat(' - ', counter.toString())).concat(path.parse(dest).ext), { overwrite: true }); this.movedFiles.set(src, path.join(newFileName.concat(' - ', counter.toString())).concat(path.parse(dest).ext)); + await fs.move(src, path.join(newFileName.concat(' - ', counter.toString())).concat(path.parse(dest).ext), { overwrite: true }); vscode.window.showInformationMessage(loc.duplicateFileError(path.parse(dest).base, src, newFileName.concat(' - ', counter.toString()))); return newFileName.concat(' - ', counter.toString()); } @@ -280,8 +280,8 @@ export class BookTocManager implements IBookTocManager { if (elem.file) { let fileName = undefined; try { - await fs.move(path.join(this.sourceBookContentPath, elem.file).concat('.ipynb'), path.join(this.targetBookContentPath, elem.file).concat('.ipynb'), { overwrite: false }); this.movedFiles.set(path.join(this.sourceBookContentPath, elem.file).concat('.ipynb'), path.join(this.targetBookContentPath, elem.file).concat('.ipynb')); + await fs.move(path.join(this.sourceBookContentPath, elem.file).concat('.ipynb'), path.join(this.targetBookContentPath, elem.file).concat('.ipynb'), { overwrite: false }); } catch (error) { if (error.code === 'EEXIST') { fileName = await this.renameFile(path.join(this.sourceBookContentPath, elem.file).concat('.ipynb'), path.join(this.targetBookContentPath, elem.file).concat('.ipynb')); @@ -291,8 +291,8 @@ export class BookTocManager implements IBookTocManager { } } try { - await fs.move(path.join(this.sourceBookContentPath, elem.file).concat('.md'), path.join(this.targetBookContentPath, elem.file).concat('.md'), { overwrite: false }); this.movedFiles.set(path.join(this.sourceBookContentPath, elem.file).concat('.md'), path.join(this.targetBookContentPath, elem.file).concat('.md')); + await fs.move(path.join(this.sourceBookContentPath, elem.file).concat('.md'), path.join(this.targetBookContentPath, elem.file).concat('.md'), { overwrite: false }); } catch (error) { if (error.code === 'EEXIST') { fileName = await this.renameFile(path.join(this.sourceBookContentPath, elem.file).concat('.md'), path.join(this.targetBookContentPath, elem.file).concat('.md')); @@ -321,8 +321,8 @@ export class BookTocManager implements IBookTocManager { let moveFile = path.join(path.parse(uri).dir, path.parse(uri).name); let fileName = undefined; try { - await fs.move(section.book.contentPath, path.join(this.targetBookContentPath, moveFile).concat(path.parse(uri).ext), { overwrite: false }); this.movedFiles.set(section.book.contentPath, path.join(this.targetBookContentPath, moveFile).concat(path.parse(uri).ext)); + await fs.move(section.book.contentPath, path.join(this.targetBookContentPath, moveFile).concat(path.parse(uri).ext), { overwrite: false }); } catch (error) { if (error.code === 'EEXIST') { fileName = await this.renameFile(section.book.contentPath, path.join(this.targetBookContentPath, moveFile).concat(path.parse(uri).ext)); @@ -366,6 +366,7 @@ export class BookTocManager implements IBookTocManager { const filePath = path.parse(file.book.contentPath); let fileName = undefined; try { + this.movedFiles.set(file.book.contentPath, path.join(rootPath, filePath.base)); await fs.move(file.book.contentPath, path.join(rootPath, filePath.base), { overwrite: false }); } catch (error) { if (error.code === 'EEXIST') {