-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Fpath to represent file paths (#64)
* Use Fpath to represent file paths * Update the docs * Fix problems due to Fpath.parent being not the same Filename.dirname * Update tests to accept that '//////' gets normalized to '//' by Fpath
- Loading branch information
Showing
24 changed files
with
219 additions
and
234 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
*) | ||
|
||
open Printf | ||
open Filename_.Operators | ||
open Fpath_.Operators | ||
open Cmdliner | ||
|
||
(* | ||
|
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 |
---|---|---|
@@ -1,20 +1,12 @@ | ||
(* | ||
A trivial wrapper around "string" to make signatures clearer. | ||
Subset of the standard 'Filename' module using 'Fpath.t' for the type | ||
of file paths. | ||
*) | ||
|
||
type t = string | ||
let temp_file ?temp_dir prefix suffix = | ||
Filename.temp_file | ||
?temp_dir:(Option.map Fpath.to_string temp_dir) | ||
prefix suffix | ||
|> Fpath.v | ||
|
||
let of_string x = x | ||
let to_string x = x | ||
|
||
include Filename | ||
|
||
module Operators = struct | ||
let ( // ) a b = | ||
if is_relative b then concat a b else b | ||
|
||
let ( / ) a seg = | ||
concat a seg | ||
|
||
let ( !! ) path = path | ||
end | ||
let get_temp_dir_name () = Filename.get_temp_dir_name () |> Fpath.v |
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 |
---|---|---|
@@ -1,36 +1,7 @@ | ||
(* | ||
A trivial wrapper around "string" to make signatures clearer. | ||
For internal use only. | ||
It would be nicer to use 'Fpath' but we're trying to minimize | ||
dependencies outside the standard library. | ||
Subset of the standard 'Filename' module using 'Fpath.t' for the type | ||
of file paths. | ||
*) | ||
|
||
type t | ||
|
||
val of_string : string -> t | ||
val to_string : t -> string | ||
|
||
(* Functions from the 'Filename' module. *) | ||
val basename : t -> string | ||
val dirname : t -> t | ||
val is_relative : t -> bool | ||
val concat : t -> t -> t | ||
val dir_sep : string | ||
val temp_file : ?temp_dir:t -> string -> string -> t | ||
|
||
(* Extensions *) | ||
module Operators : sig | ||
(* Turn a, b into a/b; turn a, /b into /b. | ||
Same as ( // ) in Fpath. *) | ||
val ( // ) : t -> t -> t | ||
|
||
(* Append a path segment. | ||
Same as ( / ) in Fpath. | ||
The appended segment shouldn't contain slashes or backslashes | ||
but this isn't enforced. *) | ||
val ( / ) : t -> string -> t | ||
|
||
(* to_string *) | ||
val ( !! ) : t -> string | ||
end | ||
val temp_file : ?temp_dir:Fpath.t -> string -> string -> Fpath.t | ||
val get_temp_dir_name : unit -> Fpath.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(* | ||
Extensions of the Fpath module which deals with file paths. | ||
*) | ||
|
||
module Operators = struct | ||
let ( // ) = Fpath.( // ) | ||
let ( / ) = Fpath.( / ) | ||
let ( !! ) = Fpath.to_string | ||
end | ||
|
||
let to_string_list paths = List.rev_map Fpath.to_string paths |> List.rev | ||
|
||
let dirname path = | ||
let dir, _basename = Fpath.split_base path in | ||
Fpath.rem_empty_seg dir |
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,26 @@ | ||
(* | ||
Extensions of the Fpath module which deals with file paths. | ||
*) | ||
|
||
(* Operators can be put in scope with 'open Fpath_.Operators' *) | ||
module Operators : sig | ||
val ( // ) : Fpath.t -> Fpath.t -> Fpath.t | ||
val ( / ) : Fpath.t -> string -> Fpath.t | ||
|
||
(* to_string *) | ||
val ( !! ) : Fpath.t -> string | ||
end | ||
|
||
val to_string_list : Fpath.t list -> string list | ||
|
||
(* Same as Filename.dirname: | ||
/a/b -> /a | ||
/a/b/ -> /a | ||
/a -> / | ||
a -> . | ||
/ -> / (!) | ||
. -> . (!) | ||
/a/.. -> /a (!) | ||
*) | ||
val dirname : Fpath.t -> Fpath.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
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
Oops, something went wrong.