]> matita.cs.unibo.it Git - helm.git/blobdiff - matitaB/matita/matitaFilesystem.ml
Matitaweb: more changes to file selection dialog box.
[helm.git] / matitaB / matita / matitaFilesystem.ml
index 798f7f67d03555ddd4a49d109c47a62d0b7956cd..b6a26f98bf5cb89d85ed722c6e3e682df50a9a78 100644 (file)
 
 exception SvnError of string;;
 
+let mutex = Mutex.create ();;
+
+let to_be_committed = ref [];;
+
 let exec_process cmd =
   let (stdout, stdin, stderr) as chs = Unix.open_process_full cmd [||] in
   let outlines = ref [] in
@@ -48,6 +52,8 @@ let exec_process cmd =
         errno, output ^ "\n\n" ^ errors
      | _ -> assert false))
 
+(* this should be executed only for a freshly created user
+ * so no CS is needed *)
 let checkout user =
   let rt_dir = Helm_registry.get "matita.rt_base_dir" in
   let repo = Helm_registry.get "matita.weblib" in
@@ -64,20 +70,20 @@ let html_of_library uid =
 
   let basedir = (Helm_registry.get "matita.rt_base_dir") ^ "/users/" ^ uid in
 
-  let branch text acc =
+  let branch lpath children =
     let id = newid () in
-    let name = Filename.basename text in
+    let name = Filename.basename lpath in
     let name = if name <> "." then name else "cic:/matita" in
-    "<span class=\"trigger\" onClick=\"showBranch('" ^ id ^ "')\">\n" ^
+    "<span class=\"trigger\" onClick=\"showBranch('" ^ id ^ "','" ^ lpath ^ "/')\">\n" ^
     "<img src=\"treeview/closed.gif\" id=\"I" ^ id ^ "\"/>\n" ^
     name ^ "<br/></span>\n" ^
     "<span class=\"branch\" id=\"" ^ id ^ "\">\n" ^
-    acc ^ "\n</span>"
+    children ^ "\n</span>"
   in
-  let leaf text =
+  let leaf lpath =
     "<img src=\"treeview/doc.gif\"/>\n" ^
-    "<a href=\"javascript:retrieveFile('" ^ text ^ "')\">" ^ 
-     (Filename.basename text) ^ "</a><br/>"
+    "<a href=\"javascript:void(0)\" onClick=\"selectFile('" ^ lpath ^ "')\" onDblClick=\"retrieveFile('" ^ lpath ^ "')\">" ^ 
+     (Filename.basename lpath) ^ "</a><br/>"
   in
 
   let rec aux path =
@@ -99,7 +105,7 @@ let html_of_library uid =
       String.concat "\n" (List.map (fun x -> aux (lpath x)) subdirs) in
     let scripttags =
       String.concat "\n" 
-       (List.map (fun x -> leaf (gpath x)) scripts)
+       (List.map (fun x -> leaf (lpath x)) scripts)
     in
     branch path (subdirtags ^ "\n" ^ scripttags)
   in
@@ -108,3 +114,44 @@ let html_of_library uid =
   prerr_endline "BEGIN TREE";prerr_endline res;prerr_endline "END TREE";
   res
 ;;
+
+let reset_lib () =
+  let to_be_removed = (Helm_registry.get "matita.rt_base_dir") ^ "/users/*" in
+  ignore (Sys.command ("rm -rf " ^ to_be_removed))
+;;
+
+(* adds a user to the commit queue; concurrent instances possible, so we
+ * enclose the update in a CS
+ *)
+let add_user uid =
+  Mutex.lock mutex;
+  to_be_committed := uid::List.filter (fun x -> x <> uid) !to_be_committed;
+  Mutex.unlock mutex;
+;;
+
+(* this function and the next one should only be called by the server itself (or
+ * the admin) at a scheduled time, so no concurrent instances and no CS needed
+ * also, svn should already be safe as far as concurrency is concerned *)
+let commit user =
+  let rt_dir = Helm_registry.get "matita.rt_base_dir" in
+  let repo = Helm_registry.get "matita.weblib" in
+
+  let errno, outstr = exec_process 
+    ("svn ci --message \"commit by user " ^ user ^ "\" " ^ rt_dir ^ "/users/" ^ user ^ "/")
+  in
+  if errno = 0 then ()
+  else raise (SvnError outstr)
+
+let do_global_commit () =
+  prerr_endline ("to be committed: " ^ String.concat " " !to_be_committed);
+  List.fold_left
+    (fun acc u ->
+       try
+         commit u;
+         acc
+       with
+       | SvnError outstr -> 
+           prerr_endline outstr;
+           u::acc)
+  [] (List.rev !to_be_committed)
+;;