úÎ:±9ÉSafe‹ Safe$<9ŠThis data type is passed to  and ; to change the behaviour of where the temp file is created.?The following will be called inside the atomic write functions: )openTempFile tempFileDir tempFileTemplateSee the documentation for  % to see how these arguments are used. )atomicReplaceFile options @file@ contentsatomically replaces file's with contents.options should be Just some 6, which detail where the temporary file is placed, or C for the default of creating a temp file in the existing directory.If the target file must exist.©As moving is atomic on filesystems generally, the target file should only ever be in two states, either what it was like before it was written or what it was like after.iAtomically modifies a file, by reading it and applying a function to it's contents. This is different to *, which is best illistrated by an example.ŠLets say a file contains a single integer, say "1". An IO statement is writen that reads the file, adds one to the number, and then calls  to write it back out.IRunning this should result the file being replaced with the contents "2".6Now lets say we run this from two different processes.cIf the processes run sequentially, we will read "1", then write "2", then read "2", then write "3".×But if the processes run overlapping, the first process may read "1", and before it writes "2", the second process may read "1". The first process will then write "2" but then also the second process will write "2".JWe've clobbered a write, and the behavour is inconsistent based on timing.This is where  comes in.‡ gets passed a function, and will lock a lock file, (passed as an argument) to ensure two processes can not run on it at the same time.1If the two processes in the above case both used -, then the result would be "3" in call cases.zMake sure the lock file is different to the file you're modifying, or else you'll get permission denied errors on windows.ROne may ask, if you're going to lock the files, why bother with temp files at all?FWell, you wouldn't need to if all your processes asked for locks. But  achieves two things: From writers that use : Writes occur sequentiallyoFrom all readers (including those who do not attempt to gain a lock): Will only ever see a consistent state.ZJust using locks and not an "atomic style" temp file and replace does not achieve point 2.The arguments to  are similar to W, except for the third argument, which details how to replace the contents of the file.TThis replacement function argument is quite complex. Lets say we have the following: Uf x = duringAction >> pure (afterAction, whatToWrite) atomicModifyFile options file fThe whole result of f/ must be an IO action. Often this will be just pure something;, but in the above case I've included an actual IO action:  duringAction.-The following sequences of events will occur: Exclusively lock the lock file.-The entire contents of the file will be read.The IO  duringAction will be executed, as f) is run against the contents of the file.If  whatToWrite is  Just contents, contentsU will be written to to a temp file and then moved over the target file. But if  whatToWrite is Nothing , do nothing.Unlock the lock file. afterAction, will be executed as the IO return value of .nSo this function has a lot of flexibility, however, in many simple use cases it will look something like this: NatomicModifyFile options file (\contents -> pure (pure (), Just (f contents)))Which just says apply fA to the contents of the contents of the file and do nothing else.Like , & will fail if the file does not exist.     .atomic-file-ops-0.3.0.0-51TBUU1xTL6Byy4kXdyWVRSystem.IO.AtomicFileOpsPaths_atomic_file_opsAtomicTempOptions tempFileDirtempFileTemplateatomicReplaceFileatomicModifyFileversion getBinDir getLibDir getDynLibDir getDataDir getLibexecDir getSysconfDirgetDataFileNamebase System.IO openTempFileGHC.BaseNothing