Safe Haskell | None |
---|---|
Language | Haskell2010 |
- withTempFile :: forall a root. IsFileSystemRoot root => Path (Rooted root) -> String -> (AbsolutePath -> Handle -> IO a) -> IO a
- getFileSize :: IsFileSystemRoot root => Path (Rooted root) -> IO Integer
- handleDoesNotExist :: IO a -> IO (Maybe a)
- atomicCopyFile :: AbsolutePath -> AbsolutePath -> IO ()
- atomicWriteFile :: AbsolutePath -> ByteString -> IO ()
- atomicWithFile :: AbsolutePath -> (Handle -> IO a) -> IO a
Miscelleneous
:: IsFileSystemRoot root | |
=> Path (Rooted root) | Temp directory |
-> String | Template |
-> (AbsolutePath -> Handle -> IO a) | Callback |
-> IO a |
Create a short-lived temporary file
Creates the directory where the temp file should live if it does not exist.
getFileSize :: IsFileSystemRoot root => Path (Rooted root) -> IO Integer Source
handleDoesNotExist :: IO a -> IO (Maybe a) Source
Atomic file operations
:: AbsolutePath | Source |
-> AbsolutePath | Destination |
-> IO () |
Copy a file atomically
If both files live in the same directory, we call renameFile
. Otherwise
we read the source file and call atomicWriteFile
(because only when the
two files live in the same directory can be sure that the two locations are
on the same physical device).
:: AbsolutePath | Source |
-> ByteString | Destination |
-> IO () |
Atomically write a bytestring
We write to a temporary file in the destination folder and then rename.
:: AbsolutePath | Final destination |
-> (Handle -> IO a) | Callback |
-> IO a |
Like 'withFile .. WriteMode', but overwrite the destination atomically.
We open a handle to a temporary file in the same directory as the final location, then call the callback, and only when there are no exceptions finally rename the temporary file to the final destination.