File: Misc.hs

package info (click to toggle)
haskell-unixutils 1.22-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 132 kB
  • sloc: haskell: 973; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
-- |Wrappers around some handy unix shell commands.  Please let
-- me know if you think of better module names to hold these
-- functions.  -dsf
module System.Unix.Misc
    ( md5sum
    , gzip)
    where

import Control.Exception
import Data.Maybe
import System.Cmd
import System.Directory
import System.Exit
import System.IO
import System.Posix.Files
import System.Process
import System.Unix.Process

md5sum :: FilePath -> IO String
md5sum path =
    do
      (text, _, exitCode) <- simpleProcess "md5sum" [path]
      let output = listToMaybe (words text)
      case exitCode of
        ExitSuccess ->
            case output of
              Nothing -> error ("Error in output of 'md5sum " ++ path ++ "'")
              Just checksum -> return checksum
        ExitFailure _ -> error ("Error running 'md5sum " ++ path ++ "'")

gzip :: FilePath -> IO ()
gzip path =
    do
      result <- system ("gzip < " ++ path ++ " > " ++ path ++ ".gz")
      case result of
        ExitSuccess -> return ()
        e -> error (show e)