# src/services/fileops.py import shutil from pathlib import Path from core.logger import log class FileOpsService: """纯粹的物理层文件与目录操作服务""" @staticmethod def move_file(old_path: Path, new_path: Path): """执行物理重命名/移动任务,并记录审计日志。接入 shutil.move 保障跨盘跨 Docker 卷的安全""" if old_path.exists() and old_path != new_path: # 物理层变更审计:检测并创建缺失的目录 if not new_path.parent.exists(): log.info(f"🆕 发现目标目录不存在,正在执行物理创建: {new_path.parent.absolute()}") new_path.parent.mkdir(parents=True, exist_ok=True) try: # 💡 替换掉了脆弱的 old_path.rename() shutil.move(str(old_path), str(new_path)) except Exception as e: log.error(f"❌ 跨盘或物理移动失败 [源: {old_path.name}] -> [异常: {e}]") raise e