top | item 44177998

(no title)

database64128 | 9 months ago

Just write `defer v.Close()`? In almost all cases, `close(2)` errors can be safely ignored. Rust also does this: https://github.com/rust-lang/rust/blob/792fc2b033aea7ea7b766...

discuss

order

catlifeonmars|9 months ago

I don’t think you want to do this for files you’ve opened for writing.

In fact it’s quite common to “commit” on close, at least from what I’ve seen.

database64128|9 months ago

> In fact it’s quite common to “commit” on close, at least from what I’ve seen.

close(2) does not "commit". You have to call v.Sync() (i.e. fsync(2)) for that.

From man 2 close:

       A successful close does not guarantee that the data has been successfully saved to disk, as the kernel uses the buffer cache  to  defer  writes.   Typi‐
       cally,  filesystems  do  not flush buffers when a file is closed.  If you need to be sure that the data is physically stored on the underlying disk, use
       fsync(2).  (It will depend on the disk hardware at this point.)