Commits

camlspotter committed 75dd43f

Unix.Find.find: follow_symlink

Comments (0)

Files changed (2)

     method dev_inode : (int * int, exn) Result.t
     method dir : string
     method is_dir : bool
+    method is_ldir : bool
     method is_reg : bool
     method kind : (Unix.file_kind, exn) Result.t
+    method lkind : (Unix.file_kind, exn) Result.t
     method path : string
     method stat : (Unix.stats, exn) Result.t
+    method lstat : (Unix.stats, exn) Result.t
   end
 
   class path_ ~dir ~base ~depth = 
       method path = path
       method depth : int = depth
       method stat : (_,_) Result.t = try `Ok (stat path) with e -> `Error e
+      method lstat : (_,_) Result.t = try `Ok (lstat path) with e -> `Error e
       method kind : (_,_) Result.t = match self#stat with
         | `Error _exn -> `Error _exn
         | `Ok stat -> `Ok stat.st_kind
+      method lkind : (_,_) Result.t = match self#lstat with
+        | `Error _exn -> `Error _exn
+        | `Ok stat -> `Ok stat.st_kind
       method is_dir = self#kind = `Ok S_DIR
+      method is_ldir = self#lkind = `Ok S_DIR
       method is_reg = self#kind = `Ok S_REG
       method dev_inode : (_,_) Result.t = match self#stat with
       | `Ok stat -> `Ok (stat.st_dev, stat.st_ino)
 
   let prune () = raise Prune
   
-  let find ~f fnames =
+  let find ?(follow_symlink=false) ~f fnames =
   
     (* visited cache *)
     let visited = ref Inodes.empty in
             | "." | ".." -> dirs
             | name -> 
         	let pth = new path_ ~depth:(pth#depth + 1) ~dir:pth#path ~base:name in
-        	if try pth#is_dir with _ -> false then pth::dirs
+        	if try if follow_symlink then pth#is_dir else pth#is_ldir with _ -> false then pth::dirs
         	else begin find_non_dir pth; dirs end)
         in
         List.iter (if_not_visited_then ~f:find_dir) subdirs
     method dev_inode : (int * int, exn) Result.t
     method dir : string
     method is_dir : bool
+    method is_ldir : bool
     method is_reg : bool
     method kind : (Unix.file_kind, exn) Result.t
+    method lkind : (Unix.file_kind, exn) Result.t
     method path : string
     method stat : (Unix.stats, exn) Result.t
+    method lstat : (Unix.stats, exn) Result.t
   end
 
   val prune : unit -> 'a
-  val find : f:(path -> unit) -> string list -> unit
+  val find : ?follow_symlink:bool -> f:(path -> unit) -> string list -> unit
 
 end