Browse Source

Now working

 - Reset rc file when there is an error while reading
Leo 10 years ago
parent
commit
ebc9ec44bc
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/file_com.ml

+ 6 - 1
src/file_com.ml

@@ -74,5 +74,10 @@ let rec init_rc ?(rc=(!Const.rc_file)) () =
   match (Sys.file_exists rc) with
     | `No -> create_rc_file ~name:rc; init_rc ~rc ();
     | `Unknown -> failwith "Error reading configuration file";
-    | `Yes -> In_channel.read_all rc |> Settings_j.rc_file_of_string
+    | `Yes -> (* Try to read, if there is an error, reset file *)
+            try
+                In_channel.read_all rc |> Settings_j.rc_file_of_string
+            with
+            | Yojson.Json_error _ -> (* Invalid file, delete, so that it will be reseted
+            on next call *) Sys.remove rc; init_rc ~rc ()
 ;;