Browse Source

Solve problem with program logging

 - The "num" value in tmp file was not incremented
 - When the file was existing, it was rewritten, which is
   wrong
Leo 10 years ago
parent
commit
1871993566
4 changed files with 3 additions and 7 deletions
  1. 0 1
      exec_cmd.ml
  2. 0 1
      tmp_file.json
  3. 2 4
      tmp_file.ml
  4. 1 1
      tmp_test.json

+ 0 - 1
exec_cmd.ml

@@ -57,7 +57,6 @@ let log ?(func= (+) 1 ) ~file_name =
     | _ -> failwith "Incorrect format"
 ;;
 
-
 (* Execute some command and log it *)
 let execute ?(display=true) ~tmp cmd =
     log ~func:((+) 1) ~file_name:tmp;

+ 0 - 1
tmp_file.json

@@ -1 +0,0 @@
-{"cmd":[],"num":0}

+ 2 - 4
tmp_file.ml

@@ -38,7 +38,7 @@ open Core.Std;;
 
 (* Function to create the tmp file *)
 let create_tmp_file ~name =
-  Out_channel.create name (* TODO create file in /tmp *)
+  Yojson.Basic.pretty_to_channel (Out_channel.create name) Const.tmp_file_template (* TODO create file in /tmp *)
 ;;
 
 (* Function to open tmp file *)
@@ -52,9 +52,7 @@ let rec init ~tmp =
           Core_extended.Shell.rm tmp;
           init ~tmp:tmp
         end
-      | `Yes -> Yojson.Basic.pretty_to_channel (Out_channel.create tmp)
-                  Const.tmp_file_template;
-                tmp
+      | `Yes -> tmp
 ;;
 
 (* Verify that the value exist *)

+ 1 - 1
tmp_test.json

@@ -1 +1 @@
-{"cmd":[],"num":1}
+{"cmd":[],"num":2}