1
# Copyright 2008 Amazon.com, Inc. or its affiliates. All Rights
2
# Reserved. Licensed under the Amazon Software License (the
3
# "License"). You may not use this file except in compliance with the
4
# License. A copy of the License is located at
5
# http://aws.amazon.com/asl or in the "license" file accompanying this
6
# file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
# the License for the specific language governing permissions and
9
# limitations under the License.
11
require 'ec2/amitools/fileutil'
18
def initialize(e = EXECUTABLE)
26
def archive; @options << '-rlpgoD'; self; end
27
def times; @options << '-t'; self; end
28
def recursive; @options << '-r'; self; end
29
def sparse; @options << '-S'; self; end
30
def links; @options << '-l'; self; end
31
def dereference; @options << '-L'; self; end
32
def xattributes; @options << '-X'; self; end
33
def version; @options << '--version'; self; end
34
def src(path) @src = path; self; end
35
def dst(path) @dst = path; self; end
36
def quietly; @quiet = true; self; end
40
alias :destination :dst
45
files.each {|file| exclude file }
47
@options << "--exclude #{files}" unless files.nil?
53
"#{@executable} #{@options.join(' ')} #{@src} #{@dst} #{'2>&1 > /dev/null' if @quiet}".strip
59
src = FileUtil.tempdir('ec2-ami-tools-rsync-test-src')
60
dst = FileUtil.tempdir('ec2-ami-tools-rsync-test-dst')
62
FileUtils.touch("#{src}/foo")
63
FileUtils.symlink("#{src}/foo", "#{src}/bar")
64
FileUtils.mkdir("#{src}/baz")
65
File.open("#{src}/baz/food", 'w+'){|io| io << IO.read(__FILE__) }
66
FileUtils.symlink("#{src}/baz/food", "#{src}/baz/bard")
68
incantation = Command.new.archive.recursive.sparse.links.src("#{src}/").dst("#{dst}")
69
`#{incantation.expand} 2>&1`
71
return true if rc == 0
73
#check that the structure was copied reasonably anyway
74
slist = Dir["#{src}/**/**"]
75
dlist = Dir["#{dst}/**/**"]
76
return false unless dlist == dlist
78
ditem = item.gsub(src, dst)
79
return false unless dlist.include? ditem
80
if File.file?(sitem) or File.symlink?(sitem)
81
@out.print "comparing #{sitem} to #{ditem}" if @out
82
return false unless IO.read(ditem) == IO.read(sitem)
84
if ['food', 'bard'].include? File.basename(ditem)
85
return false unless IO.read(sitem) == IO.read(__FILE__)
100
@@usable ||= self.symlinking?