gg icon indicating copy to clipboard operation
gg copied to clipboard

missing fsync in atomic create

Open photoszzt opened this issue 5 years ago • 2 comments

I think this code is not atomic. https://github.com/StanfordSNR/gg/blob/febdf22643655bf9a89f7ddc8b5849dc7e8f4d9e/src/util/path.cc#L188-L209 Two fsync is missing. You need to fsync the temp file and fsync the containing directory after the rename. See: https://lwn.net/Articles/457667/

photoszzt avatar Sep 07 '19 16:09 photoszzt

I don't thing consistency in the face of a kernel panic or power failure is a requirement based on how that code is used. Adding 2 fsyncs to every file creation would just slow builds down.

JustinAzoff avatar Oct 21 '19 19:10 JustinAzoff

@JustinAzoff The problem is if I don't put these two fsyncs, the program fails. It complaints that the file is missing when the file is created but the directory is not fsync.

photoszzt avatar Oct 21 '19 19:10 photoszzt