From a71a18ce82be43026a3c26cf701e5c7183167b8a Mon Sep 17 00:00:00 2001 From: truewhile <62226914+truewhile@users.noreply.github.com> Date: Sun, 6 Sep 2026 13:42:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(upload):=20=E5=88=A0=E6=97=A7=E5=85=83?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=B8=8D=E4=B8=AD?= =?UTF-8?q?=E6=AD=A2=E4=BB=BB=E5=8A=A1=EF=BC=8C=E7=BB=A7=E7=BB=AD=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 旧逻辑:DeleteFiles 失败 → uploadTaskFailWithRetry → 任务重试 → 再次 DeleteFiles 失败 → 永远无法上传,形成死循环。 新逻辑:DeleteFiles 失败时记录 warn 日志后继续上传新文件。 旧副本由下次同步的 scanLocalMetaForUpload 检测(新旧两个副本, 命中新版本后把旧版本 cid 收入 pendingDeletes)并通过 cleanupBatchRedundantFiles 异步批量清理。 这修复了小姐姐库在 115 限流环境下每次增量同步都重复上传 大量元数据的问题(Heyzo 等目录文件被上传了 7 次以上)。 --- internal/service/strm_queue.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/service/strm_queue.go b/internal/service/strm_queue.go index 184ff40..c56004d 100644 --- a/internal/service/strm_queue.go +++ b/internal/service/strm_queue.go @@ -366,9 +366,11 @@ func (s *StrmService) processUpload115(ctx context.Context, task *model.StrmUplo finish(model.StrmTaskFailed, "该网盘不支持元数据上传") return } - // 以本地为准:网盘端已有同名但内容不同的旧元数据时,先批量删除所有旧副本再上传。 - // 115 的上传接口不保证同名覆盖,直接上传可能产生同名重复文件;删除失败则 - // 任务重试(旧文件 ID 失效的场景会在下次同步后自动修复)。 + // 以本地为准:网盘端已有同名但内容不同的旧元数据时,先尝试批量删除所有旧副本再上传。 + // 115 的上传接口不保证同名覆盖,直接上传可能产生同名重复文件。 + // 删除失败时不中止任务——继续上传新文件,旧副本交由下次同步的 cleanupBatchRedundantFiles + // 按目录批量清理(下次同步会看到新旧两个版本,命中新版本后把旧版本 cid 收入 pendingDeletes + // 异步删除)。这样避免了「删旧失败 → 任务重试 → 再次删旧失败 → 永远无法上传」的死循环。 if task.RemoteRef != "" { open115, ok := provider.(cloud.OpenAPI115Provider) if !ok { @@ -377,8 +379,11 @@ func (s *StrmService) processUpload115(ctx context.Context, task *model.StrmUplo } refs := strings.Split(task.RemoteRef, ",") if err := open115.OpenClient().DeleteFiles(ctx, task.RemotePath, refs...); err != nil { - s.uploadTaskFailWithRetry(task, "删除网盘旧元数据失败:"+err.Error()) - return + s.log.Warn("删除网盘旧元数据失败,跳过删除继续上传新文件", + zap.String("task_id", task.ID), + zap.String("local_path", task.LocalPath), + zap.Error(err)) + // 不 return:继续上传新文件,旧副本由下次同步清理 } } f, err := os.Open(task.LocalPath)