From a3e1cb67181fd966051f8607bda66a8f0f2ff473 Mon Sep 17 00:00:00 2001 From: mcarton Date: Tue, 29 Dec 2015 18:38:58 +0100 Subject: [PATCH 1/2] Fix `thefuck unzip`, fix #416 --- thefuck/rules/dirty_unzip.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/thefuck/rules/dirty_unzip.py b/thefuck/rules/dirty_unzip.py index 3e45ea37..b13d3f1f 100644 --- a/thefuck/rules/dirty_unzip.py +++ b/thefuck/rules/dirty_unzip.py @@ -24,8 +24,14 @@ def _zip_file(command): @for_app('unzip') def match(command): - return ('-d' not in command.script - and _is_bad_zip(_zip_file(command))) + if '-d' in command.script: + return False + + zip_file = _zip_file(command) + if zip_file: + return _is_bad_zip(zip_file) + else: + return False def get_new_command(command): From 42b344676e34341b927bf7a163fc326069c88b43 Mon Sep 17 00:00:00 2001 From: mcarton Date: Tue, 29 Dec 2015 18:46:35 +0100 Subject: [PATCH 2/2] Fix dirty_unzip rule on non-zip files --- thefuck/rules/dirty_untar.py | 1 - thefuck/rules/dirty_unzip.py | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/thefuck/rules/dirty_untar.py b/thefuck/rules/dirty_untar.py index efbf1e32..25d02a64 100644 --- a/thefuck/rules/dirty_untar.py +++ b/thefuck/rules/dirty_untar.py @@ -19,7 +19,6 @@ def _is_tar_extract(cmd): def _tar_file(cmd): - for c in cmd: for ext in tar_extensions: if c.endswith(ext): diff --git a/thefuck/rules/dirty_unzip.py b/thefuck/rules/dirty_unzip.py index b13d3f1f..8423a5ae 100644 --- a/thefuck/rules/dirty_unzip.py +++ b/thefuck/rules/dirty_unzip.py @@ -5,8 +5,11 @@ from thefuck.shells import quote def _is_bad_zip(file): - with zipfile.ZipFile(file, 'r') as archive: - return len(archive.namelist()) > 1 + try: + with zipfile.ZipFile(file, 'r') as archive: + return len(archive.namelist()) > 1 + except: + return False def _zip_file(command):