You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/10/26 15:08:54 UTC

tinkerpop git commit: Better respected permissions on the `plugins.txt` file

Repository: tinkerpop
Updated Branches:
  refs/heads/tp32 d459c6a9c -> 0282615ac


Better respected permissions on the `plugins.txt` file

Prevented writing if marked as read-only  CTR


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/0282615a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/0282615a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/0282615a

Branch: refs/heads/tp32
Commit: 0282615ac782282afaeb0d3441a66a51c17d1b60
Parents: d459c6a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Oct 26 11:07:54 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Oct 26 11:07:54 2017 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                                |  1 +
 .../tinkerpop/gremlin/console/Mediator.groovy     | 18 ++++++++++++------
 .../gremlin/console/commands/PluginCommand.groovy | 15 +++++++++------
 3 files changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0282615a/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 0f0abcd..8e7657c 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -23,6 +23,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 [[release-3-2-7]]
 === TinkerPop 3.2.7 (Release Date: NOT OFFICIALLY RELEASED YET)
 
+* Better respected permissions on the `plugins.txt` file and prevented writing if marked as read-only.
 * Added getters for the lambdas held by `LambdaCollectingBarrierStep`, `LambdaFlatMapStep` and `LambdaSideEffectStep`.
 * Fixed an old hack in `GroovyTranslator` and `PythonTranslator` where `Elements` were being mapped to their id only.
 * Fixed an "attachement"-bug in `InjectStep` with a solution generalized to `StartStep`.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0282615a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Mediator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Mediator.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Mediator.groovy
index 2f5b827..17dfb43 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Mediator.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Mediator.groovy
@@ -75,15 +75,21 @@ class Mediator {
     def writePluginState() {
         def file = new File(ConsoleFs.PLUGIN_CONFIG_FILE)
 
-        // ensure that the directories exist to hold the file.
-        file.mkdirs()
+        def canWrite = file.canWrite()
+        if (canWrite) {
 
-        if (file.exists())
-            file.delete()
+            // ensure that the directories exist to hold the file.
+            file.mkdirs()
 
-        new File(ConsoleFs.PLUGIN_CONFIG_FILE).withWriter { out ->
-            activePlugins().each { k, v -> out << (k + LINE_SEP) }
+            if (file.exists())
+                file.delete()
+
+            new File(ConsoleFs.PLUGIN_CONFIG_FILE).withWriter { out ->
+                activePlugins().each { k, v -> out << (k + LINE_SEP) }
+            }
         }
+
+        return canWrite
     }
 
     def activePlugins() {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0282615a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/PluginCommand.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/PluginCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/PluginCommand.groovy
index 15dcd20..98cd7cf 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/PluginCommand.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/PluginCommand.groovy
@@ -18,6 +18,7 @@
  */
 package org.apache.tinkerpop.gremlin.console.commands
 
+import org.apache.tinkerpop.gremlin.console.ConsoleFs
 import org.apache.tinkerpop.gremlin.console.Mediator
 import org.codehaus.groovy.tools.shell.ComplexCommandSupport
 import org.codehaus.groovy.tools.shell.Groovysh
@@ -45,9 +46,10 @@ class PluginCommand extends ComplexCommandSupport {
         mediator.showShellEvaluationOutput(false)
         mediator.availablePlugins.values().find { it.plugin.name == pluginName }.activate()
         mediator.showShellEvaluationOutput(true)
-        mediator.writePluginState()
-
-        return "$pluginName activated"
+        if (mediator.writePluginState())
+            return "$pluginName activated"
+        else
+            return "$pluginName activated but " + ConsoleFs.PLUGIN_CONFIG_FILE + " is readonly - the plugin list will remain unchanged on console restart"
     }
 
     def Object do_unuse = { List<String> arguments ->
@@ -58,9 +60,10 @@ class PluginCommand extends ComplexCommandSupport {
             return "$pluginName could not be found - use ':plugin list' to see available plugins"
 
         mediator.availablePlugins.values().find { it.plugin.name == pluginName }.deactivate()
-        mediator.writePluginState()
-
-        return "$pluginName deactivated - restart your console for this to take effect"
+        if (mediator.writePluginState())
+            return "$pluginName deactivated - restart your console for this to take effect"
+        else
+            return "$pluginName deactivated but " + ConsoleFs.PLUGIN_CONFIG_FILE + " is readonly - the plugin list will remain unchanged on console restart"
     }
 
     def do_list = { List<String> arguments ->