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
79ea3719
Commit
79ea3719
authored
Sep 13, 2021
by
yann300
Committed by
davidzagi93@gmail.com
Sep 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
normalize path api
parent
ae94f77a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
fileManager.js
apps/remix-ide/src/app/files/fileManager.js
+17
-0
No files found.
apps/remix-ide/src/app/files/fileManager.js
View file @
79ea3719
...
@@ -61,6 +61,10 @@ class FileManager extends Plugin {
...
@@ -61,6 +61,10 @@ class FileManager extends Plugin {
return
path
.
replace
(
/^
\/
browser
\/
/
,
''
).
replace
(
/^browser
\/
/
,
''
)
// forbids plugin to access the root filesystem
return
path
.
replace
(
/^
\/
browser
\/
/
,
''
).
replace
(
/^browser
\/
/
,
''
)
// forbids plugin to access the root filesystem
}
}
normalize
(
path
)
{
return
path
.
replace
(
/^
\/
+/
,
''
)
}
/**
/**
* Emit error if path doesn't exist
* Emit error if path doesn't exist
* @param {string} path path of the file/directory
* @param {string} path path of the file/directory
...
@@ -119,6 +123,7 @@ class FileManager extends Plugin {
...
@@ -119,6 +123,7 @@ class FileManager extends Plugin {
*/
*/
exists
(
path
)
{
exists
(
path
)
{
try
{
try
{
path
=
this
.
normalize
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
limitPluginScope
(
path
)
const
provider
=
this
.
fileProviderOf
(
path
)
const
provider
=
this
.
fileProviderOf
(
path
)
const
result
=
provider
.
exists
(
path
)
const
result
=
provider
.
exists
(
path
)
...
@@ -168,6 +173,7 @@ class FileManager extends Plugin {
...
@@ -168,6 +173,7 @@ class FileManager extends Plugin {
* @returns {void}
* @returns {void}
*/
*/
async
open
(
path
)
{
async
open
(
path
)
{
path
=
this
.
normalize
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
getPathFromUrl
(
path
).
file
path
=
this
.
getPathFromUrl
(
path
).
file
await
this
.
_handleExists
(
path
,
`Cannot open file
${
path
}
`
)
await
this
.
_handleExists
(
path
,
`Cannot open file
${
path
}
`
)
...
@@ -183,6 +189,7 @@ class FileManager extends Plugin {
...
@@ -183,6 +189,7 @@ class FileManager extends Plugin {
*/
*/
async
writeFile
(
path
,
data
)
{
async
writeFile
(
path
,
data
)
{
try
{
try
{
path
=
this
.
normalize
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
limitPluginScope
(
path
)
if
(
await
this
.
exists
(
path
))
{
if
(
await
this
.
exists
(
path
))
{
await
this
.
_handleIsFile
(
path
,
`Cannot write file
${
path
}
`
)
await
this
.
_handleIsFile
(
path
,
`Cannot write file
${
path
}
`
)
...
@@ -204,6 +211,7 @@ class FileManager extends Plugin {
...
@@ -204,6 +211,7 @@ class FileManager extends Plugin {
*/
*/
async
readFile
(
path
)
{
async
readFile
(
path
)
{
try
{
try
{
path
=
this
.
normalize
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
limitPluginScope
(
path
)
await
this
.
_handleExists
(
path
,
`Cannot read file
${
path
}
`
)
await
this
.
_handleExists
(
path
,
`Cannot read file
${
path
}
`
)
await
this
.
_handleIsFile
(
path
,
`Cannot read file
${
path
}
`
)
await
this
.
_handleIsFile
(
path
,
`Cannot read file
${
path
}
`
)
...
@@ -221,6 +229,8 @@ class FileManager extends Plugin {
...
@@ -221,6 +229,8 @@ class FileManager extends Plugin {
*/
*/
async
copyFile
(
src
,
dest
,
customName
)
{
async
copyFile
(
src
,
dest
,
customName
)
{
try
{
try
{
src
=
this
.
normalize
(
src
)
dest
=
this
.
normalize
(
dest
)
src
=
this
.
limitPluginScope
(
src
)
src
=
this
.
limitPluginScope
(
src
)
dest
=
this
.
limitPluginScope
(
dest
)
dest
=
this
.
limitPluginScope
(
dest
)
await
this
.
_handleExists
(
src
,
`Cannot copy from
${
src
}
. Path does not exist.`
)
await
this
.
_handleExists
(
src
,
`Cannot copy from
${
src
}
. Path does not exist.`
)
...
@@ -245,6 +255,8 @@ class FileManager extends Plugin {
...
@@ -245,6 +255,8 @@ class FileManager extends Plugin {
*/
*/
async
copyDir
(
src
,
dest
)
{
async
copyDir
(
src
,
dest
)
{
try
{
try
{
src
=
this
.
normalize
(
src
)
dest
=
this
.
normalize
(
dest
)
src
=
this
.
limitPluginScope
(
src
)
src
=
this
.
limitPluginScope
(
src
)
dest
=
this
.
limitPluginScope
(
dest
)
dest
=
this
.
limitPluginScope
(
dest
)
await
this
.
_handleExists
(
src
,
`Cannot copy from
${
src
}
. Path does not exist.`
)
await
this
.
_handleExists
(
src
,
`Cannot copy from
${
src
}
. Path does not exist.`
)
...
@@ -281,6 +293,8 @@ class FileManager extends Plugin {
...
@@ -281,6 +293,8 @@ class FileManager extends Plugin {
*/
*/
async
rename
(
oldPath
,
newPath
)
{
async
rename
(
oldPath
,
newPath
)
{
try
{
try
{
oldPath
=
this
.
normalize
(
oldPath
)
newPath
=
this
.
normalize
(
newPath
)
oldPath
=
this
.
limitPluginScope
(
oldPath
)
oldPath
=
this
.
limitPluginScope
(
oldPath
)
newPath
=
this
.
limitPluginScope
(
newPath
)
newPath
=
this
.
limitPluginScope
(
newPath
)
await
this
.
_handleExists
(
oldPath
,
`Cannot rename
${
oldPath
}
`
)
await
this
.
_handleExists
(
oldPath
,
`Cannot rename
${
oldPath
}
`
)
...
@@ -313,6 +327,7 @@ class FileManager extends Plugin {
...
@@ -313,6 +327,7 @@ class FileManager extends Plugin {
*/
*/
async
mkdir
(
path
)
{
async
mkdir
(
path
)
{
try
{
try
{
path
=
this
.
normalize
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
limitPluginScope
(
path
)
if
(
await
this
.
exists
(
path
))
{
if
(
await
this
.
exists
(
path
))
{
throw
createError
({
code
:
'EEXIST'
,
message
:
`Cannot create directory
${
path
}
`
})
throw
createError
({
code
:
'EEXIST'
,
message
:
`Cannot create directory
${
path
}
`
})
...
@@ -332,6 +347,7 @@ class FileManager extends Plugin {
...
@@ -332,6 +347,7 @@ class FileManager extends Plugin {
*/
*/
async
readdir
(
path
)
{
async
readdir
(
path
)
{
try
{
try
{
path
=
this
.
normalize
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
limitPluginScope
(
path
)
await
this
.
_handleExists
(
path
)
await
this
.
_handleExists
(
path
)
await
this
.
_handleIsDir
(
path
)
await
this
.
_handleIsDir
(
path
)
...
@@ -356,6 +372,7 @@ class FileManager extends Plugin {
...
@@ -356,6 +372,7 @@ class FileManager extends Plugin {
*/
*/
async
remove
(
path
)
{
async
remove
(
path
)
{
try
{
try
{
path
=
this
.
normalize
(
path
)
path
=
this
.
limitPluginScope
(
path
)
path
=
this
.
limitPluginScope
(
path
)
await
this
.
_handleExists
(
path
,
`Cannot remove file or directory
${
path
}
`
)
await
this
.
_handleExists
(
path
,
`Cannot remove file or directory
${
path
}
`
)
const
provider
=
this
.
fileProviderOf
(
path
)
const
provider
=
this
.
fileProviderOf
(
path
)
...
...
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