Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

34 lines (29 sloc) 0.898 kb
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Keter.TempFolder
( TempFolder
, setup
, getFolder
) where
import Keter.Prelude
import Data.Word (Word)
import Keter.Postgres (Appname)
import qualified Data.IORef as I
data TempFolder = TempFolder
{ tfRoot :: FilePath
, tfCounter :: IORef Word
}
setup :: FilePath -> KIO (Either SomeException TempFolder)
setup fp = liftIO $ do
e <- isDirectory fp
when e $ removeTree fp
createTree fp
c <- I.newIORef minBound
return $ TempFolder fp c
getFolder :: TempFolder -> Appname -> KIO (Either SomeException FilePath)
getFolder TempFolder {..} appname = do
!i <- atomicModifyIORef tfCounter $ \i -> (succ i, i)
let fp = tfRoot </> fromText (appname ++ "-" ++ show i)
liftIO (createTree fp >> return fp)
Jump to Line
Something went wrong with that request. Please try again.