Commit 89bb8da9 authored by yann300's avatar yann300

do not forward symbolic link

parent e9c17597
...@@ -11,7 +11,8 @@ if (!program.sharedFolder) { ...@@ -11,7 +11,8 @@ if (!program.sharedFolder) {
program.outputHelp() program.outputHelp()
process.exit(1) process.exit(1)
} else { } 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() var router = new Router()
......
...@@ -17,6 +17,7 @@ module.exports = { ...@@ -17,6 +17,7 @@ module.exports = {
get: function (args, cb) { get: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
if (!isRealPath(path, cb)) return
isbinaryfile(path, (error, isBinary) => { isbinaryfile(path, (error, isBinary) => {
if (error) console.log(error) if (error) console.log(error)
if (isBinary) { if (isBinary) {
...@@ -32,6 +33,7 @@ module.exports = { ...@@ -32,6 +33,7 @@ module.exports = {
set: function (args, cb) { set: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
if (!isRealPath(path, cb)) return
this.trackDownStreamUpdate[path] = path this.trackDownStreamUpdate[path] = path
fs.writeFile(path, args.content, 'utf8', (error, data) => { fs.writeFile(path, args.content, 'utf8', (error, data) => {
if (error) console.log(error) if (error) console.log(error)
...@@ -42,6 +44,8 @@ module.exports = { ...@@ -42,6 +44,8 @@ module.exports = {
rename: function (args, cb) { rename: function (args, cb) {
var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder) var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder)
var newpath = utils.absolutePath(args.newPath, 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) => { fs.move(oldpath, newpath, (error, data) => {
if (error) console.log(error) if (error) console.log(error)
cb(error, data) cb(error, data)
...@@ -50,6 +54,7 @@ module.exports = { ...@@ -50,6 +54,7 @@ module.exports = {
remove: function (args, cb) { remove: function (args, cb) {
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
if (!isRealPath(path, cb)) return
fs.remove(path, (error, data) => { fs.remove(path, (error, data) => {
if (error) console.log(error) if (error) console.log(error)
cb(error, data) cb(error, data)
...@@ -57,6 +62,7 @@ module.exports = { ...@@ -57,6 +62,7 @@ module.exports = {
}, },
setupNotifications: function (websocket, path) { setupNotifications: function (websocket, path) {
if (!isRealPath(path)) return
watch.createMonitor(path, (monitor) => { watch.createMonitor(path, (monitor) => {
this.monitors.push(monitor) this.monitors.push(monitor)
monitor.on('created', (f, stat) => { monitor.on('created', (f, stat) => {
...@@ -82,6 +88,17 @@ module.exports = { ...@@ -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) { function message (name, value) {
return JSON.stringify({type: 'notification', scope: 'sharedfolder', name: name, value: value}) return JSON.stringify({type: 'notification', scope: 'sharedfolder', name: name, value: value})
} }
...@@ -48,11 +48,13 @@ function walkSync (dir, filelist, sharedFolder) { ...@@ -48,11 +48,13 @@ function walkSync (dir, filelist, sharedFolder) {
filelist = filelist || {} filelist = filelist || {}
files.forEach(function (file) { files.forEach(function (file) {
var subElement = path.join(dir, file) var subElement = path.join(dir, file)
if (fs.statSync(subElement).isDirectory()) { if (!fs.lstatSync(subElement).isSymbolicLink()) {
filelist = walkSync(subElement, filelist, sharedFolder) if (fs.statSync(subElement).isDirectory()) {
} else { filelist = walkSync(subElement, filelist, sharedFolder)
var relative = relativePath(subElement, sharedFolder) } else {
filelist[relative] = isbinaryfile.sync(subElement) var relative = relativePath(subElement, sharedFolder)
filelist[relative] = isbinaryfile.sync(subElement)
}
} }
}) })
return filelist 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