Module: Lono::Utils::Rsync

Included in:
AppFile::Build::LambdaLayer::RubyPackager, Configset::S3File::Build
Defined in:
lib/lono/utils/rsync.rb

Constant Summary collapse

@@rsync_installed =
false

Instance Method Summary collapse

Instance Method Details

#check_rsync_installed!Object



27
28
29
30
31
32
33
34
# File 'lib/lono/utils/rsync.rb', line 27

def check_rsync_installed!
  return if @@rsync_installed # only check once
  if system "type rsync > /dev/null 2>&1"
    @@rsync_installed = true
  else
    raise "ERROR: Rsync is required. Rsync does not seem to be installed.".color(:red)
  end
end

#rsync(src, dest) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lono/utils/rsync.rb', line 14

def rsync(src, dest)
  # Using FileUtils.cp_r doesnt work if there are special files like socket files in the src dir.
  # Instead of using this hack https://bugs.ruby-lang.org/issues/10104
  # Using rsync to perform the copy.
  src.chop! if src.ends_with?('/')
  dest.chop! if dest.ends_with?('/')
  check_rsync_installed!
  # Ensures required trailing slashes
  FileUtils.mkdir_p(File.dirname(dest))
  sh "rsync -a --links --no-specials --no-devices #{Shellwords.escape(src)}/ #{Shellwords.escape(dest)}/"
end

#sh(command) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/lono/utils/rsync.rb', line 5

def sh(command)
  puts "=> #{command}"
  out = `#{command}`
  puts out if ENV['LONO_DEBUG_SH']
  success = $?.success?
  raise("ERROR: running command #{command}").color(:red) unless success
  success
end