15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/indocker/rsync.rb', line 15
def self.sync(session, from, to, create_path: nil, raise_on_error: false, exclude: nil)
if create_path
session.exec!("mkdir -p #{create_path}")
end
if session.local?
return if File.expand_path(to) == File.expand_path(from)
Indocker::Shell.command("rm -rf #{to}", Indocker.logger, raise_on_error: raise_on_error)
if Indocker::Shell.command_exist?("rsync")
sync_local_rsync(from, to, raise_on_error: raise_on_error, exclude: exclude)
else
Indocker.logger.debug("WARNING: exclude option skipped due to fallback to CP command")
sync_local_cp(from, to, raise_on_error: raise_on_error)
end
else
command = "rsync --delete-after -a -e 'ssh -p #{session.port}' #{from} #{session.user}@#{session.host}:#{to}"
Indocker.logger.debug("sync #{from} #{session.user}@#{session.host}:#{to}")
Indocker::Shell.command(command, Indocker.logger, raise_on_error: raise_on_error)
end
end
|