From e6c33804d918e01ae647706b59dbcdfa0ec66dc4 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Thu, 11 Feb 2021 16:21:14 +0100 Subject: [PATCH] Debug clashing names --- apps/remix-ide/src/app/files/fileManager.js | 9 +++++++-- apps/remix-ide/src/lib/helper.js | 1 + .../file-explorer/src/lib/file-explorer.tsx | 13 +++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 8e46839fcf..c91803c5f2 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -100,13 +100,18 @@ class FileManager extends Plugin { * @param {string} path path of the directory or file * @returns {boolean} true if the path exists */ - exists (path) { + async exists (path, type) { const provider = this.fileProviderOf(path) - const result = provider.exists(path, (err, result) => { + const result = await provider.exists(path, (err, result) => { if (err) return false return result }) + if (type === 'file') { + return result && await this.isFile(path) + } else if (type === 'folder') { + return result && await this.isDirectory(path) + } return result } diff --git a/apps/remix-ide/src/lib/helper.js b/apps/remix-ide/src/lib/helper.js index ab7f8c743f..a518ef98a2 100644 --- a/apps/remix-ide/src/lib/helper.js +++ b/apps/remix-ide/src/lib/helper.js @@ -37,6 +37,7 @@ module.exports = { () => { return exist }, (callback) => { fileProvider.exists(name + counter + prefix + '.' + ext, (error, currentExist) => { + console.log('currentExists: ', currentExist) if (error) { callback(error) } else { diff --git a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx index b1d1a46385..afa734110a 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -311,6 +311,8 @@ export const FileExplorer = (props: FileExplorerProps) => { const fileManager = state.fileManager helper.createNonClashingName(newFilePath, filesProvider, async (error, newName) => { + console.log('newFilePath: ', newFilePath) + console.log('newName: ', newName) if (error) { modal('Create File Failed', error, { label: 'Close', @@ -336,7 +338,8 @@ export const FileExplorer = (props: FileExplorerProps) => { const dirName = newFolderPath + '/' try { - const exists = await fileManager.exists(dirName) + const exists = await fileManager.exists(dirName, 'folder') + console.log('exists: ', exists) if (exists) return await fileManager.mkdir(dirName) @@ -372,10 +375,11 @@ export const FileExplorer = (props: FileExplorerProps) => { }) } - const renamePath = async (oldPath: string, newPath: string) => { + const renamePath = async (oldPath: string, newPath: string, type?: string) => { try { const fileManager = state.fileManager - const exists = await fileManager.exists(newPath) + const exists = await fileManager.exists(newPath, type) + console.log('exists: ', exists) if (exists) { modal('Rename File Failed', 'File name already exists', { @@ -814,9 +818,10 @@ export const FileExplorer = (props: FileExplorerProps) => { const oldPath: string = state.focusEdit.element const oldName = extractNameFromKey(oldPath) const newPath = oldPath.replace(oldName, content) + const type: string = state.focusEdit.type editRef.current.textContent = extractNameFromKey(oldPath) - renamePath(oldPath, newPath) + renamePath(oldPath, newPath, type) } setState(prevState => { return { ...prevState, focusEdit: { element: null, isNew: false, type: '', lastEdit: '' } }