Debian Codegraph @

src/System/Directory/Primitive.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Primitive System.Direcotry simple bindings to Haskell functions
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --guardedness #-}
8
9 module System.Directory.Primitive where
10
11 open import Agda.Builtin.Unit using (⊤)
12 open import Agda.Builtin.Bool using (Bool)
13 open import Agda.Builtin.IO using (IO)
14 open import Agda.Builtin.List using (List)
15 open import Agda.Builtin.Maybe using (Maybe)
16 open import Agda.Builtin.Nat using (Nat)
17 open import Agda.Builtin.String using (String)
18 open import System.FilePath.Posix.Primitive
19
20 {-# FOREIGN GHC import System.Directory #-}
21 {-# FOREIGN GHC import Data.Text #-}
22
23 data XdgDirectory : Set where
24 XdgData XdgConfig XdgCache XdgState : XdgDirectory
25
26 data XdgDirectoryList : Set where
27 XdgDataDirs XdgConfigDirs : XdgDirectoryList
28
29 {-# COMPILE GHC XdgDirectory = data XdgDirectory (XdgData|XdgConfig|XdgCache|XdgState) #-}
30 {-# COMPILE GHC XdgDirectoryList = data XdgDirectoryList (XdgDataDirs|XdgConfigDirs) #-}
31
32 private
33 variable
34 m n : Nature
35
36 postulate
37
38 -- Actions on directories
39
40 createDirectory : FilePath n → IO ⊤
41 createDirectoryIfMissing : Bool → FilePath n → IO ⊤
42 removeDirectory : FilePath n → IO ⊤
43 removeDirectoryRecursive : FilePath n → IO ⊤
44 removePathForcibly : FilePath n → IO ⊤
45 renameDirectory : FilePath m → FilePath n → IO ⊤
46 listDirectory : FilePath n → IO (List RelativePath)
47 getDirectoryContents : FilePath n → IO (List RelativePath)
48
49 -- Current working directory
50
51 getCurrentDirectory : IO AbsolutePath
52 setCurrentDirectory : FilePath n → IO ⊤
53 withCurrentDirectory : ∀ {a} {A : Set a} → FilePath n → IO A → IO A
54
55 -- Pre-defined directories
56
57 getHomeDirectory : IO AbsolutePath
58 getXdgDirectory : XdgDirectory → RelativePath → IO AbsolutePath
59 getXdgDirectoryList : XdgDirectoryList → IO (List AbsolutePath)
60 getAppUserDataDirectory : RelativePath → IO AbsolutePath
61 getUserDocumentsDirectory : IO AbsolutePath
62 getTemporaryDirectory : IO AbsolutePath
63
64 -- Actions on files
65
66 removeFile : FilePath m → IO ⊤
67 renameFile : FilePath m → FilePath n → IO ⊤
68 renamePath : FilePath m → FilePath n → IO ⊤
69 copyFile : FilePath m → FilePath n → IO ⊤
70 copyFileWithMetadata : FilePath m → FilePath n → IO ⊤
71 getFileSize : FilePath n → IO Nat
72 canonicalizePath : FilePath n → IO AbsolutePath
73 makeAbsolute : FilePath n → IO AbsolutePath
74 makeRelativeToCurrentDirectory : FilePath n → IO RelativePath
75
76 -- Existence tests
77
78 doesPathExist : FilePath n → IO Bool
79 doesFileExist : FilePath n → IO Bool
80 doesDirectoryExist : FilePath n → IO Bool
81 findExecutable : String → IO (Maybe AbsolutePath)
82 findExecutables : String → IO (List AbsolutePath)
83 findExecutablesInDirectories : List (FilePath n) → String → IO (List (FilePath n))
84 findFile : List (FilePath n) → String → IO (Maybe (FilePath n))
85 findFiles : List (FilePath n) → String → IO (List (FilePath n))
86 findFileWith : (FilePath n → IO Bool) → List (FilePath n) → String → IO (Maybe (FilePath n))
87 findFilesWith : (FilePath n → IO Bool) → List (FilePath n) → String → IO (List (FilePath n))
88 exeExtension : String
89
90 -- Symbolic links
91
92 createFileLink : FilePath m → FilePath n → IO ⊤
93 createDirectoryLink : FilePath m → FilePath n → IO ⊤
94 removeDirectoryLink : FilePath n → IO ⊤
95 pathIsSymbolicLink : FilePath n → IO Bool
96 getSymbolicLinkTarget : FilePath n → IO SomePath
97
98
99 {-# COMPILE GHC createDirectory = const createDirectory #-}
100 {-# COMPILE GHC createDirectoryIfMissing = const createDirectoryIfMissing #-}
101 {-# COMPILE GHC removeDirectory = const removeDirectory #-}
102 {-# COMPILE GHC removeDirectoryRecursive = const removeDirectoryRecursive #-}
103 {-# COMPILE GHC removePathForcibly = const removePathForcibly #-}
104 {-# COMPILE GHC renameDirectory = \ _ _ -> renameDirectory #-}
105 {-# COMPILE GHC listDirectory = const listDirectory #-}
106 {-# COMPILE GHC getDirectoryContents = const getDirectoryContents #-}
107
108 {-# COMPILE GHC getCurrentDirectory = getCurrentDirectory #-}
109 {-# COMPILE GHC setCurrentDirectory = const setCurrentDirectory #-}
110 {-# COMPILE GHC withCurrentDirectory = \ _ _ _ -> withCurrentDirectory #-}
111
112 {-# COMPILE GHC getHomeDirectory = getHomeDirectory #-}
113 {-# COMPILE GHC getXdgDirectory = getXdgDirectory #-}
114 {-# COMPILE GHC getXdgDirectoryList = getXdgDirectoryList #-}
115 {-# COMPILE GHC getAppUserDataDirectory = getAppUserDataDirectory #-}
116 {-# COMPILE GHC getUserDocumentsDirectory = getUserDocumentsDirectory #-}
117 {-# COMPILE GHC getTemporaryDirectory = getTemporaryDirectory #-}
118
119 {-# COMPILE GHC removeFile = const removeFile #-}
120 {-# COMPILE GHC renameFile = \ _ _ -> renameFile #-}
121 {-# COMPILE GHC renamePath = \ _ _ -> renamePath #-}
122 {-# COMPILE GHC copyFile = \ _ _ -> copyFile #-}
123 {-# COMPILE GHC copyFileWithMetadata = \ _ _ -> copyFileWithMetadata #-}
124 {-# COMPILE GHC getFileSize = const getFileSize #-}
125 {-# COMPILE GHC canonicalizePath = const canonicalizePath #-}
126 {-# COMPILE GHC makeAbsolute = const makeAbsolute #-}
127 {-# COMPILE GHC makeRelativeToCurrentDirectory = const makeRelativeToCurrentDirectory #-}
128
129 {-# COMPILE GHC doesPathExist = const doesPathExist #-}
130 {-# COMPILE GHC doesFileExist = const doesFileExist #-}
131 {-# COMPILE GHC doesDirectoryExist = const doesDirectoryExist #-}
132 {-# COMPILE GHC findExecutable = findExecutable . unpack #-}
133 {-# COMPILE GHC findExecutables = findExecutables . unpack #-}
134 {-# COMPILE GHC findExecutablesInDirectories = \ _ fps -> findExecutablesInDirectories fps . unpack #-}
135 {-# COMPILE GHC findFile = \ _ fps -> findFile fps . unpack #-}
136 {-# COMPILE GHC findFiles = \ _ fps -> findFiles fps . unpack #-}
137 {-# COMPILE GHC findFileWith = \ _ p fps -> findFileWith p fps . unpack #-}
138 {-# COMPILE GHC findFilesWith = \ _ p fps -> findFilesWith p fps . unpack #-}
139 {-# COMPILE GHC exeExtension = pack exeExtension #-}
140
141 {-# COMPILE GHC createFileLink = \ _ _ -> createFileLink #-}
142 {-# COMPILE GHC createDirectoryLink = \ _ _ -> createDirectoryLink #-}
143 {-# COMPILE GHC removeDirectoryLink = const removeDirectoryLink #-}
144 {-# COMPILE GHC pathIsSymbolicLink = const pathIsSymbolicLink #-}
145 {-# COMPILE GHC getSymbolicLinkTarget = const getSymbolicLinkTarget #-}