chore: log project size errors
This commit is contained in:
parent
c590aef460
commit
2847ade631
@ -29,12 +29,15 @@ except ImportError: # 兼容全局环境中存在同名包的情况
|
|||||||
PROJECT_MAX_STORAGE_BYTES,
|
PROJECT_MAX_STORAGE_BYTES,
|
||||||
)
|
)
|
||||||
from modules.container_file_proxy import ContainerFileProxy
|
from modules.container_file_proxy import ContainerFileProxy
|
||||||
|
from utils.logger import setup_logger
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from modules.user_container_manager import ContainerHandle
|
from modules.user_container_manager import ContainerHandle
|
||||||
|
|
||||||
# 临时禁用长度检查
|
# 临时禁用长度检查
|
||||||
DISABLE_LENGTH_CHECK = True
|
DISABLE_LENGTH_CHECK = True
|
||||||
|
|
||||||
|
logger = setup_logger(__name__)
|
||||||
class FileManager:
|
class FileManager:
|
||||||
def __init__(self, project_path: str, container_session: Optional["ContainerHandle"] = None):
|
def __init__(self, project_path: str, container_session: Optional["ContainerHandle"] = None):
|
||||||
self.project_path = Path(project_path).resolve()
|
self.project_path = Path(project_path).resolve()
|
||||||
@ -68,16 +71,24 @@ class FileManager:
|
|||||||
return self._container_proxy.run(action, payload)
|
return self._container_proxy.run(action, payload)
|
||||||
|
|
||||||
def _get_project_size(self) -> int:
|
def _get_project_size(self) -> int:
|
||||||
"""计算项目目录的总大小(字节)"""
|
"""计算项目目录的总大小(字节),遇到异常时记录并抛出。"""
|
||||||
total = 0
|
total = 0
|
||||||
if not self.project_path.exists():
|
if not self.project_path.exists():
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
for path in self.project_path.rglob('*'):
|
for path in self.project_path.rglob('*'):
|
||||||
try:
|
if not path.is_file():
|
||||||
if path.is_file():
|
|
||||||
total += path.stat().st_size
|
|
||||||
except PermissionError:
|
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
|
total += path.stat().st_size
|
||||||
|
except Exception as exc:
|
||||||
|
logger.error(
|
||||||
|
"Failed to stat %s while calculating project size: %s",
|
||||||
|
path,
|
||||||
|
exc,
|
||||||
|
exc_info=True,
|
||||||
|
)
|
||||||
|
raise
|
||||||
return total
|
return total
|
||||||
|
|
||||||
def _validate_path(self, path: str) -> Tuple[bool, str, Path]:
|
def _validate_path(self, path: str) -> Tuple[bool, str, Path]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user