@@ -18,20 +18,21 @@ module Restyler.Monad.Directory
1818
1919import Restyler.Prelude
2020
21+ import Path.IO qualified as PathIO
2122import UnliftIO.Directory (Permissions (.. ))
2223import UnliftIO.Directory qualified as Directory
2324
2425class Monad m => MonadDirectory m where
25- getCurrentDirectory :: m FilePath
26- setCurrentDirectory :: FilePath -> m ()
27- doesFileExist :: FilePath -> m Bool
28- doesDirectoryExist :: FilePath -> m Bool
29- getPermissions :: FilePath -> m Permissions
30- setPermissions :: FilePath -> Permissions -> m ()
31- createFileLink :: FilePath -> FilePath -> m ()
32- pathIsSymbolicLink :: FilePath -> m Bool
33- listDirectory :: FilePath -> m [FilePath ]
34- removeFile :: FilePath -> m ()
26+ getCurrentDirectory :: m ( Path Abs Dir )
27+ setCurrentDirectory :: Path Abs Dir -> m ()
28+ doesFileExist :: forall b . Path b File -> m Bool
29+ doesDirectoryExist :: forall b . Path b Dir -> m Bool
30+ getPermissions :: forall b . Path b File -> m Permissions
31+ setPermissions :: forall b . Path b File -> Permissions -> m ()
32+ createFileLink :: forall b0 b1 . Path b0 File -> Path b1 File -> m ()
33+ pathIsSymbolicLink :: forall b . Path b File -> m Bool
34+ listDirectoryRecur :: forall b . Path b Dir -> m [Path Rel File ]
35+ removeFile :: forall b . Path b File -> m ()
3536
3637newtype ActualDirectory m a = ActualDirectory
3738 { unwrap :: m a
@@ -48,49 +49,49 @@ newtype ActualDirectory m a = ActualDirectory
4849instance (MonadLogger m , MonadUnliftIO m ) => MonadDirectory (ActualDirectory m ) where
4950 getCurrentDirectory = do
5051 logTrace " getCurrentDirectory"
51- liftIO Directory. getCurrentDirectory
52+ liftIO PathIO. getCurrentDir
5253
5354 setCurrentDirectory path = do
5455 logTrace $ " setCurrentDirectory" :# [" path" .= path]
55- liftIO $ Directory. setCurrentDirectory path
56+ liftIO $ PathIO. setCurrentDir path
5657
5758 doesFileExist path = do
5859 logTrace $ " doesFileExist" :# [" path" .= path]
59- liftIO $ Directory . doesFileExist path
60+ liftIO $ PathIO . doesFileExist path
6061
6162 doesDirectoryExist path = do
6263 logTrace $ " doesDirectoryExist" :# [" path" .= path]
63- liftIO $ Directory. doesDirectoryExist path
64+ liftIO $ PathIO. doesDirExist path
6465
6566 getPermissions path = do
6667 logTrace $ " getPermissions" :# [" path" .= path]
67- liftIO $ Directory . getPermissions path
68+ liftIO $ PathIO . getPermissions path
6869
6970 setPermissions path p = do
7071 logTrace $ " setPermissions" :# [" path" .= path]
71- liftIO $ Directory . setPermissions path p
72+ liftIO $ PathIO . setPermissions path p
7273
7374 createFileLink path t = do
7475 logTrace $ " createFileLink" :# [" path" .= path]
75- liftIO $ Directory . createFileLink path t
76+ liftIO $ PathIO . createFileLink path t
7677
7778 pathIsSymbolicLink path = do
7879 logTrace $ " pathIsSymbolicLink" :# [" path" .= path]
79- liftIO $ Directory. pathIsSymbolicLink path
80+ liftIO $ PathIO. isSymlink path
8081
81- listDirectory path = do
82- logTrace $ " listDirectory " :# [" path" .= path]
83- liftIO $ Directory. listDirectory path
82+ listDirectoryRecur path = do
83+ logTrace $ " listDirectoryRecur " :# [" path" .= path]
84+ liftIO $ snd <$> PathIO. listDirRecurRel path
8485
8586 removeFile path = do
8687 logTrace $ " removeFile" :# [" path" .= path]
87- liftIO $ Directory . removeFile path
88+ liftIO $ PathIO . removeFile path
8889
89- isFileExecutable :: MonadDirectory m => FilePath -> m Bool
90+ isFileExecutable :: MonadDirectory m => Path b File -> m Bool
9091isFileExecutable = fmap Directory. executable . getPermissions
9192
9293modifyPermissions
93- :: MonadDirectory m => FilePath -> (Permissions -> Permissions ) -> m ()
94+ :: MonadDirectory m => Path b File -> (Permissions -> Permissions ) -> m ()
9495modifyPermissions path f = do
9596 p <- getPermissions path
9697 setPermissions path $ f p
0 commit comments