From 295694001f143fd7357e5ee6e2a0ea51aafe38ff Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Fri, 15 May 2026 13:00:17 +0000 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9B=AE=E5=BD=95=E5=88=9B=E5=BB=BA=E6=97=B6?= =?UTF-8?q?=E6=97=A7=E6=96=87=E4=BB=B6=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/history/file_utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/common/history/file_utils.py b/app/common/history/file_utils.py index d110123d..3178ab6d 100644 --- a/app/common/history/file_utils.py +++ b/app/common/history/file_utils.py @@ -69,6 +69,9 @@ def get_history_file_path(history_type: str, file_name: str) -> Path: Path: 历史记录文件路径 """ history_dir = get_path(f"data/history/{history_type}_history") + if history_dir.exists() and not history_dir.is_dir(): + logger.warning(f"检测到旧版历史记录文件,正在删除以创建目录: {history_dir}") + history_dir.unlink() history_dir.mkdir(parents=True, exist_ok=True) return history_dir / f"{file_name}.json" From 3ff567637f5a9463e212ce2ddead267b1e18f8e1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 13:23:41 +0000 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=B8=BA=E5=8E=86=E5=8F=B2=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=BF=81=E7=A7=BB=E5=88=A0=E9=99=A4=E4=B8=8E=E5=BB=BA?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E5=A2=9E=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=85=9C?= =?UTF-8?q?=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/SECTL/SecRandom/sessions/6f6ab0cc-130c-465b-81d9-e35ad9b0df2e Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com> --- app/common/history/file_utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/common/history/file_utils.py b/app/common/history/file_utils.py index 3178ab6d..273316af 100644 --- a/app/common/history/file_utils.py +++ b/app/common/history/file_utils.py @@ -71,8 +71,18 @@ def get_history_file_path(history_type: str, file_name: str) -> Path: history_dir = get_path(f"data/history/{history_type}_history") if history_dir.exists() and not history_dir.is_dir(): logger.warning(f"检测到旧版历史记录文件,正在删除以创建目录: {history_dir}") - history_dir.unlink() - history_dir.mkdir(parents=True, exist_ok=True) + try: + history_dir.unlink(missing_ok=True) + except PermissionError as e: + logger.error(f"删除旧版历史记录文件失败(权限不足): {history_dir}, 错误: {e}") + except OSError as e: + logger.error(f"删除旧版历史记录文件失败: {history_dir}, 错误: {e}") + try: + history_dir.mkdir(parents=True, exist_ok=True) + except FileExistsError: + logger.error(f"创建历史记录目录失败,目标仍为文件: {history_dir}") + except OSError as e: + logger.error(f"创建历史记录目录失败: {history_dir}, 错误: {e}") return history_dir / f"{file_name}.json" From 8936a6fbb7a66aeae90b3253d4a369cc3fc2fdae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 15 May 2026 13:45:04 +0000 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=B8=A5=E6=A0=BC=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E7=9B=AE=E5=BD=95=E5=8F=AF=E7=94=A8=E6=80=A7?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E8=BF=94=E5=9B=9E=E6=97=A0=E6=95=88=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent-Logs-Url: https://github.com/SECTL/SecRandom/sessions/9f2f5591-dc71-40c7-b4df-bb8e08e0105a Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com> --- app/common/history/file_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/common/history/file_utils.py b/app/common/history/file_utils.py index 273316af..4c68526b 100644 --- a/app/common/history/file_utils.py +++ b/app/common/history/file_utils.py @@ -58,12 +58,15 @@ def clear_history_cache(history_type: str | None = None, file_name: str | None = # ================================================== # 历史记录文件路径处理函数 # ================================================== -def get_history_file_path(history_type: str, file_name: str) -> Path: +def get_history_file_path( + history_type: str, file_name: str, strict: bool = False +) -> Path: """获取历史记录文件路径 Args: history_type: 历史记录类型 (roll_call, lottery 等) file_name: 文件名(不含扩展名) + strict: 当目录创建失败时是否抛出异常 Returns: Path: 历史记录文件路径 @@ -83,6 +86,8 @@ def get_history_file_path(history_type: str, file_name: str) -> Path: logger.error(f"创建历史记录目录失败,目标仍为文件: {history_dir}") except OSError as e: logger.error(f"创建历史记录目录失败: {history_dir}, 错误: {e}") + if strict and not history_dir.is_dir(): + raise NotADirectoryError(f"历史记录目录不可用: {history_dir}") return history_dir / f"{file_name}.json" @@ -101,7 +106,11 @@ def load_history_data(history_type: str, file_name: str) -> Dict[str, Any]: Returns: Dict[str, Any]: 历史记录数据 """ - file_path = get_history_file_path(history_type, file_name) + try: + file_path = get_history_file_path(history_type, file_name, strict=True) + except OSError as e: + logger.error(f"获取历史记录文件路径失败: {e}") + return {} if not file_path.exists(): with _history_cache_lock: @@ -138,8 +147,8 @@ def save_history_data(history_type: str, file_name: str, data: Dict[str, Any]) - Returns: bool: 保存是否成功 """ - file_path = get_history_file_path(history_type, file_name) try: + file_path = get_history_file_path(history_type, file_name, strict=True) with open(file_path, "w", encoding="utf-8") as f: json.dump(data, f, ensure_ascii=False, indent=4) with _history_cache_lock: