Prevent overwriting the archive itself when extracting single-file archives.
This commit is contained in:
parent
b51777c8f1
commit
8cd637e198
|
@ -24,7 +24,7 @@ def extract_bzip2 (archive, encoding, cmd, **kwargs):
|
|||
if kwargs['verbose']:
|
||||
cmdlist.append('-v')
|
||||
cmdlist.extend(['-c', '-d'])
|
||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
||||
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||
cmdlist.append('--')
|
||||
cmdlist.extend([archive, '>', outfile])
|
||||
# note that for shell calls the command must be a string
|
||||
|
|
|
@ -25,7 +25,7 @@ def extract_gzip (archive, encoding, cmd, **kwargs):
|
|||
cmdlist.append('-v')
|
||||
cmdlist.extend(['-c', '-d'])
|
||||
cmdlist.append('--')
|
||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
||||
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||
cmdlist.extend([archive, '>', outfile])
|
||||
# note that for shell calls the command must be a string
|
||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
||||
|
|
|
@ -25,7 +25,7 @@ def extract_lzma (archive, encoding, cmd, **kwargs):
|
|||
cmdlist.append('-v')
|
||||
cmdlist.extend(['-c', '-d'])
|
||||
cmdlist.append('--')
|
||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
||||
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||
cmdlist.extend([archive, '>', outfile])
|
||||
# note that for shell calls the command must be a string
|
||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""Archive commands for the lzop program."""
|
||||
import os
|
||||
from patoolib import util
|
||||
from .. import util
|
||||
|
||||
|
||||
def extract_lzop (archive, encoding, cmd, **kwargs):
|
||||
|
@ -25,9 +25,7 @@ def extract_lzop (archive, encoding, cmd, **kwargs):
|
|||
if kwargs['verbose']:
|
||||
cmdlist.append('--verbose')
|
||||
cmdlist.append('--')
|
||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
||||
if archive == outfile:
|
||||
outfile = archive + ".raw"
|
||||
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||
cmdlist.extend([archive, '>', outfile])
|
||||
# note that for shell calls the command must be a string
|
||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
||||
|
|
|
@ -24,7 +24,7 @@ def extract_compress (archive, encoding, cmd, **kwargs):
|
|||
if kwargs['verbose']:
|
||||
cmdlist.append('-v')
|
||||
cmdlist.append('-c')
|
||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
||||
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||
cmdlist.extend([archive, '>', outfile])
|
||||
# note that for shell calls the command must be a string
|
||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
||||
|
|
|
@ -25,7 +25,7 @@ def extract_xz (archive, encoding, cmd, **kwargs):
|
|||
cmdlist.append('-v')
|
||||
cmdlist.extend(['-c', '-d'])
|
||||
cmdlist.append('--')
|
||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
||||
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||
cmdlist.extend([archive, '>', outfile])
|
||||
# note that for shell calls the command must be a string
|
||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
||||
|
|
|
@ -224,6 +224,15 @@ def stripext (filename):
|
|||
return os.path.splitext(os.path.basename(filename))[0]
|
||||
|
||||
|
||||
def get_single_outfile (directory, archive):
|
||||
"""Get output filename if archive is in a single file format like gzip."""
|
||||
outfile = os.path.join(directory, stripext(archive))
|
||||
if archive == outfile:
|
||||
# prevent overwriting the archive itself
|
||||
outfile += ".raw"
|
||||
return outfile
|
||||
|
||||
|
||||
def log_error (msg, out=sys.stderr):
|
||||
"""Print error message to stderr (or any other given output)."""
|
||||
print >> out, "patool error:", msg
|
||||
|
|
Loading…
Reference in New Issue