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}")