checking for isFile

pull/1392/head
lianahus 3 years ago
parent 942ab6f9a1
commit 5ba2e3f6c5
  1. 20
      apps/remix-ide/src/app/files/fileManager.js
  2. 3
      apps/remix-ide/src/app/files/fileProvider.js
  3. 4
      apps/remix-ide/src/app/files/remixDProvider.js
  4. 3
      apps/remix-ide/src/app/panels/tab-proxy.js
  5. 2
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
  6. 18
      libs/remixd/src/services/remixdClient.ts

@ -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', '')

@ -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
}

@ -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()

@ -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)
})

@ -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}.`)
}
}

@ -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)

Loading…
Cancel
Save