fix(step3/step7): 路径断层闭环 — _safe_rename换用os.rename、generate_sampling_points入口强制.bsq后缀校验
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user