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