From 5ba2e3f6c5b552048507c78702279d2187d3b491 Mon Sep 17 00:00:00 2001 From: lianahus Date: Fri, 16 Jul 2021 14:48:42 +0200 Subject: [PATCH 1/3] checking for isFile --- apps/remix-ide/src/app/files/fileManager.js | 20 +++++++++++++++++-- apps/remix-ide/src/app/files/fileProvider.js | 3 +++ .../remix-ide/src/app/files/remixDProvider.js | 4 ++-- apps/remix-ide/src/app/panels/tab-proxy.js | 3 ++- .../file-explorer/src/lib/file-explorer.tsx | 2 +- libs/remixd/src/services/remixdClient.ts | 18 ++++++++++++++++- 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index 9b618a9fe9..fe8cd8b220 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -155,9 +155,9 @@ class FileManager extends Plugin { * @param {string} path path of the directory * @returns {boolean} true if path is a directory. */ - isDirectory (path) { + async isDirectory (path) { const provider = this.fileProviderOf(path) - const result = provider.isDirectory(path) + const result = await provider.isDirectory(path) return result } @@ -360,9 +360,11 @@ class FileManager extends Plugin { async remove (path) { try { path = this.limitPluginScope(path) + console.log('remove fileManager,js ', path) await this._handleExists(path, `Cannot remove file or directory ${path}`) const provider = this.fileProviderOf(path) + // this.emit('folderRemoved', path) return await provider.remove(path) } catch (e) { throw new Error(e) @@ -383,6 +385,7 @@ class FileManager extends Plugin { this._deps.browserExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) }) this._deps.browserExplorer.event.on('fileAdded', (path) => { this.fileAddedEvent(path) }) this._deps.localhostExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) }) + this._deps.localhostExplorer.event.on('folderRemoved', (path) => { this.removeTabsOfPath(path) }) this._deps.localhostExplorer.event.on('errored', (event) => { this.removeTabsOf(this._deps.localhostExplorer) }) this._deps.localhostExplorer.event.on('closed', (event) => { this.removeTabsOf(this._deps.localhostExplorer) }) this._deps.workspaceExplorer.event.on('fileChanged', (path) => { this.fileChangedEvent(path) }) @@ -547,6 +550,19 @@ class FileManager extends Plugin { } } + removeTabsOfPath (path) { + for (const tab in this.openedFiles) { + if (tab.substring(0, path.length) === path) { + console.log('removeTabsOfPath ', path) + if (path === this._deps.config.get('currentFile')) { + this._deps.config.set('currentFile', '') + } + this.editor.discard(path) + delete this.openedFiles[path] + } + } + } + fileRemovedEvent (path) { if (path === this._deps.config.get('currentFile')) { this._deps.config.set('currentFile', '') diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index c789635160..cc837a5efe 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -185,6 +185,7 @@ class FileProvider { window.remixFileSystem.rmdirSync(path, console.log) } this.event.emit('fileRemoved', this._normalizePath(path)) + console.log('file provider remove remove ', path) } } catch (e) { console.log(e) @@ -250,6 +251,8 @@ class FileProvider { if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) { window.remixFileSystem.unlinkSync(path, console.log) this.event.emit('fileRemoved', this._normalizePath(path)) + console.log('file provider removefile remove ', path) + return true } else return false } diff --git a/apps/remix-ide/src/app/files/remixDProvider.js b/apps/remix-ide/src/app/files/remixDProvider.js index bc59bfe90b..aab388da37 100644 --- a/apps/remix-ide/src/app/files/remixDProvider.js +++ b/apps/remix-ide/src/app/files/remixDProvider.js @@ -35,10 +35,11 @@ module.exports = class RemixDProvider extends FileProvider { this._appManager.on('remixd', 'fileRemoved', (path) => { this.event.emit('fileRemoved', path) + console.log('remixd appmanager listener remove ', path) }) this._appManager.on('remixd', 'fileRenamed', (oldPath, newPath) => { - this.event.emit('fileRemoved', oldPath, newPath) + this.event.emit('fileRenamed', oldPath, newPath) }) this._appManager.on('remixd', 'rootFolderChanged', () => { @@ -141,7 +142,6 @@ module.exports = class RemixDProvider extends FileProvider { this._appManager.call('remixd', 'remove', { path: unprefixedpath }) .then(result => { const path = unprefixedpath - delete this.filesContent[path] resolve(true) this.init() diff --git a/apps/remix-ide/src/app/panels/tab-proxy.js b/apps/remix-ide/src/app/panels/tab-proxy.js index 24edfa1da6..ecc6c02022 100644 --- a/apps/remix-ide/src/app/panels/tab-proxy.js +++ b/apps/remix-ide/src/app/panels/tab-proxy.js @@ -44,7 +44,8 @@ export class TabProxy extends Plugin { fileManager.events.on('fileRemoved', (name) => { const workspace = this.fileManager.currentWorkspace() - + console.log('wotk= ', workspace) + console.log('mode= ', this.fileManager.mode) workspace ? this.removeTab(workspace + '/' + name) : this.removeTab(this.fileManager.mode + '/' + name) }) 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 eab163b09e..66d9886a48 100644 --- a/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx +++ b/libs/remix-ui/file-explorer/src/lib/file-explorer.tsx @@ -408,7 +408,7 @@ export const FileExplorer = (props: FileExplorerProps) => { try { await fileManager.remove(p) } catch (e) { - const isDir = state.fileManager.isDirectory(p) + const isDir = await state.fileManager.isDirectory(p) toast(`Failed to remove ${isDir ? 'folder' : 'file'} ${p}.`) } } diff --git a/libs/remixd/src/services/remixdClient.ts b/libs/remixd/src/services/remixdClient.ts index 31588628ea..b65f0fbdb2 100644 --- a/libs/remixd/src/services/remixdClient.ts +++ b/libs/remixd/src/services/remixdClient.ts @@ -180,12 +180,19 @@ export class RemixdClient extends PluginClient { if (!fs.existsSync(path)) return reject(new Error('File not found ' + path)) if (!isRealPath(path)) return + + if (this._isFile(path)) { + this.emit('fileRemoved', path) + console.log('isfile ', path) + } else { + this.emit('folderRemoved', path) + console.log('isFolder ', path) + } return fs.remove(path, (error: Error) => { if (error) { console.log(error) return reject(new Error('Failed to remove file/directory: ' + error)) } - this.emit('fileRemoved', args.path) resolve(true) }) }) @@ -194,6 +201,15 @@ export class RemixdClient extends PluginClient { } } + _isFile (path: string): boolean { + try { + console.log('isfile inside ', path) + return fs.statSync(path).isFile() + } catch (error) { + throw new Error(error) + } + } + isDirectory (args: SharedFolderArgs): boolean { try { const path = utils.absolutePath(args.path, this.currentSharedFolder) From b5f9f912efb980797a9e823590c188e6c951cc04 Mon Sep 17 00:00:00 2001 From: lianahus Date: Wed, 21 Jul 2021 14:57:08 +0200 Subject: [PATCH 2/3] sending info about folder content --- apps/remix-ide/src/app/files/fileManager.js | 17 ----------- apps/remix-ide/src/app/files/fileProvider.js | 3 -- .../remix-ide/src/app/files/remixDProvider.js | 1 - apps/remix-ide/src/app/panels/tab-proxy.js | 2 -- .../solidity-compiler/src/lib/css/style.css | 1 - libs/remixd/src/services/remixdClient.ts | 30 ++++++++++++++----- 6 files changed, 22 insertions(+), 32 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index fe8cd8b220..f2d83d3915 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -360,11 +360,8 @@ class FileManager extends Plugin { async remove (path) { try { path = this.limitPluginScope(path) - console.log('remove fileManager,js ', path) await this._handleExists(path, `Cannot remove file or directory ${path}`) const provider = this.fileProviderOf(path) - - // this.emit('folderRemoved', path) return await provider.remove(path) } catch (e) { throw new Error(e) @@ -385,7 +382,6 @@ class FileManager extends Plugin { this._deps.browserExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) }) this._deps.browserExplorer.event.on('fileAdded', (path) => { this.fileAddedEvent(path) }) this._deps.localhostExplorer.event.on('fileRemoved', (path) => { this.fileRemovedEvent(path) }) - this._deps.localhostExplorer.event.on('folderRemoved', (path) => { this.removeTabsOfPath(path) }) this._deps.localhostExplorer.event.on('errored', (event) => { this.removeTabsOf(this._deps.localhostExplorer) }) this._deps.localhostExplorer.event.on('closed', (event) => { this.removeTabsOf(this._deps.localhostExplorer) }) this._deps.workspaceExplorer.event.on('fileChanged', (path) => { this.fileChangedEvent(path) }) @@ -550,19 +546,6 @@ class FileManager extends Plugin { } } - removeTabsOfPath (path) { - for (const tab in this.openedFiles) { - if (tab.substring(0, path.length) === path) { - console.log('removeTabsOfPath ', path) - if (path === this._deps.config.get('currentFile')) { - this._deps.config.set('currentFile', '') - } - this.editor.discard(path) - delete this.openedFiles[path] - } - } - } - fileRemovedEvent (path) { if (path === this._deps.config.get('currentFile')) { this._deps.config.set('currentFile', '') diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index cc837a5efe..c789635160 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -185,7 +185,6 @@ class FileProvider { window.remixFileSystem.rmdirSync(path, console.log) } this.event.emit('fileRemoved', this._normalizePath(path)) - console.log('file provider remove remove ', path) } } catch (e) { console.log(e) @@ -251,8 +250,6 @@ class FileProvider { if (window.remixFileSystem.existsSync(path) && !window.remixFileSystem.statSync(path).isDirectory()) { window.remixFileSystem.unlinkSync(path, console.log) this.event.emit('fileRemoved', this._normalizePath(path)) - console.log('file provider removefile remove ', path) - return true } else return false } diff --git a/apps/remix-ide/src/app/files/remixDProvider.js b/apps/remix-ide/src/app/files/remixDProvider.js index aab388da37..04b0217df1 100644 --- a/apps/remix-ide/src/app/files/remixDProvider.js +++ b/apps/remix-ide/src/app/files/remixDProvider.js @@ -35,7 +35,6 @@ module.exports = class RemixDProvider extends FileProvider { this._appManager.on('remixd', 'fileRemoved', (path) => { this.event.emit('fileRemoved', path) - console.log('remixd appmanager listener remove ', path) }) this._appManager.on('remixd', 'fileRenamed', (oldPath, newPath) => { diff --git a/apps/remix-ide/src/app/panels/tab-proxy.js b/apps/remix-ide/src/app/panels/tab-proxy.js index ecc6c02022..dba54aef61 100644 --- a/apps/remix-ide/src/app/panels/tab-proxy.js +++ b/apps/remix-ide/src/app/panels/tab-proxy.js @@ -44,8 +44,6 @@ export class TabProxy extends Plugin { fileManager.events.on('fileRemoved', (name) => { const workspace = this.fileManager.currentWorkspace() - console.log('wotk= ', workspace) - console.log('mode= ', this.fileManager.mode) workspace ? this.removeTab(workspace + '/' + name) : this.removeTab(this.fileManager.mode + '/' + name) }) diff --git a/libs/remix-ui/solidity-compiler/src/lib/css/style.css b/libs/remix-ui/solidity-compiler/src/lib/css/style.css index 3846ca0f0f..d2bbe9e606 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/css/style.css +++ b/libs/remix-ui/solidity-compiler/src/lib/css/style.css @@ -103,7 +103,6 @@ } .remixui_container { margin: 0; - margin-bottom: 2%; } .remixui_optimizeContainer { display: flex; diff --git a/libs/remixd/src/services/remixdClient.ts b/libs/remixd/src/services/remixdClient.ts index b65f0fbdb2..7d24c2aae1 100644 --- a/libs/remixd/src/services/remixdClient.ts +++ b/libs/remixd/src/services/remixdClient.ts @@ -180,19 +180,34 @@ export class RemixdClient extends PluginClient { if (!fs.existsSync(path)) return reject(new Error('File not found ' + path)) if (!isRealPath(path)) return - - if (this._isFile(path)) { - this.emit('fileRemoved', path) - console.log('isfile ', path) - } else { - this.emit('folderRemoved', path) - console.log('isFolder ', path) + // Saving the content of the item{folder} before removing it + const ls = [] + try { + const resolveList = (path) => { + if (!this._isFile(path)) { + const list = utils.resolveDirectory(path, this.currentSharedFolder) + Object.keys(list).forEach(itemPath => { + if (list[itemPath].isDirectory) { + resolveList(`${this.currentSharedFolder}${itemPath}`) + } + ls.push(itemPath) + }) + } + } + resolveList(path) + ls.push(args.path) + } catch (e) { + throw new Error(e) } return fs.remove(path, (error: Error) => { if (error) { console.log(error) return reject(new Error('Failed to remove file/directory: ' + error)) } + for (const file in ls) { + this.emit('fileRemoved', ls[file]) + } + resolve(true) }) }) @@ -203,7 +218,6 @@ export class RemixdClient extends PluginClient { _isFile (path: string): boolean { try { - console.log('isfile inside ', path) return fs.statSync(path).isFile() } catch (error) { throw new Error(error) From c5fa74a55c04f4a51f781c5bd559b2dffad3ce0c Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 22 Jul 2021 18:07:00 +0530 Subject: [PATCH 3/3] added / in path --- libs/remixd/src/services/remixdClient.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/remixd/src/services/remixdClient.ts b/libs/remixd/src/services/remixdClient.ts index 7d24c2aae1..8645caf4ac 100644 --- a/libs/remixd/src/services/remixdClient.ts +++ b/libs/remixd/src/services/remixdClient.ts @@ -188,7 +188,7 @@ export class RemixdClient extends PluginClient { const list = utils.resolveDirectory(path, this.currentSharedFolder) Object.keys(list).forEach(itemPath => { if (list[itemPath].isDirectory) { - resolveList(`${this.currentSharedFolder}${itemPath}`) + resolveList(`${this.currentSharedFolder}/${itemPath}`) } ls.push(itemPath) }) @@ -227,7 +227,6 @@ export class RemixdClient extends PluginClient { isDirectory (args: SharedFolderArgs): boolean { try { const path = utils.absolutePath(args.path, this.currentSharedFolder) - return fs.statSync(path).isDirectory() } catch (error) { throw new Error(error) @@ -237,7 +236,6 @@ export class RemixdClient extends PluginClient { isFile (args: SharedFolderArgs): boolean { try { const path = utils.absolutePath(args.path, this.currentSharedFolder) - return fs.statSync(path).isFile() } catch (error) { throw new Error(error)