let normalize_seg segs =
  if List.exists (fun s -> (s = "."|| (s = "..")) segs
  then
    (let rec inner acc =
       function
       | [] -> List.rev acc
       | "." :: tl -> inner acc tl
       | ".." :: tl ->
           let new_acc = (* do not go too high *)
             (match acc with | [] -> [] | _ :: tl -> tl)
           in inner new_acc tl
       | hd :: tl -> inner (hd :: acc) tl
     in inner [] segs)
  else segs