mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-30 15:02:27 -05:00
Update dependencies:
- github.com/gin-gonic/gin v1.10.0 -> v1.10.1
- github.com/gin-contrib/sessions v1.10.3 -> v1.10.4
- github.com/jackc/pgx/v5 v5.7.4 -> v5.7.5
- github.com/minio/minio-go/v7 v7.0.91 -> v7.0.92
- github.com/pquerna/otp v1.4.0 -> v1.5.0
- github.com/tdewolff/minify/v2 v2.23.5 -> v2.23.8
- github.com/yuin/goldmark v1.7.11 -> v1.7.12
- go.opentelemetry.io/otel{,/*} v1.35.0 -> v1.36.0
- modernc.org/sqlite v1.37.0 -> v1.37.1
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4188
Reviewed-by: Daenney <daenney@noreply.codeberg.org>
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
93 lines
2.5 KiB
Go
93 lines
2.5 KiB
Go
//go:build (linux || darwin || dragonfly || freebsd || illumos || netbsd || openbsd) && !appengine && !tinygo
|
|
// +build linux darwin dragonfly freebsd illumos netbsd openbsd
|
|
// +build !appengine
|
|
// +build !tinygo
|
|
|
|
package msgp
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// ReadFile reads a file into 'dst' using
|
|
// a read-only memory mapping. Consequently,
|
|
// the file must be mmap-able, and the
|
|
// Unmarshaler should never write to
|
|
// the source memory. (Methods generated
|
|
// by the msgp tool obey that constraint, but
|
|
// user-defined implementations may not.)
|
|
//
|
|
// Reading and writing through file mappings
|
|
// is only efficient for large files; small
|
|
// files are best read and written using
|
|
// the ordinary streaming interfaces.
|
|
func ReadFile(dst Unmarshaler, file *os.File) error {
|
|
stat, err := file.Stat()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err := syscall.Mmap(int(file.Fd()), 0, int(stat.Size()), syscall.PROT_READ, syscall.MAP_SHARED)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
adviseRead(data)
|
|
_, err = dst.UnmarshalMsg(data)
|
|
uerr := syscall.Munmap(data)
|
|
if err == nil {
|
|
err = uerr
|
|
}
|
|
return err
|
|
}
|
|
|
|
// MarshalSizer is the combination
|
|
// of the Marshaler and Sizer
|
|
// interfaces.
|
|
type MarshalSizer interface {
|
|
Marshaler
|
|
Sizer
|
|
}
|
|
|
|
// WriteFile writes a file from 'src' using
|
|
// memory mapping. It overwrites the entire
|
|
// contents of the previous file.
|
|
// The mapping size is calculated
|
|
// using the `Msgsize()` method
|
|
// of 'src', so it must produce a result
|
|
// equal to or greater than the actual encoded
|
|
// size of the object. Otherwise,
|
|
// a fault (SIGBUS) will occur.
|
|
//
|
|
// Reading and writing through file mappings
|
|
// is only efficient for large files; small
|
|
// files are best read and written using
|
|
// the ordinary streaming interfaces.
|
|
//
|
|
// NOTE: The performance of this call
|
|
// is highly OS- and filesystem-dependent.
|
|
// Users should take care to test that this
|
|
// performs as expected in a production environment.
|
|
// (Linux users should run a kernel and filesystem
|
|
// that support fallocate(2) for the best results.)
|
|
func WriteFile(src MarshalSizer, file *os.File) error {
|
|
sz := src.Msgsize()
|
|
err := fallocate(file, int64(sz))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err := syscall.Mmap(int(file.Fd()), 0, sz, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
adviseWrite(data)
|
|
chunk := data[:0]
|
|
chunk, err = src.MarshalMsg(chunk)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
uerr := syscall.Munmap(data)
|
|
if uerr != nil {
|
|
return uerr
|
|
}
|
|
return file.Truncate(int64(len(chunk)))
|
|
}
|