Sha256: 7c0ecea8a82f2584976b25ce3e70dfd61fac398fb8937aa6db592ee1d4806d10

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module VagrantPlugins
  module FileUpload
    class Provisioner < Vagrant.plugin("2", :provisioner)
      def provision
        @machine.communicate.tap do |comm|
          source = File.expand_path(config.source)
          destination = expand_guest_path(config.destination)

          # if source is a directory, make it then trim destination with dirname
          # Make sure the remote path exists
          if File.directory?(source)
            # We need to make sure the actual destination folder
            # also exists before uploading, otherwise
            # you will get nested folders. We also need to append
            # a './' to the source folder so we copy the contents
            # rather than the folder itself, in case a users destination
            # folder differs from its source.
            #
            # https://serverfault.com/questions/538368/make-scp-always-overwrite-or-create-directory
            # https://unix.stackexchange.com/questions/292641/get-scp-path-behave-like-rsync-path/292732
            command = "mkdir -p \"%s\"" % destination
            source << "/."
          else
            command = "mkdir -p \"%s\"" % File.dirname(destination)
          end
          comm.execute(command)

          # now upload the file
          comm.upload(source, destination)
        end
      end

      private

      # Expand the guest path if the guest has the capability
      def expand_guest_path(destination)
        if machine.guest.capability?(:shell_expand_guest_path)
          machine.guest.capability(:shell_expand_guest_path, destination)
        else
          destination
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-unbundled-1.9.8.1 plugins/provisioners/file/provisioner.rb