Commit 293e1c1d authored by Hrvoje Ribicic's avatar Hrvoje Ribicic

Make arbitrary compression tools work

We assume that the compression tools the user supplies use stdin and
stdout for handling data, and that a switch is used to distinguish
compression from decompression. This patch introduces these constraints
by adding the invocation of these tools to the import-export daemon.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarThomas Thrainer <thomasth@google.com>
parent 249f28eb
......@@ -438,14 +438,6 @@ def ParseOptions():
return (status_file_path, mode)
# Compression utility mapping, for compression types whose name does not match
# the name of the utility to invoke
COMPRESSION_UTILITIES = {
"gzip-fast": "gzip",
"gzip-slow": "gzip",
}
# Return code signifying that no program was found
PROGRAM_NOT_FOUND_RCODE = 127
......@@ -493,7 +485,8 @@ def VerifyOptions():
"""
if options.compress != constants.IEC_NONE:
utility_name = COMPRESSION_UTILITIES.get(options.compress, options.compress)
utility_name = constants.IEC_COMPRESSION_UTILITIES.get(options.compress,
options.compress)
timed_out, rcode = \
_RunWithTimeout([utility_name, CHECK_SWITCH], 2, silent=True)
......
......@@ -297,10 +297,11 @@ class CommandBuilder(object):
parts.append(socat_cmd)
if compr in [constants.IEC_GZIP, constants.IEC_GZIP_FAST,
constants.IEC_GZIP_SLOW]:
parts.append("gunzip -c")
elif compr == constants.IEC_LZOP:
parts.append("lzop -d -c")
constants.IEC_GZIP_SLOW, constants.IEC_LZOP]:
utility_name = constants.IEC_COMPRESSION_UTILITIES.get(compr, compr)
parts.append("%s -d -c" % utility_name)
elif compr != constants.IEC_NONE:
parts.append("%s -d" % compr)
else:
# No compression
pass
......@@ -310,12 +311,13 @@ class CommandBuilder(object):
elif self._mode == constants.IEM_EXPORT:
parts.append(dd_cmd)
if compr == constants.IEC_GZIP_SLOW:
parts.append("gzip -c")
if compr in [constants.IEC_GZIP_SLOW, constants.IEC_LZOP]:
utility_name = constants.IEC_COMPRESSION_UTILITIES.get(compr, compr)
parts.append("%s -c" % utility_name)
elif compr in [constants.IEC_GZIP_FAST, constants.IEC_GZIP]:
parts.append("gzip -1 -c")
elif compr == constants.IEC_LZOP:
parts.append("lzop -c")
elif compr != constants.IEC_NONE:
parts.append(compr)
else:
# No compression
pass
......
......@@ -601,6 +601,13 @@ iecNone = "none"
iecAll :: [String]
iecAll = [iecGzip, iecGzipFast, iecGzipSlow, iecLzop, iecNone]
iecCompressionUtilities :: Map String String
iecCompressionUtilities =
Map.fromList
[ (iecGzipFast, iecGzip)
, (iecGzipSlow, iecGzip)
]
ieCustomSize :: String
ieCustomSize = "fd"
......
......@@ -66,9 +66,9 @@ class TestCommandBuilder(unittest.TestCase):
# The commands various compressions should use
compress_import = {
constants.IEC_GZIP: "gunzip",
constants.IEC_GZIP_FAST: "gunzip",
constants.IEC_GZIP_SLOW: "gunzip",
constants.IEC_GZIP: "gzip -d",
constants.IEC_GZIP_FAST: "gzip -d",
constants.IEC_GZIP_SLOW: "gzip -d",
constants.IEC_LZOP: "lzop -d",
}
compress_export = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment