From 0b4e7a8e8c724ab78db25ca0f4ff771d5f0dc25b Mon Sep 17 00:00:00 2001 From: MIUMA <2117410945@qq.com> Date: Wed, 15 Jul 2026 23:06:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB=20HOME=20=E7=9B=AE=E5=BD=95=E4=B8=8B=20import=20offic?= =?UTF-8?q?e=20=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- office/compatibility.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/office/compatibility.py b/office/compatibility.py index 1a0c6ba..776ba2b 100644 --- a/office/compatibility.py +++ b/office/compatibility.py @@ -27,15 +27,19 @@ def _check_first_run(self) -> bool: Returns: bool: 如果是首次运行返回True,否则返回False """ - # 创建标记目录 - self.mark_file.parent.mkdir(exist_ok=True) - - # 如果标记文件不存在,则是首次运行 - if not self.mark_file.exists(): - # 创建标记文件 - self.mark_file.write_text(f"First run on {platform.system()} at {platform.platform()}") - return True - return False + try: + # 创建标记目录 + self.mark_file.parent.mkdir(exist_ok=True) + # 如果标记文件不存在,则是首次运行 + if not self.mark_file.exists(): + # 创建标记文件 + self.mark_file.write_text(f"First run on {platform.system()} at {platform.platform()}") + return True + return False + except (PermissionError, OSError): + # 只读或无法写入的 HOME 目录(部分 CI 容器、锁定的企业账户)下, + # 跳过首次运行标记,不应影响 office 的正常导入。 + return False def get_compatibility_info(self) -> Dict[str, List[str]]: """获取兼容性信息。