Commits

Sebastien Mondet  committed bdde18e

System: fix following of symlinks in `file_tree`

  • Participants
  • Parent commits 34aa2b1

Comments (0)

Files changed (1)

File pvem_lwt_unix.ml

   let file_tree ?(follow_symlinks=false) path =
     let directory p l = return (`Node (p, l)) in
     let file p l = return (`Leaf (p, l)) in
-    let rec find_aux path =
+    let rec find_aux ?name_to_report path =
+      let name =
+        match name_to_report with
+        | Some s -> s
+        | None -> Filename.basename path in
       file_info path
       >>= begin function
       | `Absent -> fail (`File_not_found path)
       | `Character_device
       | `Fifo
       | `Regular_file _
-      | `Socket as k -> file (Filename.basename path) k
+      | `Socket as k -> file name k
       | `Symlink content as k ->
         begin match follow_symlinks with
         | true ->
             if Filename.is_relative content
             then (Filename.concat path content)
             else content in
-          find_aux continue
-        | false -> file (Filename.basename path) k
+          find_aux ~name_to_report:(Filename.basename path) continue
+        | false ->
+          file name k
         end
       | `Directory ->
         let `Stream next_dir = list_directory path in
               return (newone :: l))
         >>| List.rev
         >>= fun sub_tree ->
-        directory (Filename.basename path) sub_tree
+        directory name sub_tree
       end
     in
     (find_aux path