0
@@ -146,7 +146,7 @@ module Capistrano
0
# Returns the name of the file that the source code will be
0
- @filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression
_extension}")
0
+ @filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression
.extension}")
0
# The directory to which the copy should be checked out
0
@@ -166,46 +166,33 @@ module Capistrano
0
@remote_filename ||= File.join(remote_dir, File.basename(filename))
0
+ # A struct for representing the specifics of a compression type.
0
+ # Commands are arrays, where the first element is the utility to be
0
+ # used to perform the compression or decompression.
0
+ Compression = Struct.new(:extension, :compress_command, :decompress_command)
0
# The compression method to use, defaults to :gzip.
0
- configuration[:copy_compression] || :gzip
0
- # Returns the file extension used for the compression method in
0
- def compression_extension
0
- when :gzip, :gz then "tar.gz"
0
- when :bzip2, :bz2 then "tar.bz2"
0
- else raise ArgumentError, "invalid compression type #{compression.inspect}"
0
+ type = configuration[:copy_compression] || :gzip
0
+ when :gzip, :gz then Compression.new("tar.gz", %w(tar czf), %w(tar xzf))
0
+ when :bzip2, :bz2 then Compression.new("tar.bz2", %w(tar cjf), %w(tar xjf))
0
+ when :zip then Compression.new("zip", %w(zip -qr), %w(unzip -q))
0
+ else raise ArgumentError, "invalid compression type #{type.inspect}"
0
# Returns the command necessary to compress the given directory
0
- # into the given file. The command is returned as an array, where
0
- # the first element is the utility to be used to perform the compression.
0
+ # into the given file.
0
def compress(directory, file)
0
- when :gzip, :gz then ["tar", "czf", file, directory]
0
- when :bzip2, :bz2 then ["tar", "cjf", file, directory]
0
- when :zip then ["zip", "-qr", file, directory]
0
- else raise ArgumentError, "invalid compression type #{compression.inspect}"
0
+ compression.compress_command + [file, directory]
0
# Returns the command necessary to decompress the given file,
0
# relative to the current working directory. It must also
0
- # preserve the directory structure in the file. The command is returned
0
- # as an array, where the first element is the utility to be used to
0
- # perform the decompression.
0
+ # preserve the directory structure in the file.
0
- when :gzip, :gz then ["tar", "xzf", file]
0
- when :bzip2, :bz2 then ["tar", "xjf", file]
0
- when :zip then ["unzip", "-q", file]
0
- else raise ArgumentError, "invalid compression type #{compression.inspect}"
0
+ compression.decompress_command + [file]