fix(files): seek to start before writing for consistent behavior

Both local and S3 backends now seek to position 0 before writing,
ensuring consistent behavior regardless of the reader's current offset.
This commit is contained in:
kolaente
2026-02-04 19:37:49 +01:00
parent ab705d7d21
commit 41b511b322

View File

@@ -153,8 +153,15 @@ func (f *File) Delete(s *xorm.Session) (err error) {
return keyvalue.DecrBy(metrics.FilesCountKey, 1)
}
// writeToStorage writes content to the given path, handling both local and S3 backends
// writeToStorage writes content to the given path, handling both local and S3 backends.
// The reader is always seeked to position 0 before writing to ensure consistent behavior.
func writeToStorage(path string, content io.ReadSeeker, size uint64) error {
// Seek to start to ensure we write the complete content regardless of
// the reader's current position
if _, err := content.Seek(0, io.SeekStart); err != nil {
return fmt.Errorf("failed to seek to start of content: %w", err)
}
if s3Client == nil {
return afs.WriteReader(path, content)
}