Class: VagrantReflect::Syncer

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-reflect/util/syncer.rb

Overview

This is a helper that abstracts out the functionality of rsyncing folders so that it can be called from anywhere.

Constant Summary collapse

RSYNC_TO_REGEXP_PATTERNS =
[
  ['.', '\\.'],
  ['***', '|||EMPTY|||'],
  ['**', '|||GLOBAL|||'],
  ['*', '|||PATH|||'],
  ['?', '[^/]'],
  ['|||PATH|||', '[^/]+'],
  ['|||GLOBAL|||', '.+'],
  ['|||EMPTY|||', '.*']
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(machine, opts) ⇒ Syncer

Returns a new instance of Syncer.



20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-reflect/util/syncer.rb', line 20

def initialize(machine, opts)
  @opts = opts
  @machine = machine
  @workdir = @machine.env.root_path.to_s

  init_paths
  init_connection_info
  init_excludes
  init_commands
end

Instance Method Details

#excludes_to_regexpObject

This converts the rsync exclude patterns to regular expressions we can send to Listen.



48
49
50
51
52
# File 'lib/vagrant-reflect/util/syncer.rb', line 48

def excludes_to_regexp
  return @regexp if @regexp

  @regexp = @excludes.map(&method(:exclude_to_regex_single))
end

#log_configurationObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vagrant-reflect/util/syncer.rb', line 31

def log_configuration
  @machine.ui.info(
    I18n.t(
      'vagrant.plugins.vagrant-reflect.rsync_folder_configuration',
      guestpath: @guestpath,
      hostpath: @hostpath))

  return if @excludes.empty?

  @machine.ui.info(
    I18n.t(
      'vagrant.plugins.vagrant-reflect.rsync_folder_excludes',
      excludes: @excludes.inspect))
end

#sync_fullObject



58
59
60
61
# File 'lib/vagrant-reflect/util/syncer.rb', line 58

def sync_full
  r = Vagrant::Util::SubprocessPatched.execute(*@rsync_command_full)
  check_exit @rsync_command_full, r
end

#sync_incremental(items, &block) ⇒ Object



54
55
56
# File 'lib/vagrant-reflect/util/syncer.rb', line 54

def sync_incremental(items, &block)
  send_items_to_command items, @rsync_command_inc, &block
end

#sync_removals(items, &block) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/vagrant-reflect/util/syncer.rb', line 63

def sync_removals(items, &block)
  # Look for removed directories and fill in guest paths
  dirs = prepare_items_for_removal(items)

  send_items_to_command items, @rm_command, &block
  sync_removals_parents dirs.values, &block unless dirs.empty?
end

#sync_removals_parents(guest_items, &block) ⇒ Object



71
72
73
# File 'lib/vagrant-reflect/util/syncer.rb', line 71

def sync_removals_parents(guest_items, &block)
  send_items_to_command guest_items, @rmdir_command, &block
end