Sha256: bd760eec1faead625d4bfd783fe80e59f2f6b1dc7d1c59a84eed34bb1d7878e9

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 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] && !Array(opts[:exclude]).empty?)
          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

17 entries across 17 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/synced_folders/rsync/default_unix_cap.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.3.3.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.3.2.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.19.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.18.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.16.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.14.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.10.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.9.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.8.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.7.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.6.2 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.6.1 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.6.0 plugins/synced_folders/rsync/default_unix_cap.rb
vagrant-unbundled-2.2.5.0 plugins/synced_folders/rsync/default_unix_cap.rb