From 3f620ca60300c0d830cbe39a023a35b6be4574af Mon Sep 17 00:00:00 2001
From: Yannick DAYER <yannick.dayer@idiap.ch>
Date: Fri, 16 Dec 2022 09:09:14 +0100
Subject: [PATCH] Fix the get_file archive extraction feature.

---
 bob/extension/download.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/bob/extension/download.py b/bob/extension/download.py
index e510eda..bb5b8b8 100644
--- a/bob/extension/download.py
+++ b/bob/extension/download.py
@@ -66,7 +66,6 @@ def extract_compressed_file(filename):
     # Uncompressing if it is the case
     header, ext = os.path.splitext(filename)
     header, ext = header.lower(), ext.lower()
-
     if ext == ".zip":
         logger.info("Unziping in {0}".format(filename))
         _unzip(filename, os.path.dirname(filename))
@@ -279,8 +278,6 @@ def get_file(
     if download or force:
         logger.info("Downloading %s", final_filename)
         download_file_from_possible_urls(urls, final_filename)
-        if extract:
-            extract_compressed_file(final_filename)
 
         if file_hash is not None and not validate_file(
             final_filename, file_hash, algorithm=hash_algorithm
@@ -290,6 +287,12 @@ def get_file(
                 f"The downloaded file: {final_filename} has the hash of {found_hash}, but we expected {file_hash}. Please re-do the procedure."
             )
 
+    # Finally extract if wanted. This will always extract over what would already exist
+    # so that if a new version of the archive is downloaded, the extracted folder is
+    # updated.
+    if extract:
+        extract_compressed_file(final_filename)
+
     return final_filename
 
 
-- 
GitLab