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 = {
methods
:
[
'file'
,
'exists'
,
'open'
,
'writeFile'
,
'readFile'
,
'copyFile'
,
'unlink'
,
'rename'
,
'readdir'
,
'rmdir'
],
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
// - methods: ['getFolder', 'getCurrentFile', 'getFile', 'setFile', 'switchFile']
...
...
@@ -49,7 +59,7 @@ class FileManager extends Plugin {
*/
_handleExists
(
path
,
message
)
{
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 {
*/
_handleIsFile
(
path
,
message
)
{
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 {
*/
_handleIsDir
(
path
,
message
)
{
if
(
this
.
isFile
(
path
))
{
throw
new
Error
({
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
)
throw
createError
({
code
:
'ENOTDIR'
,
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 */
file
()
{
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
}
...
...
@@ -194,6 +175,9 @@ class FileManager extends Plugin {
unlink
(
path
)
{
this
.
_handleExists
(
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 {
*/
mkdir
(
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
)
...
...
@@ -347,7 +331,7 @@ class FileManager extends Plugin {
getFile
(
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
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
currentFile
()
===
path
)
return
resolve
(
this
.
editor
.
currentContent
())
...
...
@@ -382,7 +366,7 @@ class FileManager extends Plugin {
_setFileInternal
(
path
,
content
)
{
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 : Change Provider to Promise
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
src/app/files/fileProvider.js
View file @
de2a467c
...
...
@@ -139,10 +139,12 @@ class FileProvider {
}
isDirectory
(
path
)
{
path
=
this
.
removePrefix
(
path
)
return
window
.
remixFileSystem
.
statSync
(
path
).
isDirectory
()
}
isFile
(
path
)
{
path
=
this
.
removePrefix
(
path
)
return
window
.
remixFileSystem
.
statSync
(
path
).
isFile
()
}
...
...
@@ -156,9 +158,7 @@ class FileProvider {
const
stat
=
window
.
remixFileSystem
.
statSync
(
path
)
try
{
if
(
!
stat
.
isDirectory
())
{
window
.
remixFileSystem
.
unlinkSync
(
path
,
console
.
log
)
this
.
event
.
trigger
(
'fileRemoved'
,
[
this
.
_normalizePath
(
path
)])
return
true
return
this
.
removeFile
(
path
)
}
else
{
const
items
=
window
.
remixFileSystem
.
readdirSync
(
path
)
if
(
items
.
length
!==
0
)
{
...
...
@@ -167,8 +167,7 @@ class FileProvider {
if
(
window
.
remixFileSystem
.
statSync
(
curPath
).
isDirectory
())
{
// delete folder
this
.
remove
(
curPath
)
}
else
{
// delete file
window
.
remixFileSystem
.
unlinkSync
(
curPath
,
console
.
log
)
this
.
event
.
trigger
(
'fileRemoved'
,
[
this
.
_normalizePath
(
path
)])
this
.
removeFile
(
curPath
)
}
})
if
(
window
.
remixFileSystem
.
readdirSync
(
path
).
length
===
0
)
window
.
remixFileSystem
.
rmdirSync
(
path
,
console
.
log
)
...
...
@@ -185,6 +184,15 @@ class FileProvider {
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
)
{
var
unprefixedoldPath
=
this
.
removePrefix
(
oldPath
)
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