temporary-1.2.0.3: Portable temporary file and directory support for Windows and Unix, based on code from Cabal

Safe Haskell | Safe
Language | Haskell98

System.IO.Temp

Synopsis

- withSystemTempFile :: (MonadIO m, MonadMask m) => String -> (FilePath -> Handle -> m a) -> m a
- withSystemTempDirectory :: (MonadIO m, MonadMask m) => String -> (FilePath -> m a) -> m a
- withTempFile :: (MonadIO m, MonadMask m) => FilePath -> String -> (FilePath -> Handle -> m a) -> m a
- withTempDirectory :: (MonadMask m, MonadIO m) => FilePath -> String -> (FilePath -> m a) -> m a
- openTempFile :: FilePath -> String -> IO (FilePath, Handle)
- openBinaryTempFile :: FilePath -> String -> IO (FilePath, Handle)
- openNewBinaryFile :: FilePath -> String -> IO (FilePath, Handle)
- createTempDirectory :: FilePath -> String -> IO FilePath

# Documentation

withSystemTempFile Source

Arguments

:: (MonadIO m, MonadMask m) |
=> String | File name template. See `openTempFile`.
-> (FilePath -> Handle -> m a) | Callback that can use the file
-> m a |

Create and use a temporary directory in the system standard temporary directory.

Behaves exactly the same as `withTempFile`, except that the parent temporary directory will be that returned by `getTemporaryDirectory`.

withSystemTempDirectory Source

Arguments

:: (MonadIO m, MonadMask m) |
=> String | Directory name template. See `openTempFile`.
-> (FilePath -> m a) | Callback that can use the directory
-> m a |

Create and use a temporary directory in the system standard temporary directory.

Behaves exactly the same as `withTempDirectory`, except that the parent temporary directory will be that returned by `getTemporaryDirectory`.

withTempFile Source

Arguments

:: (MonadIO m, MonadMask m) |
=> FilePath | Temp dir to create the file in
-> String | File name template. See `openTempFile`.
-> (FilePath -> Handle -> m a) | Callback that can use the file
-> m a |

Use a temporary filename that doesn't already exist.

Creates a new temporary file inside the given directory, making use of the template. The temp file is deleted after use. For example:

    withTempFile "src" "sdist." $ \tmpFile hFile -> do ...

The `tmpFlie` will be file in the given directory, e.g. `src/sdist.342`.

withTempDirectory Source

Arguments

:: (MonadMask m, MonadIO m) |
=> FilePath | Temp directory to create the directory in
-> String | Directory name template. See `openTempFile`.
-> (FilePath -> m a) | Callback that can use the directory
-> m a |

Create and use a temporary directory.

Creates a new temporary directory inside the given directory, making use of the template. The temp directory is deleted after use. For example:

    withTempDirectory "src" "sdist." $ \tmpDir -> do ...

The `tmpDir` will be a new subdirectory of the given directory, e.g. `src/sdist.342`.

openTempFile

Arguments

:: FilePath | Directory in which to create the file
-> String | File name template. If the template is "foo.ext" then the created file will be "fooXXX.ext" where XXX is some random number.
-> IO (FilePath, Handle) |

The function creates a temporary file in ReadWrite mode. The created file isn't deleted automatically, so you need to delete it manually.

The file is creates with permissions such that only the current user can read/write it.

With some exceptions (see below), the file will be created securely in the sense that an attacker should not be able to cause openTempFile to overwrite another file on the filesystem using your credentials, by putting symbolic links (on Unix) in the place where the temporary file is to be created. On Unix the `O_CREAT` and `O_EXCL` flags are used to prevent this attack, but note that `O_EXCL` is sometimes not supported on NFS filesystems, so if you rely on this behaviour it is best to use local filesystems only.

openBinaryTempFile :: FilePath -> String -> IO (FilePath, Handle)

Like `openTempFile`, but opens the file in binary mode. See `openBinaryFile` for more comments.

openNewBinaryFile :: FilePath -> String -> IO (FilePath, Handle) Source

createTempDirectory :: FilePath -> String -> IO FilePath Source