Skip to content

Commit

Permalink
Fix ocaml#285
Browse files Browse the repository at this point in the history
Do not get stuck in a broken state: we always try to fix the lock errors, it's better to be a bit unsafe but not stuck.
  • Loading branch information
samoht committed Nov 9, 2012
1 parent a077ed7 commit 6e86353
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/core/opamSystem.ml
Expand Up @@ -391,17 +391,22 @@ let flock file =

let funlock file =
let id = string_of_int (Unix.getpid ()) in
if Sys.file_exists file then begin
if Sys.file_exists file then (
let ic = open_in file in
let s = input_line ic in
close_in ic;
if s = id then begin
OpamGlobals.log id "unlocking %s" file;
try
let s = input_line ic in
close_in ic;
if s = id then (
OpamGlobals.log id "unlocking %s" file;
Unix.unlink file;
) else
OpamGlobals.error_and_exit "cannot unlock %s (%s)" file s
with _ ->
OpamGlobals.error "%s is broken, removing it and continuing anyway ..." file;
close_in ic;
Unix.unlink file;
end else
OpamGlobals.error_and_exit "cannot unlock %s (%s)" file s
end else if Sys.file_exists (Filename.basename file) then
OpamGlobals.error_and_exit "Cannot find %s" file
) else
OpamGlobals.error "Cannot find %s, but continuing anyway..." file

let ocaml_version = lazy (
try
Expand Down

0 comments on commit 6e86353

Please sign in to comment.