commercialhaskell / rio

A standard library for Haskell
Other
838 stars 54 forks source link

`withBinaryFileDurableAtomic` fails with nested folders #160

Closed lehins closed 4 years ago

lehins commented 5 years ago

Whenever a file that is being written to is located in a sub directory withBinaryFileDurableAtomic results in a runtime exception during the atomic rename.

Same problem applies to writeBinaryFileDurableAtomic.

Here is a short repro:


import Import
import RIO.Directory
import RIO.File

run :: RIO App ()
run = do
  logInfo "We're inside the application!"

  let foo = "foo.txt"
  withBinaryFileDurableAtomic foo WriteMode $ \h -> do
    hPutBuilder h "foo"
  logInfo $ "Written " <> fromString foo

  let barFoo = "bar/foo.txt"
  createDirectoryIfMissing True barFoo
  withBinaryFileDurableAtomic barFoo WriteMode $ \h -> do
    hPutBuilder h "bar - foo"
  logInfo $ "Written " <> fromString barFoo

Which results in:

$ stack run
We're inside the application!
Written foo.txt
atomic-durable-exe: closeFileDurableAtomic - renameFile: does not exist (No such file or directory)