File: repair_plugins.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (64 lines) | stat: -rw-r--r-- 2,339 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require "vagrant/plugin/manager"

module VagrantPlugins
  module CommandPlugin
    module Action
      # This middleware attempts to repair installed plugins.
      #
      # In general, if plugins are failing to properly load the
      # core issue will likely be one of two issues:
      #   1. manual modifications within ~/.vagrant.d/
      #   2. vagrant upgrade
      # Running an install on configured plugin set will most
      # likely fix these issues, which is all this action does.
      class RepairPlugins
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::plugins::plugincommand::repair")
        end

        def call(env)
          env[:ui].info(I18n.t("vagrant.commands.plugin.repairing"))
          plugins = Vagrant::Plugin::Manager.instance.globalize!
          begin
            ENV["VAGRANT_DISABLE_PLUGIN_INIT"] = nil
            Vagrant::Bundler.instance.init!(plugins, :repair)
            ENV["VAGRANT_DISABLE_PLUGIN_INIT"] = "1"
            env[:ui].info(I18n.t("vagrant.commands.plugin.repair_complete"))
          rescue => e
            @logger.error("Failed to repair user installed plugins: #{e.class} - #{e}")
            e.backtrace.each do |backtrace_line|
              @logger.debug(backtrace_line)
            end
            env[:ui].error(I18n.t("vagrant.commands.plugin.repair_failed", message: e.message))
          end
          # Continue
          @app.call(env)
        end
      end

      class RepairPluginsLocal
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::plugins::plugincommand::repair_local")
        end

        def call(env)
          env[:ui].info(I18n.t("vagrant.commands.plugin.repairing_local"))
          Vagrant::Plugin::Manager.instance.localize!(env[:env]).each_pair do |pname, pinfo|
            env[:env].action_runner.run(Action.action_install,
              plugin_name: pname,
              plugin_entry_point: pinfo["require"],
              plugin_sources: pinfo["sources"],
              plugin_version: pinfo["gem_version"],
              plugin_env_local: true
            )
          end
          env[:ui].info(I18n.t("vagrant.commands.plugin.repair_local_complete"))
          # Continue
          @app.call(env)
        end
      end
    end
  end
end