Parcourir la source

Correct bug with -r

When executing ```oclaunc -r``` more than once, it tries to delete an
unexisting file and this led to errors.

We now verify it before
Leo il y a 10 ans
Parent
commit
1277312313
2 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. 3 0
      CHANGELOG.md
  2. 7 1
      src/tmp_file.ml

+ 3 - 0
CHANGELOG.md

@@ -6,6 +6,9 @@
  + Locking tmp file to prevent launching two times the same item (**not tested
    enough**)
  + Messages displayed with bold, underline and colors.
+ + Correct bugs:
+   + When executing ```oclaunc -r``` more than once, it tries to delete an
+     unexisting file and this led to errors.
 
 ### v0.2.1
  + Add new command line option:

+ 7 - 1
src/tmp_file.ml

@@ -119,7 +119,13 @@ let log ?(func= (+) 1 ) () =
     * else display an error message *)
 let reset cmd_num =
     match cmd_num with
-    | 0 -> Sys.remove Const.tmp_file; Messages.ok "Tmp file removed"
+    | 0 -> (*Verify that file exist and if not, delete it *)
+            Sys.file_exists Const.tmp_file
+            |> (function
+                | `No -> Messages.ok "Tmp file already removed"
+                | `Unknown -> Messages.warning "Error while removing tmp file"
+                | `Yes -> Sys.remove Const.tmp_file; Messages.ok "Tmp file removed"
+            )
     | n when n > 0 ->
             (* Set the number *)
             log ~func:((fun a b -> a) n) ();