yann300 4 years ago committed by GitHub
parent fe6d057d32
commit efcfd5d39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      libs/remixd/src/services/remixdClient.ts

@ -88,15 +88,15 @@ export class RemixdClient extends PluginClient {
set (args: SharedFolderArgs): Promise<void> {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) reject(new Error('Cannot write file: read-only mode selected'))
if (this.readOnly) return reject(new Error('Cannot write file: read-only mode selected'))
const isFolder = args.path.endsWith('/')
const path = utils.absolutePath(args.path, this.currentSharedFolder)
const exists = fs.existsSync(path)
if (exists && !isRealPath(path)) reject(new Error(''))
if (exists && !isRealPath(path)) return reject(new Error(''))
if (args.content === 'undefined') { // no !!!!!
console.log('trying to write "undefined" ! stopping.')
reject(new Error('trying to write "undefined" ! stopping.'))
return reject(new Error('trying to write "undefined" ! stopping.'))
}
this.trackDownStreamUpdate[path] = path
if (isFolder) {
@ -114,7 +114,7 @@ export class RemixdClient extends PluginClient {
fs.writeFile(path, args.content, 'utf8', (error: Error) => {
if (error) {
console.log(error)
reject(error)
return reject(error)
}
resolve()
})
@ -134,11 +134,11 @@ export class RemixdClient extends PluginClient {
createDir (args: SharedFolderArgs): Promise<void> {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) reject(new Error('Cannot create folder: read-only mode selected'))
if (this.readOnly) return reject(new Error('Cannot create folder: read-only mode selected'))
const path = utils.absolutePath(args.path, this.currentSharedFolder)
const exists = fs.existsSync(path)
if (exists && !isRealPath(path)) reject(new Error(''))
if (exists && !isRealPath(path)) return reject(new Error(''))
this.trackDownStreamUpdate[path] = path
fs.mkdirp(path).then(() => {
let splitPath = args.path.split('/')
@ -158,11 +158,11 @@ export class RemixdClient extends PluginClient {
rename (args: SharedFolderArgs): Promise<boolean> {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) reject(new Error('Cannot rename file: read-only mode selected'))
if (this.readOnly) return reject(new Error('Cannot rename file: read-only mode selected'))
const oldpath = utils.absolutePath(args.oldPath, this.currentSharedFolder)
if (!fs.existsSync(oldpath)) {
reject(new Error('File not found ' + oldpath))
return reject(new Error('File not found ' + oldpath))
}
const newpath = utils.absolutePath(args.newPath, this.currentSharedFolder)
@ -170,7 +170,7 @@ export class RemixdClient extends PluginClient {
fs.move(oldpath, newpath, (error: Error) => {
if (error) {
console.log(error)
reject(error.message)
return reject(error.message)
}
this.emit('fileRenamed', args.oldPath, args.newPath)
resolve(true)
@ -184,15 +184,15 @@ export class RemixdClient extends PluginClient {
remove (args: SharedFolderArgs): Promise<boolean> {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) reject(new Error('Cannot remove file: read-only mode selected'))
if (this.readOnly) return reject(new Error('Cannot remove file: read-only mode selected'))
const path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) reject(new Error('File not found ' + path))
if (!fs.existsSync(path)) return reject(new Error('File not found ' + path))
if (!isRealPath(path)) return
return fs.remove(path, (error: Error) => {
if (error) {
console.log(error)
reject(new Error('Failed to remove file/directory: ' + error))
return reject(new Error('Failed to remove file/directory: ' + error))
}
this.emit('fileRemoved', args.path)
resolve(true)

Loading…
Cancel
Save