Skip to content

Commit ecdde40

Browse files
Add data filter in tar extract (open-edge-platform#2084)
* add data filter in tar extract Signed-off-by: Ashwin Vaidya <[email protected]> * add file exists check Signed-off-by: Ashwin Vaidya <[email protected]> * cosmetics Signed-off-by: Ashwin Vaidya <[email protected]> --------- Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent a4c5a2b commit ecdde40

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/anomalib/data/utils/download.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ def safe_extract(tar_file: TarFile, root: Path, members: list[TarInfo]) -> None:
230230
231231
"""
232232
for member in members:
233-
tar_file.extract(member, root)
233+
# check if the file already exists
234+
if not (root / member.name).exists():
235+
tar_file.extract(member, root, filter="data")
234236

235237

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

293295
# Safely extract zip files
294296
if file_name.suffix == ".zip":

0 commit comments

Comments
 (0)