From 40c8a8bb84c56ac8fab3e16f4bc4568ca12b6d98 Mon Sep 17 00:00:00 2001 From: Tom Janson Date: Wed, 19 Sep 2018 18:17:44 +0200 Subject: [PATCH] add --read-only flag which prevents all writes --- bin/remixd | 3 ++- src/services/sharedFolder.js | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/remixd b/bin/remixd index ed5edcabae..5f2be4d1b3 100755 --- a/bin/remixd +++ b/bin/remixd @@ -10,6 +10,7 @@ program .usage('-s ') .description('Provide a two ways connection between the local computer and Remix IDE') .option('-s, --shared-folder ', 'Folder to share with Remix IDE') +.option('--read-only', 'Treat shared folder as read-only (experimental)') .option('-m, --mist', 'start mist') .option('-g, --geth', 'start geth') .option('-p, --dev-path ', 'Folder used by mist/geth to start the development instance') @@ -48,7 +49,7 @@ if (program.sharedFolder) { var sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], (webSocket) => { servicesList['sharedfolder'].setWebSocket(webSocket) servicesList['sharedfolder'].setupNotifications(program.sharedFolder) - servicesList['sharedfolder'].sharedFolder(program.sharedFolder) + servicesList['sharedfolder'].sharedFolder(program.sharedFolder, program.readOnly) }) killCallBack.push(sharedFolderrouter.start()) } diff --git a/src/services/sharedFolder.js b/src/services/sharedFolder.js index 76637e78b9..0965dcb400 100644 --- a/src/services/sharedFolder.js +++ b/src/services/sharedFolder.js @@ -12,8 +12,9 @@ module.exports = { this.websocket = websocket }, - sharedFolder: function (sharedFolder) { + sharedFolder: function (sharedFolder, readOnly) { this.sharedFolder = sharedFolder + this.readOnly = readOnly }, list: function (args, cb) { @@ -62,6 +63,7 @@ module.exports = { }, set: function (args, cb) { + if (this.readOnly) return cb('Cannot write file: read-only mode selected') var path = utils.absolutePath(args.path, this.sharedFolder) if (fs.existsSync(path) && !isRealPath(path, cb)) return if (args.content === 'undefined') { // no !!!!! @@ -76,6 +78,7 @@ module.exports = { }, rename: function (args, cb) { + if (this.readOnly) return cb('Cannot rename file: read-only mode selected') var oldpath = utils.absolutePath(args.oldPath, this.sharedFolder) if (!fs.existsSync(oldpath)) { return cb('File not found ' + oldpath) @@ -89,6 +92,7 @@ module.exports = { }, remove: function (args, cb) { + if (this.readOnly) return cb('Cannot remove file: read-only mode selected') var path = utils.absolutePath(args.path, this.sharedFolder) if (!fs.existsSync(path)) { return cb('File not found ' + path)