Sha256: 07cee4984964529988c3b8c4f69813d4567c0e89be7c404203b5bbed0fdc47bd

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require "vagrant"

module VagrantPlugins
  module RsyncBlitz
    class StartupRsync
      include Vagrant::Action::Builtin::MixinSyncedFolders

      def initialize(app, env)
        @app = app
        @blitz_startup_registered = false
        @rsync_folder_count = 0
      end

      def call(env)
        folders = synced_folders(env[:machine])
        @rsync_folder_count += folders[:rsync].size if folders.key?(:rsync)

        @app.call(env)

        # Ensure only one at_exit block is registered.
        return unless @blitz_startup_registered == false

        return unless env[:machine].config.blitz.autostart == true

        at_exit do
          unless $!.is_a?(SystemExit)
            env[:ui].warn "Vagrant's startup was interrupted by an exception."
            exit 1
          end

          exit_status = $!.status
          if exit_status != 0
            env[:ui].warn "The previous process exited with exit code #{exit_status}."
            exit exit_status
          end

          # Don't run if there are no rsynced folders.
          unless @rsync_folder_count == 0 then
            env[:machine].env.cli("rsync-blitz")
          end
        end

        @blitz_startup_registered = true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-rsync-blitz-2.0.0 lib/vagrant-rsync-blitz/action/startup_rsync.rb