I have a program that used to overwrite input files in-place, and that was lacking atomicity. When switching to renameio, the biggest question for me was - what perm bits should I use? The old os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0) call didn't need to change any permissions, so it's not obvious what should I do here.
I don't think there's a way to replace a file and keep its permission bits in an atomic way. For now, I'm just using os.Lstat first to grab the bits, then using them for renameio.WriteFile. I realise that's racy, for example if the permissions change between the two operations, but it seems like an OK tradeoff while keeping it impossible to lose data.
Maybe I'm alone in seeing this as a gap in the README or docs. Do you reckon any tips would be a good addition?
I have a program that used to overwrite input files in-place, and that was lacking atomicity. When switching to renameio, the biggest question for me was - what
permbits should I use? The oldos.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0)call didn't need to change any permissions, so it's not obvious what should I do here.I don't think there's a way to replace a file and keep its permission bits in an atomic way. For now, I'm just using
os.Lstatfirst to grab the bits, then using them forrenameio.WriteFile. I realise that's racy, for example if the permissions change between the two operations, but it seems like an OK tradeoff while keeping it impossible to lose data.Maybe I'm alone in seeing this as a gap in the README or docs. Do you reckon any tips would be a good addition?