From 6ec604c116c53a538a3590e52fa4ad024fb65b64 Mon Sep 17 00:00:00 2001 From: Huan-zhaojun <111294954+Huan-zhaojun@users.noreply.github.com> Date: Wed, 29 Jul 2026 01:06:45 +0800 Subject: [PATCH] fix(media): fsync video temp file via read-write handle CommitVideoUpload opened the temp file with os.Open (O_RDONLY) and called Sync on it. POSIX allows fsync on read-only descriptors, but Windows FlushFileBuffers requires a handle with write access, so video upload commits failed with "Access is denied" on Windows. Open the file O_RDWR instead (no O_TRUNC, contents untouched); fsync semantics on POSIX are identical. Fixes the six Windows-only media test failures; Linux behavior unchanged. --- backend/internal/infra/media/local_store.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/internal/infra/media/local_store.go b/backend/internal/infra/media/local_store.go index 9167ac8f..d195cb2b 100644 --- a/backend/internal/infra/media/local_store.go +++ b/backend/internal/infra/media/local_store.go @@ -88,7 +88,11 @@ func (s *LocalStore) CommitVideoUpload(ctx context.Context, tempPath, storageKey return err } // 确保临时文件已落盘。 - file, err := os.Open(tempPath) + // 必须以 O_RDWR 打开:Windows 的 FlushFileBuffers 要求句柄具有写访问权限, + // 对 O_RDONLY 句柄调用 Sync 会返回 Access is denied; + // Linux 的 fsync 对只读/读写 fd 行为一致,此举不改变 POSIX 平台语义。 + // O_RDWR 不含 O_TRUNC,不会改动文件内容。 + file, err := os.OpenFile(tempPath, os.O_RDWR, 0) if err != nil { return fmt.Errorf("打开视频临时文件: %w", err) }