Skip to content

Commit

Permalink
Add data filter in tar extract (#2084)
Browse files Browse the repository at this point in the history
* add data filter in tar extract

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>

* add file exists check

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>

* cosmetics

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>

---------

Signed-off-by: Ashwin Vaidya <ashwinnitinvaidya@gmail.com>
  • Loading branch information
ashwinvaidya17 committed May 24, 2024
1 parent a4c5a2b commit ecdde40
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/anomalib/data/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ def safe_extract(tar_file: TarFile, root: Path, members: list[TarInfo]) -> None:
"""
for member in members:
tar_file.extract(member, root)
# check if the file already exists
if not (root / member.name).exists():
tar_file.extract(member, root, filter="data")


def generate_hash(file_path: str | Path, algorithm: str = "sha256") -> str:
Expand Down Expand Up @@ -288,7 +290,7 @@ def extract(file_name: Path, root: Path) -> None:
root (Path): Root directory where the dataset will be stored.
"""
logger.info("Extracting dataset into root folder.")
logger.info(f"Extracting dataset into {root} folder.")

# Safely extract zip files
if file_name.suffix == ".zip":
Expand Down

0 comments on commit ecdde40

Please sign in to comment.