refactor(services): 引入 FileOpsService,统一 ffprobe 与缓存调用
- 新增 services/fileops.py:用 shutil.move 取代 Path.rename,解决跨盘/跨 Docker 卷移动报 Invalid cross-device link - task.py:季目录与根目录改名统一交给 FileOpsService,任务结构统一为 (old, new) 元组 - mediainfo/metadata/subtitle:ffprobe 调用收敛到 FFprobeUtil,去掉重复的 json.loads 与 stderr 处理 - subtitle:内置字幕提取、外挂字幕转换增加"目标已存在且非空则跳过"的幂等保护 - tmdb:缓存读写迁移到 JsonCacheManager,移除类内静态缓存状态
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user