Skip to content

Commit e425349

Browse files
committed
decided to move whole instance declaration into Plush.Run.Posix.IO
1 parent 721dd66 commit e425349

File tree

4 files changed

+52
-100
lines changed

4 files changed

+52
-100
lines changed

src-main/Recho.hs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import System.Environment
2020
import System.Exit
2121

2222
import Plush.Run.BuiltIns.Trivial (rechoExec)
23+
import Plush.Run.Posix.IO ()
2324

2425
main :: IO ()
2526
main = getArgs >>= rechoExec >>= exitWith

src/Plush/Run.hs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import qualified Data.Text.Encoding.Error as T
3838

3939
import Plush.Resource
4040
import Plush.Run.Posix
41+
import Plush.Run.Posix.IO ()
4142
import Plush.Run.ShellExec
4243
import Plush.Run.TestExec
4344

src/Plush/Run/Posix.hs

-47
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ import System.Posix.IO (stdInput, stdOutput, stdError,
5757
OpenMode(..), OpenFileFlags(..), defaultFileFlags)
5858
import System.Posix.Types
5959

60-
import qualified Plush.Run.Posix.IO as IO
61-
6260

6361
type Bindings = [(String, String)]
6462

@@ -170,48 +168,3 @@ stdJsonInput, stdJsonOutput :: Fd
170168
stdJsonInput = Fd 3
171169
stdJsonOutput = Fd 4
172170

173-
174-
instance PosixLike IO where
175-
createDirectory = IO.createDirectory
176-
removeDirectory = IO.removeDirectory
177-
getDirectoryContents = IO.getDirectoryContents
178-
getWorkingDirectory = IO.getWorkingDirectory
179-
changeWorkingDirectory = IO.changeWorkingDirectory
180-
181-
getInitialEnvironment = IO.getInitialEnvironment
182-
183-
type FileStatus IO = IO.FileStatus
184-
getFileStatus = IO.getFileStatus
185-
getSymbolicLinkStatus = IO.getSymbolicLinkStatus
186-
isExecutable = IO.isExecutable
187-
188-
removeLink = IO.removeLink
189-
setFileTimes = IO.setFileTimes
190-
touchFile = IO.touchFile
191-
192-
openFd = IO.openFd
193-
createFile = IO.createFile
194-
closeFd = IO.closeFd
195-
196-
dupTo = IO.dupTo
197-
dupFdCloseOnExec = IO.dupFdCloseOnExec
198-
setCloseOnExec = IO.setCloseOnExec
199-
200-
readAll = IO.readAll
201-
write = IO.write
202-
203-
getUserHomeDirectoryForName = IO.getUserHomeDirectoryForName
204-
realAndEffectiveIDsMatch = IO.realAndEffectiveIDsMatch
205-
getProcessID = IO.getProcessID
206-
207-
execProcess = IO.execProcess
208-
captureStdout = IO.captureStdout
209-
pipeline = IO.pipeline
210-
contentFd = IO.contentFd
211-
212-
instance PosixLikeFileStatus IO.FileStatus where
213-
accessTime = IO.accessTime
214-
modificationTime = IO.modificationTime
215-
isRegularFile = IO.isRegularFile
216-
isDirectory = IO.isDirectory
217-
isSymbolicLink = IO.isSymbolicLink

src/Plush/Run/Posix/IO.hs

+50-53
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,12 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-}
1616

17-
{-| This module exports the functions needed to create the instance of PosixIO
18-
for IO. The actual instance appears in "Plush.Run.Posix". This module is
19-
mostly to just remove clutter from that module.
17+
{-# Language TypeFamilies #-}
18+
{-# OPTIONS_GHC -fno-warn-orphans #-}
2019

21-
Note that many of these functions are just re-exports from "System.Posix".
22-
-}
23-
24-
25-
module Plush.Run.Posix.IO (
26-
P.createDirectory,
27-
P.removeDirectory,
28-
getDirectoryContents,
29-
P.getWorkingDirectory,
30-
P.changeWorkingDirectory,
31-
32-
getInitialEnvironment,
33-
34-
P.getFileStatus,
35-
P.getSymbolicLinkStatus,
36-
isExecutable,
37-
38-
P.removeLink,
39-
P.setFileTimes,
40-
P.touchFile,
41-
42-
P.openFd,
43-
P.createFile,
44-
P.closeFd,
45-
46-
dupTo,
47-
PM.dupFdCloseOnExec,
48-
setCloseOnExec,
49-
50-
readAll,
51-
write,
52-
53-
getUserHomeDirectoryForName,
54-
realAndEffectiveIDsMatch,
55-
getProcessID,
56-
57-
execProcess,
58-
captureStdout,
59-
pipeline,
60-
contentFd,
20+
{-| This module exports the instance of PosixIO for IO. -}
6121

62-
P.FileStatus,
63-
P.accessTime,
64-
P.modificationTime,
65-
P.isRegularFile,
66-
P.isDirectory,
67-
P.isSymbolicLink,
68-
) where
22+
module Plush.Run.Posix.IO () where
6923

7024
import Control.Applicative ((<$>), (<*>))
7125
import Control.Concurrent (forkIO)
@@ -85,6 +39,52 @@ import qualified System.IO.Error as IO
8539
import qualified System.Posix as P
8640
import qualified System.Posix.Missing as PM
8741

42+
import qualified Plush.Run.Posix as PL
43+
44+
instance PL.PosixLike IO where
45+
createDirectory = P.createDirectory
46+
removeDirectory = P.removeDirectory
47+
getDirectoryContents = getDirectoryContents
48+
getWorkingDirectory = P.getWorkingDirectory
49+
changeWorkingDirectory = P.changeWorkingDirectory
50+
51+
getInitialEnvironment = P.getEnvironment
52+
53+
type FileStatus IO = P.FileStatus
54+
getFileStatus = P.getFileStatus
55+
getSymbolicLinkStatus = P.getSymbolicLinkStatus
56+
isExecutable = isExecutable
57+
58+
removeLink = P.removeLink
59+
setFileTimes = P.setFileTimes
60+
touchFile = P.touchFile
61+
62+
openFd = P.openFd
63+
createFile = P.createFile
64+
closeFd = P.closeFd
65+
66+
dupTo = dupTo
67+
dupFdCloseOnExec = PM.dupFdCloseOnExec
68+
setCloseOnExec = setCloseOnExec
69+
70+
readAll = readAll
71+
write = write
72+
73+
getUserHomeDirectoryForName = getUserHomeDirectoryForName
74+
realAndEffectiveIDsMatch = realAndEffectiveIDsMatch
75+
getProcessID = getProcessID
76+
77+
execProcess = execProcess
78+
captureStdout = captureStdout
79+
pipeline = pipeline
80+
contentFd = contentFd
81+
82+
instance PL.PosixLikeFileStatus P.FileStatus where
83+
accessTime = P.accessTime
84+
modificationTime = P.modificationTime
85+
isRegularFile = P.isRegularFile
86+
isDirectory = P.isDirectory
87+
isSymbolicLink = P.isSymbolicLink
8888

8989

9090
getDirectoryContents :: FilePath -> IO [FilePath]
@@ -101,9 +101,6 @@ getDirectoryContents fp = do
101101
else readUntilNull ds >>= return . (entry :)
102102

103103

104-
getInitialEnvironment :: IO [(String, String)]
105-
getInitialEnvironment = P.getEnvironment
106-
107104
isExecutable :: FilePath -> IO Bool
108105
isExecutable path = P.fileAccess path False False True
109106

0 commit comments

Comments
 (0)