I am writing a file transfer program, which I would like to know that the destination has enough disk space before start transfer.
I used method found here to create a "sparse" (or not) file:
func main() {
f, err := os.Create("foo.bar")
if err != nil {
log.Fatal(err)
}
defer f.Close()
if err := f.Truncate(1e7); err != nil {
log.Fatal(err)
}
}
My question is, will the "Truncate()" function create a real file, which actually uses that much disk space, or it just create a record in the "FAT" table to "claim" that the file uses that much space?
In another word, will Truncate() fail if there is not enough disk space?
EDIT
I removed the "go" tag, as it is NOT related to golang. And to emphasize, my purpose is to create a file of specific size that ACTUALLY uses the space, so that if there is not enough disk space, file creation will fail.