Parcourir la source

Add verification for tmp file

 - Verify if file exists else create it
Leo il y a 10 ans
Parent
commit
aa8414053e
2 fichiers modifiés avec 13 ajouts et 1 suppressions
  1. 2 0
      oclaunch.ml
  2. 11 1
      tmp_file.ml

+ 2 - 0
oclaunch.ml

@@ -42,5 +42,7 @@ let rc_content = File_com.init_rc ~rc:Const.rc_file;;
 (* Obtain data from tmp file *)
 let tmp_content = Tmp_file.init ~tmp:Const.tmp_file;;
 
+(*
 (* Execute each item in config file *)
 List.map ~f:Exec_cmd.execute rc_content.progs;;
+*)

+ 11 - 1
tmp_file.ml

@@ -36,9 +36,19 @@
 
 open Core.Std;;
 
+(* Function to create the tmp file *)
+let create_tmp_file ~name =
+  Out_channel.create name (* TODO create file in /tmp *)
+;;
+
 (* Function to open tmp file *)
 let init ~tmp =
-  Yojson.Basic.from_file tmp;;
+  (* If file do not exists, create it *)
+  let file_exists = (Sys.file_exists tmp) in
+    match file_exists with
+      | `No | `Unknown -> create_tmp_file ~name:tmp
+      | `Yes -> Yojson.Basic.from_file tmp
+;;
 
 (* Verify that the value exist *)
 let verify_key_exist ~key entry =