diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index 2ad2ea4aa9..da8f97c8b0 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -272,7 +272,13 @@ class FileManager extends Plugin { await this._handleIsDir(src, `Cannot copy from ${src}. Path is not a directory.`) await this._handleExists(dest, `Cannot paste content into ${dest}. Path does not exist.`) await this._handleIsDir(dest, `Cannot paste content into ${dest}. Path is not directory.`) - await this.inDepthCopy(src, dest) + + const provider = this.fileProviderOf(src) + if (provider.isSubDirectory(src, dest)) { + this.call('notification', 'toast', 'File(s) to paste is an ancestor of the destination folder') + } else { + await this.inDepthCopy(src, dest) + } } catch (e) { throw new Error(e) } diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index 2176bc53b8..61e751ee62 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -3,6 +3,7 @@ import { CompilerImports } from '@remix-project/core-plugin' const EventManager = require('events') const remixLib = require('@remix-project/remix-lib') +const pathModule = require('path') const Storage = remixLib.Storage class FileProvider { @@ -308,6 +309,14 @@ class FileProvider { _normalizePath (path) { return this.type + path } + + isSubDirectory (parent, child) { + if (!parent) return false + if (parent === child) return true + const relative = pathModule.relative(parent, child) + + return !!relative && relative.split(pathModule.sep)[0] !== '..' + } } module.exports = FileProvider diff --git a/apps/remix-ide/src/app/files/workspaceFileProvider.js b/apps/remix-ide/src/app/files/workspaceFileProvider.js index 505be72b8c..3fcd635fcf 100644 --- a/apps/remix-ide/src/app/files/workspaceFileProvider.js +++ b/apps/remix-ide/src/app/files/workspaceFileProvider.js @@ -49,14 +49,6 @@ class WorkspaceFileProvider extends FileProvider { return ret } - isSubDirectory (parent, child) { - if (!parent) return false - if (parent === child) return true - const relative = pathModule.relative(parent, child) - - return !!relative && relative.split(pathModule.sep)[0] !== '..' - } - resolveDirectory (path, callback) { super.resolveDirectory(path, (error, files) => { if (error) return callback(error) diff --git a/apps/remix-ide/src/app/panels/tab-proxy.js b/apps/remix-ide/src/app/panels/tab-proxy.js index c3a897b7d6..bc8a7c4c8f 100644 --- a/apps/remix-ide/src/app/panels/tab-proxy.js +++ b/apps/remix-ide/src/app/panels/tab-proxy.js @@ -190,15 +190,6 @@ export class TabProxy extends Plugin { } renameTab (oldName, newName) { - this.addTab(newName, '', async () => { - await this.fileManager.open(newName) - this.event.emit('openFile', newName) - }, - async () => { - await this.fileManager.closeFile(newName) - this.event.emit('closeFile', newName) - this.emit('closeFile', newName) - }) this.removeTab(oldName) }