Sha256: 4925ec5f25bf9e10df5cf739a43003b9bdf4a79a36495b72c98cd9fe332c32cf

Contents?: true

Size: 1.23 KB

Versions: 98

Compression:

Stored size: 1.23 KB

Contents

require 'shellwords'

class Jets::Util
  class << self
    # Make sure that the result is a text.
    def normalize_result(result)
      JSON.dump(result)
    end

    def cp_r(src, dest)
      # Fix for https://github.com/tongueroo/jets/issues/122
      #
      # 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!
      sh "rsync -a --links --no-specials --no-devices #{Shellwords.escape(src)}/ #{Shellwords.escape(dest)}/", quiet: true
    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 Jets::Error.new("Rsync is required. Rsync does not seem to be installed.")
      end
    end

    def sh(command, quiet: false)
      puts "=> #{command}" unless quiet
      system(command)
      success = $?.success?
      raise Jets::Error.new("Command failed: #{command}") unless success
      success
    end
  end
end

Version data entries

98 entries across 98 versions & 2 rubygems

Version Path
jets-4.0.12 lib/jets/util.rb
jets-4.0.11 lib/jets/util.rb
jets-5.0.13 lib/jets/util.rb
jets-5.0.12 lib/jets/util.rb
jets-5.0.11 lib/jets/util.rb
jets-5.0.10 lib/jets/util.rb
jets-5.0.9 lib/jets/util.rb
jets-5.0.8 lib/jets/util.rb
jets-5.0.7 lib/jets/util.rb
jets-5.0.6 lib/jets/util.rb
jets-5.0.5 lib/jets/util.rb
jets-5.0.4 lib/jets/util.rb
jets-5.0.3 lib/jets/util.rb
jets-5.0.2 lib/jets/util.rb
jets-5.0.1 lib/jets/util.rb
jets-5.0.0 lib/jets/util.rb
jets-4.0.10 lib/jets/util.rb
jets-5.0.0.beta1 lib/jets/util.rb
jets-4.0.9 lib/jets/util.rb
jets-4.0.8 lib/jets/util.rb