2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 00:37:51 +00:00

fix: version check before data_filter import

- better error handling if untar fails
This commit is contained in:
18alantom 2024-01-24 11:58:03 +05:30
parent 23bd717d7b
commit 80f2e70af6
2 changed files with 11 additions and 4 deletions

View File

@ -346,7 +346,8 @@ class App(AppMeta):
with tarfile.open(cache_path, mode) as tar: with tarfile.open(cache_path, mode) as tar:
try: try:
tar.extractall(app_path.parent, filter=get_app_cache_extract_filter()) tar.extractall(app_path.parent, filter=get_app_cache_extract_filter())
except: except Exception:
logger.exception(f"Cache extraction failed for {self.app_name}")
shutil.rmtree(app_path) shutil.rmtree(app_path)
return False return False

View File

@ -9,7 +9,7 @@ from functools import lru_cache
from glob import glob from glob import glob
from pathlib import Path from pathlib import Path
from shlex import split from shlex import split
from tarfile import data_filter, AbsoluteLinkError, TarInfo from tarfile import AbsoluteLinkError, TarInfo
from typing import List, Optional, Tuple from typing import List, Optional, Tuple
# imports - third party imports # imports - third party imports
@ -578,15 +578,21 @@ def get_app_cache_extract_filter(
): # -> Callable[[TarInfo, str], TarInfo | None] ): # -> Callable[[TarInfo, str], TarInfo | None]
state = dict(count=0, size=0) state = dict(count=0, size=0)
if sys.version_info.major <=2 or sys.version_info.minor <=8:
def data_filter(m, p):
return m
else:
from tarfile import data_filter
def filter_function(member: TarInfo, dest_path: str) -> Optional[TarInfo]: def filter_function(member: TarInfo, dest_path: str) -> Optional[TarInfo]:
state["count"] += 1 state["count"] += 1
state["size"] += member.size state["size"] += member.size
if state["count"] > count_threshold: if state["count"] > count_threshold:
raise Exception(f"Number of entries exceeds threshold ({state['count']})") raise RuntimeError(f"Number of entries exceeds threshold ({state['count']})")
if state["size"] > size_threshold: if state["size"] > size_threshold:
raise Exception(f"Extracted size exceeds threshold ({state['size']})") raise RuntimeError(f"Extracted size exceeds threshold ({state['size']})")
try: try:
return data_filter(member, dest_path) return data_filter(member, dest_path)