From abac272b31c16f477f90b8834928a3bec30da582 Mon Sep 17 00:00:00 2001 From: DXC Date: Sun, 10 May 2026 16:04:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(step3/step7):=20=E8=B7=AF=E5=BE=84=E6=96=AD?= =?UTF-8?q?=E5=B1=82=E9=97=AD=E7=8E=AF=20=E2=80=94=20=5Fsafe=5Frename?= =?UTF-8?q?=E6=8D=A2=E7=94=A8os.rename=E3=80=81generate=5Fsampling=5Fpoint?= =?UTF-8?q?s=E5=85=A5=E5=8F=A3=E5=BC=BA=E5=88=B6.bsq=E5=90=8E=E7=BC=80?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/steps/glint_removal_step.py | 7 ++++--- src/core/steps/prediction_step.py | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/steps/glint_removal_step.py b/src/core/steps/glint_removal_step.py index 7e9cb49..ca20b7b 100644 --- a/src/core/steps/glint_removal_step.py +++ b/src/core/steps/glint_removal_step.py @@ -21,7 +21,8 @@ import numpy as np def _safe_rename(src_bsq: str, src_hdr: str, dest_bsq: str, dest_hdr: str) -> str: """将底层硬编码生成的 .bsq + .hdr 文件对重命名到用户指定的 output_path - 若 dest 路径已存在(可能是之前残留文件),先删除再移动,确保返回路径始终指向用户指定的文件。 + 使用 os.remove + os.rename 确保原子覆盖(不等 os.replace 的跨设备行为), + resolve() 断路防止同路径 self-rename 报错。 Returns: dest_bsq 路径 @@ -40,9 +41,9 @@ def _safe_rename(src_bsq: str, src_hdr: str, dest_bsq: str, dest_hdr: str) -> st os.remove(dest_hdr_p) if src_bsq_p.exists(): - os.replace(src_bsq_p, dest_bsq_p) + os.rename(src_bsq_p, dest_bsq_p) if src_hdr_p.exists(): - os.replace(src_hdr_p, dest_hdr_p) + os.rename(src_hdr_p, dest_hdr_p) return dest_bsq diff --git a/src/core/steps/prediction_step.py b/src/core/steps/prediction_step.py index 25b56f8..30c218c 100644 --- a/src/core/steps/prediction_step.py +++ b/src/core/steps/prediction_step.py @@ -47,6 +47,9 @@ class PredictionStep: if deglint_img_path is None: raise ValueError("必须提供 deglint_img_path 参数") + # 强制后缀校验:无论用户 UI 传入 .dat/.tif/.bsq,统一规范为 .bsq + deglint_img_path = str(Path(deglint_img_path).with_suffix('.bsq')) + if Path(output_path).exists(): print(f"检测到已存在的采样点光谱数据文件,直接使用: {output_path}") notify("skipped", f"采样点光谱数据已设置: {output_path}")