forked from ocaml-multicore/eio
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: eio_posix: use directory FDs instead of realpath
realpath was an old hack from the libuv days.
- Loading branch information
Showing
9 changed files
with
397 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
type token = | ||
| Empty | ||
| DotDot | ||
| String of string | ||
|
||
let rec tokenise = function | ||
| [] -> [] | ||
| ["."] -> [Empty] (* "path/." is the same as "path/" *) | ||
| "." :: xs -> tokenise xs (* Skip dot if not at end *) | ||
| "" :: xs -> Empty :: tokenise xs | ||
| ".." :: xs -> DotDot :: tokenise xs | ||
| x :: xs -> String x :: tokenise xs | ||
|
||
module Rel = struct | ||
type t = | ||
| Leaf of { basename : string; trailing_slash : bool } | ||
| Self (* A final "." *) | ||
| Child of string * t | ||
| Parent of t | ||
|
||
let rec parse = function | ||
| [] -> Self | ||
| [String basename; Empty] -> Leaf { basename; trailing_slash = true } | ||
| [String basename] -> Leaf { basename; trailing_slash = false } | ||
| [DotDot] -> Parent Self | ||
| DotDot :: xs -> Parent (parse xs) | ||
| String s :: xs -> Child (s, parse xs) | ||
| Empty :: [] -> Self | ||
| Empty :: xs -> parse xs | ||
|
||
let parse s = parse (tokenise s) | ||
|
||
let rec concat a b = | ||
match a with | ||
| Leaf { basename; trailing_slash = _ } -> Child (basename, b) | ||
| Child (name, xs) -> Child (name, concat xs b) | ||
| Parent xs -> Parent (concat xs b) | ||
| Self -> b | ||
|
||
let rec dump f = function | ||
| Child (x, xs) -> Fmt.pf f "%S / %a" x dump xs | ||
| Parent xs -> Fmt.pf f ".. / %a" dump xs | ||
| Self -> Fmt.pf f "." | ||
| Leaf { basename; trailing_slash } -> | ||
Fmt.pf f "%S" basename; | ||
if trailing_slash then Fmt.pf f " /" | ||
end | ||
|
||
type t = | ||
| Relative of Rel.t | ||
| Absolute of Rel.t | ||
|
||
let rec parse_abs = function | ||
| "" :: [] -> Absolute Self | ||
| "" :: xs -> parse_abs xs | ||
| xs -> Absolute (Rel.parse xs) | ||
|
||
let parse = function | ||
| "" -> Relative Self | ||
| s -> | ||
match String.split_on_char '/' s with | ||
| "" :: path -> parse_abs path | ||
| path -> Relative (Rel.parse path) | ||
|
||
let dump f = function | ||
| Relative r -> Rel.dump f r | ||
| Absolute r -> Fmt.pf f "/ %a" Rel.dump r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Rel : sig | ||
type t = | ||
| Leaf of { basename : string; trailing_slash : bool } | ||
| Self (* A final "." *) | ||
| Child of string * t | ||
| Parent of t | ||
|
||
val concat : t -> t -> t | ||
|
||
val dump : t Fmt.t | ||
end | ||
|
||
type t = | ||
| Relative of Rel.t | ||
| Absolute of Rel.t | ||
|
||
val parse : string -> t | ||
(** Note: | ||
[parse "" = Relative Self] | ||
[parse ".." = Relative (Parent Self)] *) | ||
|
||
val dump : t Fmt.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.