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']:
|
if kwargs['verbose']:
|
||||||
cmdlist.append('-v')
|
cmdlist.append('-v')
|
||||||
cmdlist.extend(['-c', '-d'])
|
cmdlist.extend(['-c', '-d'])
|
||||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||||
cmdlist.append('--')
|
cmdlist.append('--')
|
||||||
cmdlist.extend([archive, '>', outfile])
|
cmdlist.extend([archive, '>', outfile])
|
||||||
# note that for shell calls the command must be a string
|
# 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.append('-v')
|
||||||
cmdlist.extend(['-c', '-d'])
|
cmdlist.extend(['-c', '-d'])
|
||||||
cmdlist.append('--')
|
cmdlist.append('--')
|
||||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||||
cmdlist.extend([archive, '>', outfile])
|
cmdlist.extend([archive, '>', outfile])
|
||||||
# note that for shell calls the command must be a string
|
# note that for shell calls the command must be a string
|
||||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
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.append('-v')
|
||||||
cmdlist.extend(['-c', '-d'])
|
cmdlist.extend(['-c', '-d'])
|
||||||
cmdlist.append('--')
|
cmdlist.append('--')
|
||||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||||
cmdlist.extend([archive, '>', outfile])
|
cmdlist.extend([archive, '>', outfile])
|
||||||
# note that for shell calls the command must be a string
|
# note that for shell calls the command must be a string
|
||||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""Archive commands for the lzop program."""
|
"""Archive commands for the lzop program."""
|
||||||
import os
|
import os
|
||||||
from patoolib import util
|
from .. import util
|
||||||
|
|
||||||
|
|
||||||
def extract_lzop (archive, encoding, cmd, **kwargs):
|
def extract_lzop (archive, encoding, cmd, **kwargs):
|
||||||
|
@ -25,9 +25,7 @@ def extract_lzop (archive, encoding, cmd, **kwargs):
|
||||||
if kwargs['verbose']:
|
if kwargs['verbose']:
|
||||||
cmdlist.append('--verbose')
|
cmdlist.append('--verbose')
|
||||||
cmdlist.append('--')
|
cmdlist.append('--')
|
||||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||||
if archive == outfile:
|
|
||||||
outfile = archive + ".raw"
|
|
||||||
cmdlist.extend([archive, '>', outfile])
|
cmdlist.extend([archive, '>', outfile])
|
||||||
# note that for shell calls the command must be a string
|
# note that for shell calls the command must be a string
|
||||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
||||||
|
|
|
@ -24,7 +24,7 @@ def extract_compress (archive, encoding, cmd, **kwargs):
|
||||||
if kwargs['verbose']:
|
if kwargs['verbose']:
|
||||||
cmdlist.append('-v')
|
cmdlist.append('-v')
|
||||||
cmdlist.append('-c')
|
cmdlist.append('-c')
|
||||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||||
cmdlist.extend([archive, '>', outfile])
|
cmdlist.extend([archive, '>', outfile])
|
||||||
# note that for shell calls the command must be a string
|
# note that for shell calls the command must be a string
|
||||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
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.append('-v')
|
||||||
cmdlist.extend(['-c', '-d'])
|
cmdlist.extend(['-c', '-d'])
|
||||||
cmdlist.append('--')
|
cmdlist.append('--')
|
||||||
outfile = os.path.join(kwargs['outdir'], util.stripext(archive))
|
outfile = util.get_single_outfile(kwargs['outdir'], archive)
|
||||||
cmdlist.extend([archive, '>', outfile])
|
cmdlist.extend([archive, '>', outfile])
|
||||||
# note that for shell calls the command must be a string
|
# note that for shell calls the command must be a string
|
||||||
cmd = " ".join([util.shell_quote(x) for x in cmdlist])
|
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]
|
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):
|
def log_error (msg, out=sys.stderr):
|
||||||
"""Print error message to stderr (or any other given output)."""
|
"""Print error message to stderr (or any other given output)."""
|
||||||
print >> out, "patool error:", msg
|
print >> out, "patool error:", msg
|
||||||
|
|
Loading…
Reference in New Issue