diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 12bd9f32da..6699179c06 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -194,10 +194,24 @@ class FileManager extends Plugin { * @returns {void} */ async rename (oldPath, newPath) { - await this.__handleExists(oldPath, `Cannot rename ${oldPath}`) + await this._handleExists(oldPath, `Cannot rename ${oldPath}`) const isFile = await this.isFile(oldPath) + const newPathExists = await this.exists(newPath) + const provider = this.fileProviderOf(oldPath) - this.fileRenamedEvent(oldPath, newPath, !isFile) + if (isFile) { + if (newPathExists) { + modalDialogCustom.alert('File already exists.') + return + } + return provider.rename(oldPath, newPath, false) + } else { + if (newPathExists) { + modalDialogCustom.alert('Folder already exists.') + return + } + return provider.rename(oldPath, newPath, true) + } } /** diff --git a/test-browser/tests/fileManager_api.test.js b/test-browser/tests/fileManager_api.test.js index 62b4340c6d..2dd0435a52 100644 --- a/test-browser/tests/fileManager_api.test.js +++ b/test-browser/tests/fileManager_api.test.js @@ -62,11 +62,19 @@ module.exports = { .addFile('renameFile.js', { content: executeRename }) .executeScript(`remix.exeCurrent()`) .pause(2000) - .pause(100000) - // .journalLastChildIncludes('pragma solidity >=0.2.0 <0.7.0;') - // .end() + .waitForElementPresent('[data-id="treeViewLibrowser/old_contract.sol"]') + .end() }, + // 'Should execute `rename` api from file manager external api': function (browser) { + // browser + // .addFile('renameFile.js', { content: executeRename }) + // .executeScript(`remix.exeCurrent()`) + // .pause(2000) + // .waitForElementPresent('[data-id="treeViewLibrowser/new_contract.sol"]') + // .end() + // }, + tearDown: sauce } @@ -136,7 +144,7 @@ const executeRename = ` const run = async () => { const result = await remix.call('fileManager', 'rename', 'browser/new_contract.sol', 'browser/old_contract.sol') - console.log(result) + console.log('result: ', result) } run()