Commits

Anonymous committed eccd7ac

+ WithM.with_sys_chdir

Comments (0)

Files changed (1)

 
 module WithLwtIO = W(LwtIO)
 ;
+
+
+type dir_abstract = string
+;
+
+
+value with_sys_chdir
+ : WithI.withres string dir_abstract
+ =
+   let module M = Identity in
+   let open WithI in
+   { cons = fun new_dir ->
+       M.catch 
+         (fun () ->
+            let old_dir = Sys.getcwd () in
+            let () = Sys.chdir new_dir in
+            M.return old_dir
+         )
+         M.error
+   ; fin = fun old_dir ->
+       M.catch
+         (fun () -> M.bind_rev (Sys.chdir old_dir) (fun () -> M.return ()))
+         M.error
+   }
+;