throw if no workspace

pull/5370/head
yann300 4 years ago
parent d36f2ef6d9
commit bb1a2cf9d9
  1. 14
      apps/remix-ide/src/app/files/fileManager.js
  2. 12
      apps/remix-ide/src/app/files/workspaceFileProvider.js

@ -514,6 +514,8 @@ class FileManager extends Plugin {
if (file.startsWith('browser')) {
return this._deps.filesProviders.browser
}
const provider = this._deps.filesProviders.workspace
if (!provider.isReady()) throw createError({ code: 'ECONNRESET', message: 'No workspace has been opened.' })
return this._deps.filesProviders.workspace
}
@ -579,7 +581,11 @@ class FileManager extends Plugin {
async.each(Object.keys(filesSet), (file, callback) => {
if (override) {
self._deps.filesProviders[fileProvider].set(file, filesSet[file].content)
try {
self._deps.filesProviders[fileProvider].set(file, filesSet[file].content)
} catch (e) {
return callback(e.message || e)
}
self.syncEditor(fileProvider + file)
return callback()
}
@ -591,7 +597,11 @@ class FileManager extends Plugin {
} else if (helper.checkSpecialChars(name)) {
modalDialogCustom.alert('Special characters are not allowed')
} else {
self._deps.filesProviders[fileProvider].set(name, filesSet[file].content)
try {
self._deps.filesProviders[fileProvider].set(name, filesSet[file].content)
} catch (e) {
return callback(e.message || e)
}
self.syncEditor(fileProvider + name)
}
callback()

@ -6,6 +6,7 @@ class WorkspaceFileProvider extends FileProvider {
constructor () {
super('')
this.workspacesPath = '.workspaces'
this.workspace = null
}
setWorkspace (workspace) {
@ -13,11 +14,20 @@ class WorkspaceFileProvider extends FileProvider {
this.workspace = workspace
}
getWorkspace () {
return this.workspace
}
isReady () {
return this.workspace !== null
}
clearWorkspace () {
this.workspace = null
}
removePrefix (path) {
if (!this.workspace) throw new Error('No workspace has been opened.')
path = path.replace(/^\/|\/$/g, '') // remove first and last slash
if (path.startsWith(this.workspacesPath + '/' + this.workspace)) return path
if (path.startsWith(this.workspace)) return this.workspacesPath + '/' + this.workspace
@ -27,6 +37,7 @@ class WorkspaceFileProvider extends FileProvider {
}
resolveDirectory (path, callback) {
if (!this.workspace) throw new Error('No workspace has been opened.')
super.resolveDirectory(path, (error, files) => {
if (error) return callback(error)
const unscoped = {}
@ -38,6 +49,7 @@ class WorkspaceFileProvider extends FileProvider {
}
_normalizePath (path) {
if (!this.workspace) throw new Error('No workspace has been opened.')
return path.replace(this.workspacesPath + '/' + this.workspace + '/', '')
}
}

Loading…
Cancel
Save