Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[opam <subcommand>] if subcommand is not "init", we add more checking…

… about the initial state.
  • Loading branch information...
commit 210a9b1aeca67b73c02506a1f077ebe67dc1e283 1 parent 1b06209
authored July 26, 2012

Showing 1 changed file with 31 additions and 24 deletions. Show diff stats Hide diff stats

  1. 55  src/client.ml
55  src/client.ml
@@ -186,8 +186,26 @@ let load_state () =
186 186
   print_state t;
187 187
   t
188 188
 
189  
-let check () =
190  
-  if not (Dirname.exists (Dirname.of_string !Globals.root_path)) then
  189
+type main_function = 
  190
+  | Read_only of (unit -> unit)
  191
+  | Write_lock of (unit -> unit)
  192
+
  193
+let check f =
  194
+  if Dirname.exists (Dirname.of_string !Globals.root_path) then
  195
+    match f with
  196
+    | Write_lock f -> Run.with_flock f
  197
+    | Read_only f ->
  198
+      let warn msg e = Globals.warning "%s: %s" msg (Printexc.to_string e) in
  199
+      try f () with e ->
  200
+        if
  201
+          None = try Some (current_ocaml_version (load_state ())) with e -> let () = warn "check" e in None
  202
+        then
  203
+          let () = warn "main" e in
  204
+          Globals.warning "initialization is not yet finished (or the state %s is inconsistent)" !Globals.root_path
  205
+          (* NOTE it is feasible to determine here if initialization is finished or not *)
  206
+        else
  207
+          raise e
  208
+  else
191 209
     Globals.error_and_exit
192 210
       "Cannot find %s. Have you run 'opam init first ?"
193 211
       !Globals.root_path
@@ -1759,45 +1777,34 @@ let switch clone alias ocaml_version =
1759 1777
 on some read/write data. *)
1760 1778
 
1761 1779
 let list print_short =
1762  
-  check ();
1763  
-  list print_short
  1780
+  check (Read_only (fun () -> list print_short))
1764 1781
 
1765 1782
 let info package =
1766  
-  check ();
1767  
-  info package
  1783
+  check (Read_only (fun () -> info package))
1768 1784
 
1769 1785
 let config request =
1770  
-  check ();
1771  
-  config request
  1786
+  check (Read_only (fun () -> config request))
1772 1787
 
1773 1788
 let install name =
1774  
-  check ();
1775  
-  Run.with_flock (fun () -> install name)
  1789
+  check (Write_lock (fun () -> install name))
1776 1790
 
1777 1791
 let update () =
1778  
-  check ();
1779  
-  Run.with_flock update
  1792
+  check (Write_lock update)
1780 1793
 
1781 1794
 let upgrade () =
1782  
-  check ();
1783  
-  Run.with_flock upgrade
  1795
+  check (Write_lock upgrade)
1784 1796
 
1785 1797
 let upload u r =
1786  
-  check ();
1787  
-  Run.with_flock (fun () -> upload u r)
  1798
+  check (Write_lock (fun () -> upload u r))
1788 1799
 
1789 1800
 let remove name =
1790  
-  check ();
1791  
-  Run.with_flock (fun () -> remove name)
  1801
+  check (Write_lock (fun () -> remove name))
1792 1802
 
1793 1803
 let remote action =
1794  
-  check ();
1795  
-  Run.with_flock (fun () -> remote action)
  1804
+  check (Write_lock (fun () -> remote action))
1796 1805
 
1797 1806
 let switch clone alias ocaml_version =
1798  
-  check ();
1799  
-  Run.with_flock (fun () -> switch clone alias ocaml_version)
  1807
+  check (Write_lock (fun () -> switch clone alias ocaml_version))
1800 1808
 
1801 1809
 let compiler_list () =
1802  
-  check ();
1803  
-  compiler_list ()
  1810
+  check (Read_only compiler_list)

0 notes on commit 210a9b1

Please sign in to comment.
Something went wrong with that request. Please try again.