Skip to content

Commit

Permalink
Filesys.reify: fixed incorrect way of following links
Browse files Browse the repository at this point in the history
I would use normalize in `reify` to avoid dealing with Dot and
Dotdot. In particular I would follow (rel) links by concatenating with
the dirname of the link and its target (correct) then normalize
(incorrect, at least till #18 is not addressed).

This commit removes uses of `normalize` and deals with Dot and Dotdot
cases (which were not difficult at all, in the end).
  • Loading branch information
pveber committed Dec 12, 2015
1 parent 49b16dc commit 7c140da
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/async-unix/filesys.ml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ let rec reify
| `Yes_as_other_object ->
Deferred.Or_error.errorf "Path %s is not of the expected type" (Path.to_string p)
| `Yes | `Yes_modulo_links ->
match Path.normalize p with
match p with
| Path.Item Path.Root -> Deferred.Or_error.return p
| Path.Cons (Path.Root, p_rel) ->
reify_aux Path.root p_rel
Expand All @@ -280,12 +280,12 @@ and reify_aux
(Path.rel, o) Path.t ->
(Path.abs, o) Path.t Deferred.Or_error.t
= fun p_abs p_rel ->
match p_rel with
| Path.Item i ->
reify_aux_item p_abs i
| Path.Cons (h, t) ->
reify_aux_item p_abs h >>=? fun p_abs' ->
reify_aux p_abs' t
match p_rel with
| Path.Item i ->
reify_aux_item p_abs i
| Path.Cons (h, t) ->
reify_aux_item p_abs h >>=? fun p_abs' ->
reify_aux p_abs' t

and reify_aux_item
: type o.
Expand Down Expand Up @@ -319,11 +319,11 @@ and reify_aux_item
| `Rel p_rel ->
k
(Path.make_relative ~from:p_abs)
Path.(normalize (concat p_abs p_rel))
Path.(concat p_abs p_rel)
)
| Path.Broken_link _ -> Deferred.Or_error.return p
| Path.Dot -> assert false (* not possible, path is normalized *)
| Path.Dotdot -> assert false (* not possible, path is normalized *)
| Path.Dot -> Deferred.Or_error.return p
| Path.Dotdot -> Deferred.Or_error.return p


and reify_link
Expand All @@ -345,7 +345,7 @@ and reify_link
let abs_target = match target with
| `Abs p -> p
| `Rel p ->
Path.(normalize (concat p_abs p))
Path.concat p_abs p
in
reify abs_target >>=? fun reified_abs_target ->
let link = match target with
Expand Down

0 comments on commit 7c140da

Please sign in to comment.