file - Atomicity with openTempFile -


i have following function:

safewrite :: text -> io () safewrite c = bracket (opentempfile "/tmp" "list.tmp")     (\(path, h) -> hclose h       >> copyfile path datafile       >> removefile path)     (\(_, h) -> ti.hputstr h c) 

i under impression safe, no copying happen if there errors during moment, , original file still usable. yesterday ended empty file, , have no idea go @ it. program had been running on month without hiccups points corner case didn't think of.

does method guarantee atomicity, meaning error somewhere else, or if not, why not? should guarantee atomicity?

your definition of mktemp atomic with respect haskell exceptions. if there exception print message failure (leaving file there).

  • it not atomic respect unix file system -- other programs overwrite same file
  • it not clean should there failure.

you can bit more clean up, optionally removing file if there exception, or using provided (atomic) mktemp function:

or using posix layer:


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -