68f67ba926e001546feedfabcacada4ec8ccbf1d
[packages/haskell98.git] / Directory.hs
1 {-# LANGUAGE CPP #-}
2 #if __GLASGOW_HASKELL__ >= 701
3 {-# LANGUAGE Trustworthy #-}
4 #endif
5
6 module Directory (
7 Permissions( Permissions, readable, writable, executable, searchable ),
8 createDirectory, removeDirectory, removeFile,
9 renameDirectory, renameFile, getDirectoryContents,
10 getCurrentDirectory, setCurrentDirectory,
11 doesFileExist, doesDirectoryExist,
12 getPermissions, setPermissions,
13 getModificationTime
14 ) where
15
16 import System.Directory hiding (Permissions,
17 readable, writable, executable, searchable,
18 getPermissions, setPermissions)
19 import qualified System.Directory as SD
20
21 data Permissions = Permissions {
22 readable :: Bool,
23 writable :: Bool,
24 executable :: Bool,
25 searchable :: Bool
26 }
27 deriving (Eq, Ord, Read, Show)
28
29 getPermissions :: FilePath -> IO Permissions
30 getPermissions fp = do perm <- SD.getPermissions fp
31 return $ Permissions {
32 readable = SD.readable perm,
33 writable = SD.writable perm,
34 executable = SD.executable perm,
35 searchable = SD.searchable perm
36 }
37
38 setPermissions :: FilePath -> Permissions -> IO ()
39 setPermissions fp perm = let mkPerm = setOwnerReadable (readable perm)
40 . setOwnerWritable (writable perm)
41 . setOwnerExecutable (executable perm)
42 . setOwnerSearchable (searchable perm)
43 in SD.setPermissions fp (mkPerm emptyPermissions)
44