Commit 89bb8da9 authored by yann300's avatar yann300

do not forward symbolic link

parent e9c17597
......@@ -11,7 +11,8 @@ if (!program.sharedFolder) {
program.outputHelp()
process.exit(1)
} else {
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.\n')
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.')
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolinc links are not forwarded to Remix IDE\n')
}
var router = new Router()
......
......@@ -17,6 +17,7 @@ module.exports = {
get: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder)
if (!isRealPath(path, cb)) return
isbinaryfile(path, (error, isBinary) => {
if (error) console.log(error)
if (isBinary) {
......@@ -32,6 +33,7 @@ module.exports = {
set: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder)
if (!isRealPath(path, cb)) return
this.trackDownStreamUpdate[path] = path
fs.writeFile(path, args.content, 'utf8', (error, data) => {
if (error) console.log(error)
......@@ -42,6 +44,8 @@ module.exports = {
rename: function (args, cb) {
var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder)
var newpath = utils.absolutePath(args.newPath, this.sharedFolder)
if (!isRealPath(oldpath, cb)) return
if (!isRealPath(newpath, cb)) return
fs.move(oldpath, newpath, (error, data) => {
if (error) console.log(error)
cb(error, data)
......@@ -50,6 +54,7 @@ module.exports = {
remove: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder)
if (!isRealPath(path, cb)) return
fs.remove(path, (error, data) => {
if (error) console.log(error)
cb(error, data)
......@@ -57,6 +62,7 @@ module.exports = {
},
setupNotifications: function (websocket, path) {
if (!isRealPath(path)) return
watch.createMonitor(path, (monitor) => {
this.monitors.push(monitor)
monitor.on('created', (f, stat) => {
......@@ -82,6 +88,17 @@ module.exports = {
}
}
function isRealPath (path, cb) {
var realPath = fs.realpathSync(path)
var isRealPath = path === realPath
var mes = '[WARN] Symbolic link modification not allowed : ' + path + ' | ' + realPath
if (!isRealPath) {
console.log('\x1b[33m%s\x1b[0m', mes)
}
if (cb && !isRealPath) cb(mes)
return isRealPath
}
function message (name, value) {
return JSON.stringify({type: 'notification', scope: 'sharedfolder', name: name, value: value})
}
......@@ -48,11 +48,13 @@ function walkSync (dir, filelist, sharedFolder) {
filelist = filelist || {}
files.forEach(function (file) {
var subElement = path.join(dir, file)
if (fs.statSync(subElement).isDirectory()) {
filelist = walkSync(subElement, filelist, sharedFolder)
} else {
var relative = relativePath(subElement, sharedFolder)
filelist[relative] = isbinaryfile.sync(subElement)
if (!fs.lstatSync(subElement).isSymbolicLink()) {
if (fs.statSync(subElement).isDirectory()) {
filelist = walkSync(subElement, filelist, sharedFolder)
} else {
var relative = relativePath(subElement, sharedFolder)
filelist[relative] = isbinaryfile.sync(subElement)
}
}
})
return filelist
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment