2module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows,
3 writeSource, readSource, setupBundledCC) where
5-- System helper functions.
6import Control.Monad (when)
7import System.Directory (getTemporaryDirectory
9 , removeDirectoryRecursive
10 , createDirectoryIfMissing
13import System.FilePath ((</>), normalise, isAbsolute, dropFileName)
17import Control.Exception as CE
21import System.Environment (getEnv, setEnv, getExecutablePath)
24catchIO :: IO a -> (IOError -> IO a) -> IO a
27throwIO :: IOError -> IO a
31isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
33tempfile :: IO (FilePath, Handle)
34tempfile = do dir <- getTemporaryDirectory
35 openTempFile (normalise dir) "idris"
37-- | Read a source file, same as readFile but make sure the encoding is utf-8.
38readSource :: FilePath -> IO String
39readSource f = do h <- openFile f ReadMode
43-- | Write a source file, same as writeFile except the encoding is set to utf-8
44writeSource :: FilePath -> String -> IO ()
45writeSource f s = withFile f WriteMode (\h -> hSetEncoding h utf8 >> hPutStr h s)
47withTempdir :: String -> (FilePath -> IO a) -> IO a
48withTempdir subdir callback
49 = do dir <- getTemporaryDirectory
50 let tmpDir = (normalise dir) </> subdir
51 removeLater <- catchIO (createDirectoryIfMissing True tmpDir >> return True)
52 (\ ioError -> if isAlreadyExistsError ioError then return False
55 result <- callback tmpDir
56 when removeLater $ removeDirectoryRecursive tmpDir
59rmFile :: FilePath -> IO ()
60rmFile f = do putStrLn $ "Removing " ++ f
61 catchIO (removeFile f)
62 (\ioerr -> putStrLn $ "WARNING: Cannot remove file "
63 ++ f ++ ", Error msg:" ++ show ioerr)
67setupBundledCC = when hasBundledToolchain
69 exePath <- getExecutablePath
71 tcDir <- return getToolchainDir
72 absolute <- return $ isAbsolute tcDir
76 else dropFileName exePath ++ tcDir
77 let pathSep = if isWindows then ";" else ":"
78 present <- doesDirectoryExist target
80 $ do newPath <- return $ target ++ pathSep ++ path
83setupBundledCC = return ()
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list