Skip to content

Commit

Permalink
Added the -h flag to the tar command(s) generated by the copy strateg…
Browse files Browse the repository at this point in the history
…y. This brings the zip and tar handling of symlinks into alignment (and is probably what most people want anyway).
  • Loading branch information
rosscooperman committed Jan 20, 2011
1 parent cb70695 commit 757f98e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions lib/capistrano/recipes/deploy/strategy/copy.rb
Expand Up @@ -86,7 +86,7 @@ def deploy!
if copy_exclude.any?
logger.debug "processing exclusions..."
if copy_exclude.any?
copy_exclude.each do |pattern|
copy_exclude.each do |pattern|
delete_list = Dir.glob(File.join(destination, pattern), File::FNM_DOTMATCH)
# avoid the /.. trap that deletes the parent directories
delete_list.delete_if { |dir| dir =~ /\/\.\.$/ }
Expand Down Expand Up @@ -183,21 +183,21 @@ def remote_filename
# Commands are arrays, where the first element is the utility to be
# used to perform the compression or decompression.
Compression = Struct.new(:extension, :compress_command, :decompress_command)

# The compression method to use, defaults to :gzip.
def compression
remote_tar = configuration[:copy_remote_tar] || 'tar'
local_tar = configuration[:copy_local_tar] || 'tar'

type = configuration[:copy_compression] || :gzip
case type
when :gzip, :gz then Compression.new("tar.gz", [local_tar, 'czf'], [remote_tar, 'xzf'])
when :bzip2, :bz2 then Compression.new("tar.bz2", [local_tar, 'cjf'], [remote_tar, 'xjf'])
when :gzip, :gz then Compression.new("tar.gz", [local_tar, 'chzf'], [remote_tar, 'xzf'])
when :bzip2, :bz2 then Compression.new("tar.bz2", [local_tar, 'chjf'], [remote_tar, 'xjf'])
when :zip then Compression.new("zip", %w(zip -qr), %w(unzip -q))
else raise ArgumentError, "invalid compression type #{type.inspect}"
end
end

# Returns the command necessary to compress the given directory
# into the given file.
def compress(directory, file)
Expand All @@ -210,7 +210,7 @@ def compress(directory, file)
def decompress(file)
compression.decompress_command + [file]
end

# Distributes the file to the remote servers
def distribute!
upload(filename, remote_filename)
Expand Down
32 changes: 16 additions & 16 deletions test/deploy/strategy/copy_test.rb
Expand Up @@ -14,16 +14,16 @@ def setup
@config.stubs(:source).returns(@source)
@strategy = Capistrano::Deploy::Strategy::Copy.new(@config)
end

def test_deploy_with_defaults_should_use_remote_gtar
@config[:copy_remote_tar] = 'gtar'

Dir.expects(:tmpdir).returns("/temp/dir")
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
@strategy.expects(:system).with(:local_checkout)

Dir.expects(:chdir).with("/temp/dir").yields
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
@strategy.expects(:system).with("tar chzf 1234567890.tar.gz 1234567890")
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
@strategy.expects(:run).with("cd /u/apps/test/releases && gtar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")

Expand All @@ -33,19 +33,19 @@ def test_deploy_with_defaults_should_use_remote_gtar

FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")

@strategy.deploy!
end

def test_deploy_with_defaults_should_use_local_gtar
@config[:copy_local_tar] = 'gtar'

Dir.expects(:tmpdir).returns("/temp/dir")
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
@strategy.expects(:system).with(:local_checkout)

Dir.expects(:chdir).with("/temp/dir").yields
@strategy.expects(:system).with("gtar czf 1234567890.tar.gz 1234567890")
@strategy.expects(:system).with("gtar chzf 1234567890.tar.gz 1234567890")
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")

Expand All @@ -55,9 +55,9 @@ def test_deploy_with_defaults_should_use_local_gtar

FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")

@strategy.deploy!
end
end

def test_deploy_with_defaults_should_use_tar_gz_and_checkout
Dir.expects(:tmpdir).returns("/temp/dir")
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_deploy_with_bzip2_should_use_bz2_and_checkout
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)

@strategy.expects(:system).with(:local_checkout)
@strategy.expects(:system).with("tar cjf 1234567890.tar.bz2 1234567890")
@strategy.expects(:system).with("tar chjf 1234567890.tar.bz2 1234567890")
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.bz2", "/tmp/1234567890.tar.bz2")
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2")

Expand All @@ -143,25 +143,25 @@ def test_deploy_with_bzip2_should_use_bz2_and_checkout

@strategy.deploy!
end

def test_deploy_with_unknown_compression_type_should_error
@config[:copy_compression] = :bogus
Dir.expects(:tmpdir).returns("/temp/dir")
@source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
@strategy.stubs(:system)
File.stubs(:open)

assert_raises(ArgumentError) { @strategy.deploy! }
end

def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir
Dir.expects(:tmpdir).never
Dir.expects(:chdir).with("/other/path").yields
@config[:copy_dir] = "/other/path"
@source.expects(:checkout).with("154", "/other/path/1234567890").returns(:local_checkout)

@strategy.expects(:system).with(:local_checkout)
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
@strategy.expects(:system).with("tar chzf 1234567890.tar.gz 1234567890")
@strategy.expects(:upload).with("/other/path/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")

Expand All @@ -182,7 +182,7 @@ def test_deploy_with_copy_remote_dir_should_copy_to_that_dir
@source.expects(:checkout).returns(:local_checkout)

@strategy.expects(:system).with(:local_checkout)
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
@strategy.expects(:system).with("tar chzf 1234567890.tar.gz 1234567890")
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/somewhere/else/1234567890.tar.gz")
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /somewhere/else/1234567890.tar.gz && rm /somewhere/else/1234567890.tar.gz")

Expand Down Expand Up @@ -288,7 +288,7 @@ def prepare_directory_tree!(cache, exclude=false)

def prepare_standard_compress_and_copy!
Dir.expects(:chdir).with("/temp/dir").yields
@strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
@strategy.expects(:system).with("tar chzf 1234567890.tar.gz 1234567890")
@strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz")
@strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")

Expand Down

0 comments on commit 757f98e

Please sign in to comment.