| | 125 | op2Match x (VRef (MkRef (IPair pv))) = do |
| | 126 | -- Pair match: ~~ :e executes the -e filetest. |
| | 127 | (k, v) <- pair_fetch pv |
| | 128 | isTrue <- fromVal v :: Eval Bool |
| | 129 | testOp <- fromVal k |
| | 130 | file <- fromVal x |
| | 131 | rv <- ($ file) $ case testOp of |
| | 132 | "r" -> FileTest.isReadable |
| | 133 | "w" -> FileTest.isWritable |
| | 134 | "x" -> FileTest.isExecutable |
| | 135 | "e" -> FileTest.exists |
| | 136 | "z" -> FileTest.sizeIsZero |
| | 137 | "s" -> FileTest.fileSize |
| | 138 | "M" -> FileTest.fileMTime |
| | 139 | "A" -> FileTest.fileATime |
| | 140 | "C" -> FileTest.fileCTime |
| | 141 | "f" -> FileTest.isFile |
| | 142 | "d" -> FileTest.isDirectory |
| | 143 | _ -> const $ die "Unknown file test operator" testOp |
| | 144 | if isTrue |
| | 145 | then return rv |
| | 146 | else fmap (castV . not) (fromVal rv) |
| | 147 | |