Commit 40c8a8bb authored by Tom Janson's avatar Tom Janson

add --read-only flag which prevents all writes

parent a0823a3e
...@@ -10,6 +10,7 @@ program ...@@ -10,6 +10,7 @@ program
.usage('-s <shared folder>') .usage('-s <shared folder>')
.description('Provide a two ways connection between the local computer and Remix IDE') .description('Provide a two ways connection between the local computer and Remix IDE')
.option('-s, --shared-folder <path>', 'Folder to share with Remix IDE') .option('-s, --shared-folder <path>', 'Folder to share with Remix IDE')
.option('--read-only', 'Treat shared folder as read-only (experimental)')
.option('-m, --mist', 'start mist') .option('-m, --mist', 'start mist')
.option('-g, --geth', 'start geth') .option('-g, --geth', 'start geth')
.option('-p, --dev-path <dev-path>', 'Folder used by mist/geth to start the development instance') .option('-p, --dev-path <dev-path>', 'Folder used by mist/geth to start the development instance')
...@@ -48,7 +49,7 @@ if (program.sharedFolder) { ...@@ -48,7 +49,7 @@ if (program.sharedFolder) {
var sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], (webSocket) => { var sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], (webSocket) => {
servicesList['sharedfolder'].setWebSocket(webSocket) servicesList['sharedfolder'].setWebSocket(webSocket)
servicesList['sharedfolder'].setupNotifications(program.sharedFolder) servicesList['sharedfolder'].setupNotifications(program.sharedFolder)
servicesList['sharedfolder'].sharedFolder(program.sharedFolder) servicesList['sharedfolder'].sharedFolder(program.sharedFolder, program.readOnly)
}) })
killCallBack.push(sharedFolderrouter.start()) killCallBack.push(sharedFolderrouter.start())
} }
......
...@@ -12,8 +12,9 @@ module.exports = { ...@@ -12,8 +12,9 @@ module.exports = {
this.websocket = websocket this.websocket = websocket
}, },
sharedFolder: function (sharedFolder) { sharedFolder: function (sharedFolder, readOnly) {
this.sharedFolder = sharedFolder this.sharedFolder = sharedFolder
this.readOnly = readOnly
}, },
list: function (args, cb) { list: function (args, cb) {
...@@ -62,6 +63,7 @@ module.exports = { ...@@ -62,6 +63,7 @@ module.exports = {
}, },
set: function (args, cb) { set: function (args, cb) {
if (this.readOnly) return cb('Cannot write file: read-only mode selected')
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
if (fs.existsSync(path) && !isRealPath(path, cb)) return if (fs.existsSync(path) && !isRealPath(path, cb)) return
if (args.content === 'undefined') { // no !!!!! if (args.content === 'undefined') { // no !!!!!
...@@ -76,6 +78,7 @@ module.exports = { ...@@ -76,6 +78,7 @@ module.exports = {
}, },
rename: function (args, cb) { rename: function (args, cb) {
if (this.readOnly) return cb('Cannot rename file: read-only mode selected')
var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder) var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder)
if (!fs.existsSync(oldpath)) { if (!fs.existsSync(oldpath)) {
return cb('File not found ' + oldpath) return cb('File not found ' + oldpath)
...@@ -89,6 +92,7 @@ module.exports = { ...@@ -89,6 +92,7 @@ module.exports = {
}, },
remove: function (args, cb) { remove: function (args, cb) {
if (this.readOnly) return cb('Cannot remove file: read-only mode selected')
var path = utils.absolutePath(args.path, this.sharedFolder) var path = utils.absolutePath(args.path, this.sharedFolder)
if (!fs.existsSync(path)) { if (!fs.existsSync(path)) {
return cb('File not found ' + path) return cb('File not found ' + path)
......
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