Debian Codegraph @

preallocate_other.go

raw
1 //go:build !darwin
2
3 package desync
4
5 import "os"
6
7 // preallocateFile truncates the file to the given size, creating it if
8 // it doesn't exist. On Linux (ext4) and other platforms, Truncate
9 // produces a file that reads back as zeros without sparse-hole issues,
10 // so no special preallocation is needed.
11 func preallocateFile(name string, size int64) error {
12 f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE, 0666)
13 if err != nil {
14 return err
15 }
16 defer f.Close()
17 return f.Truncate(size)
18 }