Sha256: 40dfbc51a61268c5f2f74ba28815c2bb41563a3c9adad1e7ed7f846987dfcb02

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'shellwords'

class Lono::Files::Builder::LambdaLayer
  module Rsync
    def sh(command)
      logger.debug "=> #{command}"
      out = `#{command}`
      logger.debug out
      success = $?.success?
      raise("ERROR: running command #{command}").color(:red) unless success
      success
    end

    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

    @@rsync_installed = false
    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lono-8.0.0.pre.rc6 lib/lono/files/builder/lambda_layer/rsync.rb
lono-8.0.0.pre.rc5 lib/lono/files/builder/lambda_layer/rsync.rb
lono-8.0.0.pre.rc4 lib/lono/files/builder/lambda_layer/rsync.rb