Sha256: e627c93cf9298e30dcd09e1b804ba2c444d4420001aee848c74cf3b2b1efb15b

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

require "shellwords"

module VagrantPlugins
  module SyncedFolderRSync
    # This module provides default rsync capabilities for
    # unix type operating systems.
    module DefaultUnixCap

      def rsync_installed(machine)
        machine.communicate.test("which rsync")
      end

      def rsync_command(machine)
        "sudo rsync"
      end

      def rsync_pre(machine, opts)
        guest_path = Shellwords.escape(opts[:guestpath])
        machine.communicate.sudo("mkdir -p #{guest_path}")
      end

      def rsync_post(machine, opts)
        if opts.key?(:chown) && !opts[:chown]
          return
        end
        machine.communicate.sudo(build_rsync_chown(opts))
      end

      def build_rsync_chown(opts)
        guest_path = Shellwords.escape(opts[:guestpath])
        if(opts[:exclude])
          exclude_base = Pathname.new(opts[:guestpath])
          exclusions = Array(opts[:exclude]).map do |ex_path|
            ex_path = ex_path.slice(1, ex_path.size) if ex_path.start_with?(File::SEPARATOR)
            "-path #{Shellwords.escape(exclude_base.join(ex_path))} -prune"
          end.join(" -o ") + " -o "
        end
        "find #{guest_path} #{exclusions}" \
          "'!' -type l -a " \
          "'(' ! -user #{opts[:owner]} -or ! -group #{opts[:group]} ')' -exec " \
          "chown #{opts[:owner]}:#{opts[:group]} '{}' +"
      end
    end
  end
end

Version data entries

29 entries across 25 versions & 4 rubygems

Version Path
vagrant-unbundled-2.2.2.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.0.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.1.4.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.1.2.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.1.1.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.0.4.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.0.3.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.0.2.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.0.1.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/synced_folders/rsync/default_unix_cap.rb