mirror of
https://github.com/simplex-chat/haskell.nix.git
synced 2026-06-03 09:17:32 +00:00
5b7f7f245c
git-subtree-dir: nix-tools git-subtree-mainline:1110a74a9dgit-subtree-split:555d57e1ea
36 lines
1.3 KiB
Haskell
36 lines
1.3 KiB
Haskell
module Stack2nix.Cache
|
|
( readCache
|
|
, appendCache
|
|
, cacheHits
|
|
) where
|
|
|
|
import Control.DeepSeq ((<$!!>))
|
|
import Control.Exception (catch, SomeException(..))
|
|
|
|
readCache :: FilePath
|
|
-> IO [( String -- url
|
|
, String -- rev
|
|
, String -- subdir
|
|
, String -- sha256
|
|
, String -- pkgname
|
|
, String -- nixexpr-path
|
|
)]
|
|
readCache f = fmap (toTuple . words) . lines <$!!> readFile f
|
|
where toTuple [ url, rev, subdir, sha256, pkgname, exprPath ]
|
|
= ( url, rev, subdir, sha256, pkgname, exprPath )
|
|
|
|
appendCache :: FilePath -> String -> String -> String -> String -> String -> String -> IO ()
|
|
appendCache f url rev subdir sha256 pkgname exprPath = do
|
|
appendFile f $! unwords [ url, rev, subdir, sha256, pkgname, exprPath ] ++ "\n"
|
|
|
|
cacheHits :: FilePath -> String -> String -> String -> IO [ (String, String) ]
|
|
cacheHits f url rev subdir
|
|
= do cache <- catch' (readCache f) (const (pure []))
|
|
return [ ( pkgname, exprPath )
|
|
| ( url', rev', subdir', sha256, pkgname, exprPath ) <- cache
|
|
, url == url'
|
|
, rev == rev'
|
|
, subdir == subdir' ]
|
|
where catch' :: IO a -> (SomeException -> IO a) -> IO a
|
|
catch' = catch
|