Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Backends:
| | | * Requires ``p7zip-rar`` package on Debian/Ubuntu. |
+-------------+----------------------+-----------------------------------------------------+
| bsdtar_ | Supported | * Not recommended: limited RAR format support. |
| | | * Available on Windows as tar.exe . |
| | | * Does not support multi-volume archives. |
| | | * Does not support solid archives. |
| | | * Does not support password-protected archives. |
Expand Down
2 changes: 1 addition & 1 deletion dumprar.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def main():

if cf_backend:
cf_backend = {"7z": "sevenzip", "7zz": "sevenzip2"}.get(cf_backend, cf_backend)
conf = {"unrar": False, "unar": False, "bsdtar": False, "sevenzip": False, "sevenzip2": False}
conf = {"unrar": False, "unar": False, "bsdtar": False, "tarexe": False, "sevenzip": False, "sevenzip2": False}
assert cf_backend in conf, f"unknown backend: {cf_backend}"
conf[cf_backend] = True
rf.tool_setup(force=True, **conf)
Expand Down
15 changes: 14 additions & 1 deletion rarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def __init__(self, key, iv):
#: executable for bsdtar tool
BSDTAR_TOOL = "bsdtar"

#: executable for tar.exe tool (bsdtar on Windows)
TAREXE_TOOL = "tar.exe"

#: executable for p7zip/7z tool
SEVENZIP_TOOL = "7z"

Expand Down Expand Up @@ -3459,6 +3462,14 @@ def add_password_arg(self, cmdline, pwd):
"errmap": [None],
}

TAREXE_CONFIG = {
"open_cmd": ("TAREXE_TOOL", "-x", "--to-stdout", "-f"),
"check_cmd": ("TAREXE_TOOL", "--version"),
"password": None,
"no_password": (),
"errmap": [None],
}

SEVENZIP_CONFIG = {
"open_cmd": ("SEVENZIP_TOOL", "e", "-so", "-bb0"),
"check_cmd": ("SEVENZIP_TOOL", "i"),
Expand All @@ -3482,7 +3493,7 @@ def add_password_arg(self, cmdline, pwd):
CURRENT_SETUP = None


def tool_setup(unrar=True, unar=True, bsdtar=True, sevenzip=True, sevenzip2=True, force=False):
def tool_setup(unrar=True, unar=True, bsdtar=True, tarexe=True, sevenzip=True, sevenzip2=True, force=False):
"""Pick a tool, return cached ToolSetup.
"""
global CURRENT_SETUP
Expand All @@ -3501,6 +3512,8 @@ def tool_setup(unrar=True, unar=True, bsdtar=True, sevenzip=True, sevenzip2=True
lst.append(SEVENZIP2_CONFIG)
if bsdtar:
lst.append(BSDTAR_CONFIG)
if tarexe:
lst.append(TAREXE_CONFIG)

for conf in lst:
setup = ToolSetup(conf)
Expand Down
24 changes: 22 additions & 2 deletions test/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def have_tool(name):
return False


def tool_setup(unrar=False, unar=False, bsdtar=False, sevenzip=False, sevenzip2=False):
def tool_setup(unrar=False, unar=False, bsdtar=False, tarexe=False, sevenzip=False, sevenzip2=False):
rarfile.FORCE_TOOL = True
rarfile.tool_setup(unrar=unrar, unar=unar, bsdtar=bsdtar,
rarfile.tool_setup(unrar=unrar, unar=unar, bsdtar=bsdtar, tarexe=tarexe,
sevenzip=sevenzip, sevenzip2=sevenzip2,
force=True)

Expand All @@ -37,6 +37,10 @@ def install_bsdtar_tool():
tool_setup(bsdtar=True)


def install_tarexe_tool():
tool_setup(tarexe=True)


def install_7z_tool():
tool_setup(sevenzip=True)

Expand Down Expand Up @@ -123,6 +127,22 @@ def test_bsdtar_tool():
uninstall_alt_tool()


@pytest.mark.skipif(not have_tool(rarfile.TAREXE_TOOL), reason="tar.exe not installed")
def test_tarexe_tool():
install_tarexe_tool()
try:
with rarfile.RarFile("test/files/rar3-comment-plain.rar") as rf:
rf.read("file1.txt")
rf.read("file2.txt")

with pytest.raises(rarfile.RarCannotExec):
with rarfile.RarFile("test/files/rar3-comment-psw.rar") as rf:
rf.setpassword("password")
rf.read("file1.txt")
finally:
uninstall_alt_tool()


@pytest.mark.skipif(not have_tool(rarfile.SEVENZIP_TOOL), reason="7z not installed")
def test_7z_tool():
install_7z_tool()
Expand Down
Loading