mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Fix macOS osAllocate.
Mozilla is just wrong. https://searchfox.org/mozilla-central/source/xpcom/glue/FileUtils.cpp
This commit is contained in:
@@ -39,12 +39,11 @@ func osAllocate(file *os.File, size int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/11497568/867786
|
||||
store := unix.Fstore_t{
|
||||
Flags: unix.F_ALLOCATECONTIG,
|
||||
Flags: unix.F_ALLOCATEALL | unix.F_ALLOCATECONTIG,
|
||||
Posmode: unix.F_PEOFPOSMODE,
|
||||
Offset: 0,
|
||||
Length: size,
|
||||
Length: size - off,
|
||||
}
|
||||
|
||||
// Try to get a continuous chunk of disk space.
|
||||
|
||||
52
vfs/os_unix_test.go
Normal file
52
vfs/os_unix_test.go
Normal file
@@ -0,0 +1,52 @@
|
||||
//go:build unix && !sqlite3_flock && !sqlite3_nosys
|
||||
|
||||
package vfs
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func Test_osAllocate(t *testing.T) {
|
||||
if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
f, err := os.CreateTemp(t.TempDir(), "file")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = io.CopyN(f, rand.Reader, 1024*1024)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
n, err := f.Seek(0, io.SeekEnd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 1024*1024 {
|
||||
t.Fatalf("got %d, want %d", n, 1024*1024)
|
||||
}
|
||||
|
||||
err = osAllocate(f, 16*1024*1024)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var stat unix.Stat_t
|
||||
err = unix.Stat(f.Name(), &stat)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if stat.Blocks*512 != 16*1024*1024 {
|
||||
t.Fatalf("got %d, want %d", stat.Blocks*512, 16*1024*1024)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user