Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions libs/remixd/src/services/remixdClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
})
Expand All @@ -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('/')
Expand All @@ -158,19 +158,19 @@ 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)

if (!isRealPath(oldpath)) return
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)
Expand All @@ -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)
Expand Down