at 22.05-pre 93 lines 3.1 kB view raw
1From: Antonio Terceiro <terceiro@debian.org> 2Date: Wed, 27 May 2015 09:36:17 -0300 3Subject: Support system-installed plugins 4Source: https://salsa.debian.org/ruby-team/vagrant/-/blob/9d86f222/debian/patches/0004-Support-system-installed-plugins.patch 5 6Plugins must be installed as regular Ruby libraries, and they must 7contain /usr/share/vagrant-plugins/plugins.d/$PLUGINNAME.json with the 8following content: 9 10{ 11 "${PLUGINNAME}": { 12 "ruby_version":"$(ruby -e 'puts RUBY_VERSION')", 13 "vagrant_version":"$(cat /usr/share/vagrant/version.txt)", 14 "gem_version":"", 15 "require":"", 16 "sources":[] 17 } 18} 19--- 20 lib/vagrant/plugin/manager.rb | 4 ++-- 21 lib/vagrant/plugin/state_file.rb | 22 +++++++++++++++++++++- 22 2 files changed, 23 insertions(+), 3 deletions(-) 23 24diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb 25index 9058e68..2772131 100644 26--- a/lib/vagrant/plugin/manager.rb 27+++ b/lib/vagrant/plugin/manager.rb 28@@ -18,7 +18,7 @@ module Vagrant 29 30 # Returns the path to the [StateFile] for system plugins. 31 def self.system_plugins_file 32- dir = Vagrant.installer_embedded_dir 33+ dir = '@system_plugin_dir@' 34 return nil if !dir 35 Pathname.new(dir).join("plugins.json") 36 end 37@@ -38,7 +38,7 @@ module Vagrant 38 39 system_path = self.class.system_plugins_file 40 @system_file = nil 41- @system_file = StateFile.new(system_path) if system_path && system_path.file? 42+ @system_file = StateFile.new(system_path, true) if system_path && system_path.file? 43 44 @local_file = nil 45 @globalized = @localized = false 46diff --git a/lib/vagrant/plugin/state_file.rb b/lib/vagrant/plugin/state_file.rb 47index c6872d4..935d431 100644 48--- a/lib/vagrant/plugin/state_file.rb 49+++ b/lib/vagrant/plugin/state_file.rb 50@@ -11,8 +11,9 @@ module Vagrant 51 # @return [Pathname] path to file 52 attr_reader :path 53 54- def initialize(path) 55+ def initialize(path, system = false) 56 @path = path 57+ @system = system 58 59 @data = {} 60 if @path.exist? 61@@ -28,6 +29,21 @@ module Vagrant 62 63 @data["version"] ||= "1" 64 @data["installed"] ||= {} 65+ load_extra_plugins 66+ end 67+ 68+ def load_extra_plugins 69+ extra_plugins = Dir.glob(@path.dirname.join('plugins.d', '*.json')) 70+ extra_plugins.each do |filename| 71+ json = File.read(filename) 72+ begin 73+ plugin_data = JSON.parse(json) 74+ @data["installed"].merge!(plugin_data) 75+ rescue JSON::ParserError => e 76+ raise Vagrant::Errors::PluginStateFileParseError, 77+ path: filename, message: e.message 78+ end 79+ end 80 end 81 82 # Add a plugin that is installed to the state file. 83@@ -107,6 +123,10 @@ module Vagrant 84 f.close 85 FileUtils.mv(f.path, @path) 86 end 87+ rescue Errno::EACCES 88+ # Ignore permission denied against system-installed plugins; regular 89+ # users are not supposed to write there. 90+ raise unless @system 91 end 92 93 protected