Sha256: 4a8c6a2b764f1f4b1ed76cd366ab2193685771fafeda3bf9a852d24657f67dd0

Contents?: true

Size: 945 Bytes

Versions: 5

Compression:

Stored size: 945 Bytes

Contents

module Cloner::RSync
  extend ActiveSupport::Concern

  def rsync_compression
    "-zz"
  end

  def rsync_flags
    port = ssh_opts[:port] || 22
    "#{rsync_compression} -utvr --checksum -e \"ssh -p #{port}\""
  end

  def rsync(from, to, directory: true, raise_on_error: false)
    if directory
      from = "#{from}/" unless from.to_s.end_with?('/')
      to = "#{to}/" unless to.to_s.end_with?('/')
    end
    cmd = "rsync #{rsync_flags} #{e ssh_user}@#{e ssh_host}:#{e from} #{e to}"
    puts "Running RSync: #{cmd}"
    pipe = IO.popen(cmd)
    while (line = pipe.gets)
      print line if verbose?
    end
    pipe.close
    ret = $?.to_i
    if ret != 0
      if raise_on_error
        raise "Error: local command exited with #{ret}"
      end
      puts "Error: local command exited with #{ret}"
    end
  end

  def rsync_public(folder)
    rsync("#{remote_app_path}/public/#{folder}", Rails.root.join("public/#{folder}"))
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cloner-0.13.0 lib/cloner/rsync.rb
cloner-0.12.0 lib/cloner/rsync.rb
cloner-0.11.0 lib/cloner/rsync.rb
cloner-0.10.0 lib/cloner/rsync.rb
cloner-0.9.2 lib/cloner/rsync.rb