Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
de2a467c
Commit
de2a467c
authored
Apr 20, 2020
by
ioedeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented unlink and changed implementation of error handler
parent
9c830a11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
42 deletions
+34
-42
fileManager.js
src/app/files/fileManager.js
+21
-37
fileProvider.js
src/app/files/fileProvider.js
+13
-5
No files found.
src/app/files/fileManager.js
View file @
de2a467c
...
@@ -26,6 +26,16 @@ const profile = {
...
@@ -26,6 +26,16 @@ const profile = {
methods
:
[
'file'
,
'exists'
,
'open'
,
'writeFile'
,
'readFile'
,
'copyFile'
,
'unlink'
,
'rename'
,
'readdir'
,
'rmdir'
],
methods
:
[
'file'
,
'exists'
,
'open'
,
'writeFile'
,
'readFile'
,
'copyFile'
,
'unlink'
,
'rename'
,
'readdir'
,
'rmdir'
],
kind
:
'file-system'
kind
:
'file-system'
}
}
const
errorMsg
=
{
ENOENT
:
'No such file or directory'
,
EISDIR
:
'Path is a directory'
,
ENOTDIR
:
'Path is not on a directory'
,
EEXIST
:
'File already exists'
,
EPERM
:
'Permission denied'
}
const
createError
=
(
err
)
=>
{
return
new
Error
(
`
${
errorMsg
[
err
.
code
]}
${
err
.
message
||
''
}
`
)
}
// File System profile
// File System profile
// - methods: ['getFolder', 'getCurrentFile', 'getFile', 'setFile', 'switchFile']
// - methods: ['getFolder', 'getCurrentFile', 'getFile', 'setFile', 'switchFile']
...
@@ -49,7 +59,7 @@ class FileManager extends Plugin {
...
@@ -49,7 +59,7 @@ class FileManager extends Plugin {
*/
*/
_handleExists
(
path
,
message
)
{
_handleExists
(
path
,
message
)
{
if
(
!
this
.
exists
(
path
))
{
if
(
!
this
.
exists
(
path
))
{
th
is
.
_handl
eError
({
code
:
'ENOENT'
,
message
})
th
row
creat
eError
({
code
:
'ENOENT'
,
message
})
}
}
}
}
...
@@ -60,7 +70,7 @@ class FileManager extends Plugin {
...
@@ -60,7 +70,7 @@ class FileManager extends Plugin {
*/
*/
_handleIsFile
(
path
,
message
)
{
_handleIsFile
(
path
,
message
)
{
if
(
!
this
.
isFile
(
path
))
{
if
(
!
this
.
isFile
(
path
))
{
th
is
.
_handl
eError
({
code
:
'EISDIR'
,
message
})
th
row
creat
eError
({
code
:
'EISDIR'
,
message
})
}
}
}
}
...
@@ -71,45 +81,16 @@ class FileManager extends Plugin {
...
@@ -71,45 +81,16 @@ class FileManager extends Plugin {
*/
*/
_handleIsDir
(
path
,
message
)
{
_handleIsDir
(
path
,
message
)
{
if
(
this
.
isFile
(
path
))
{
if
(
this
.
isFile
(
path
))
{
throw
new
Error
({
code
:
'ENOTDIR'
,
message
})
throw
createError
({
code
:
'ENOTDIR'
,
message
})
}
}
/**
* Emits error based on error code
* @param {object} error error { code, message }
*/
_handleError
(
error
)
{
const
message
=
error
.
message
?
`:
${
error
.
message
}
`
:
''
if
(
error
.
code
===
'ENOENT'
)
{
throw
new
Error
(
'No such file or directory'
+
message
)
}
if
(
error
.
code
===
'EISDIR'
)
{
throw
new
Error
(
'Path is a directory'
+
message
)
}
}
if
(
error
.
code
===
'ENOTDIR'
)
{
throw
new
Error
(
'Path is not on a directory'
+
message
)
}
if
(
error
.
code
===
'EEXIST'
)
{
throw
new
Error
(
'File already exists'
+
message
)
}
if
(
error
.
code
===
'EPERM'
||
error
.
code
===
'EACCESS'
)
{
throw
new
Error
(
'Permission denied'
+
message
)
}
return
error
}
}
/** The current opened file */
/** The current opened file */
file
()
{
file
()
{
const
file
=
this
.
currentFile
()
const
file
=
this
.
currentFile
()
if
(
!
file
)
this
.
_handleError
({
code
:
'ENOENT'
,
message
:
'No file selected'
})
if
(
!
file
)
throw
createError
({
code
:
'ENOENT'
,
message
:
'No file selected'
})
return
file
return
file
}
}
...
@@ -194,6 +175,9 @@ class FileManager extends Plugin {
...
@@ -194,6 +175,9 @@ class FileManager extends Plugin {
unlink
(
path
)
{
unlink
(
path
)
{
this
.
_handleExists
(
path
,
`Cannot remove file
${
path
}
`
)
this
.
_handleExists
(
path
,
`Cannot remove file
${
path
}
`
)
this
.
_handleIsDir
(
path
,
`Cannot remove file
${
path
}
`
)
this
.
_handleIsDir
(
path
,
`Cannot remove file
${
path
}
`
)
const
provider
=
this
.
fileProviderOf
(
path
)
provider
.
removeFile
(
path
)
}
}
/**
/**
...
@@ -216,7 +200,7 @@ class FileManager extends Plugin {
...
@@ -216,7 +200,7 @@ class FileManager extends Plugin {
*/
*/
mkdir
(
path
)
{
mkdir
(
path
)
{
if
(
this
.
exists
(
path
))
{
if
(
this
.
exists
(
path
))
{
th
is
.
_handl
eError
({
code
:
'EEXIST'
,
message
:
`Cannot create directory
${
path
}
`
})
th
row
creat
eError
({
code
:
'EEXIST'
,
message
:
`Cannot create directory
${
path
}
`
})
}
}
const
provider
=
this
.
fileProviderOf
(
path
)
const
provider
=
this
.
fileProviderOf
(
path
)
...
@@ -347,7 +331,7 @@ class FileManager extends Plugin {
...
@@ -347,7 +331,7 @@ class FileManager extends Plugin {
getFile
(
path
)
{
getFile
(
path
)
{
const
provider
=
this
.
fileProviderOf
(
path
)
const
provider
=
this
.
fileProviderOf
(
path
)
if
(
!
provider
)
th
is
.
_handl
eError
({
code
:
'ENOENT'
,
message
:
`
${
path
}
not available`
})
if
(
!
provider
)
th
row
creat
eError
({
code
:
'ENOENT'
,
message
:
`
${
path
}
not available`
})
// TODO: change provider to Promise
// TODO: change provider to Promise
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
currentFile
()
===
path
)
return
resolve
(
this
.
editor
.
currentContent
())
if
(
this
.
currentFile
()
===
path
)
return
resolve
(
this
.
editor
.
currentContent
())
...
@@ -382,7 +366,7 @@ class FileManager extends Plugin {
...
@@ -382,7 +366,7 @@ class FileManager extends Plugin {
_setFileInternal
(
path
,
content
)
{
_setFileInternal
(
path
,
content
)
{
const
provider
=
this
.
fileProviderOf
(
path
)
const
provider
=
this
.
fileProviderOf
(
path
)
if
(
!
provider
)
th
is
.
_handl
eError
({
code
:
'ENOENT'
,
message
:
`
${
path
}
not available`
})
if
(
!
provider
)
th
row
creat
eError
({
code
:
'ENOENT'
,
message
:
`
${
path
}
not available`
})
// TODO : Add permission
// TODO : Add permission
// TODO : Change Provider to Promise
// TODO : Change Provider to Promise
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
src/app/files/fileProvider.js
View file @
de2a467c
...
@@ -139,10 +139,12 @@ class FileProvider {
...
@@ -139,10 +139,12 @@ class FileProvider {
}
}
isDirectory
(
path
)
{
isDirectory
(
path
)
{
path
=
this
.
removePrefix
(
path
)
return
window
.
remixFileSystem
.
statSync
(
path
).
isDirectory
()
return
window
.
remixFileSystem
.
statSync
(
path
).
isDirectory
()
}
}
isFile
(
path
)
{
isFile
(
path
)
{
path
=
this
.
removePrefix
(
path
)
return
window
.
remixFileSystem
.
statSync
(
path
).
isFile
()
return
window
.
remixFileSystem
.
statSync
(
path
).
isFile
()
}
}
...
@@ -156,9 +158,7 @@ class FileProvider {
...
@@ -156,9 +158,7 @@ class FileProvider {
const
stat
=
window
.
remixFileSystem
.
statSync
(
path
)
const
stat
=
window
.
remixFileSystem
.
statSync
(
path
)
try
{
try
{
if
(
!
stat
.
isDirectory
())
{
if
(
!
stat
.
isDirectory
())
{
window
.
remixFileSystem
.
unlinkSync
(
path
,
console
.
log
)
return
this
.
removeFile
(
path
)
this
.
event
.
trigger
(
'fileRemoved'
,
[
this
.
_normalizePath
(
path
)])
return
true
}
else
{
}
else
{
const
items
=
window
.
remixFileSystem
.
readdirSync
(
path
)
const
items
=
window
.
remixFileSystem
.
readdirSync
(
path
)
if
(
items
.
length
!==
0
)
{
if
(
items
.
length
!==
0
)
{
...
@@ -167,8 +167,7 @@ class FileProvider {
...
@@ -167,8 +167,7 @@ class FileProvider {
if
(
window
.
remixFileSystem
.
statSync
(
curPath
).
isDirectory
())
{
// delete folder
if
(
window
.
remixFileSystem
.
statSync
(
curPath
).
isDirectory
())
{
// delete folder
this
.
remove
(
curPath
)
this
.
remove
(
curPath
)
}
else
{
// delete file
}
else
{
// delete file
window
.
remixFileSystem
.
unlinkSync
(
curPath
,
console
.
log
)
this
.
removeFile
(
curPath
)
this
.
event
.
trigger
(
'fileRemoved'
,
[
this
.
_normalizePath
(
path
)])
}
}
})
})
if
(
window
.
remixFileSystem
.
readdirSync
(
path
).
length
===
0
)
window
.
remixFileSystem
.
rmdirSync
(
path
,
console
.
log
)
if
(
window
.
remixFileSystem
.
readdirSync
(
path
).
length
===
0
)
window
.
remixFileSystem
.
rmdirSync
(
path
,
console
.
log
)
...
@@ -185,6 +184,15 @@ class FileProvider {
...
@@ -185,6 +184,15 @@ class FileProvider {
return
true
return
true
}
}
removeFile
(
path
)
{
path
=
this
.
removePrefix
(
path
)
if
(
window
.
remixFileSystem
.
existsSync
(
path
)
&&
!
window
.
remixFileSystem
.
statSync
(
path
).
isDirectory
())
{
window
.
remixFileSystem
.
unlinkSync
(
path
,
console
.
log
)
this
.
event
.
trigger
(
'fileRemoved'
,
[
this
.
_normalizePath
(
path
)])
return
true
}
else
return
false
}
rename
(
oldPath
,
newPath
,
isFolder
)
{
rename
(
oldPath
,
newPath
,
isFolder
)
{
var
unprefixedoldPath
=
this
.
removePrefix
(
oldPath
)
var
unprefixedoldPath
=
this
.
removePrefix
(
oldPath
)
var
unprefixednewPath
=
this
.
removePrefix
(
newPath
)
var
unprefixednewPath
=
this
.
removePrefix
(
newPath
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment