Sha256: 277ac1ec414ab180aa3d70cc5e7377cdef398fd2ae3fdc9891c4ca8673aeb43e

Contents?: true

Size: 1.15 KB

Versions: 15

Compression:

Stored size: 1.15 KB

Contents

require 'shellwords'

module Lono::Utils
  module Rsync
    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

    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

15 entries across 15 versions & 1 rubygems

Version Path
lono-7.5.2 lib/lono/utils/rsync.rb
lono-7.5.1 lib/lono/utils/rsync.rb
lono-7.5.0 lib/lono/utils/rsync.rb
lono-7.4.11 lib/lono/utils/rsync.rb
lono-7.4.10 lib/lono/utils/rsync.rb
lono-7.4.9 lib/lono/utils/rsync.rb
lono-7.4.8 lib/lono/utils/rsync.rb
lono-7.4.7 lib/lono/utils/rsync.rb
lono-7.4.6 lib/lono/utils/rsync.rb
lono-7.4.5 lib/lono/utils/rsync.rb
lono-7.4.4 lib/lono/utils/rsync.rb
lono-7.4.3 lib/lono/utils/rsync.rb
lono-7.4.2 lib/lono/utils/rsync.rb
lono-7.4.1 lib/lono/utils/rsync.rb
lono-7.4.0 lib/lono/utils/rsync.rb