X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matitaB%2Fmatita%2FmatitaFilesystem.ml;h=ffdf9bb0d1f7ca69e7f1d45fc10bcdd97295dafa;hb=acf77bb24694158a57444c7f32da46ceac8b30c4;hp=49091b2f5428cbd404cfbde0572999c147ea8d6e;hpb=8f694a82e3291e4a3c2a4f805782846204cf348c;p=helm.git diff --git a/matitaB/matita/matitaFilesystem.ml b/matitaB/matita/matitaFilesystem.ml index 49091b2f5..ffdf9bb0d 100644 --- a/matitaB/matita/matitaFilesystem.ml +++ b/matitaB/matita/matitaFilesystem.ml @@ -25,6 +25,10 @@ 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 @@ -113,3 +119,39 @@ 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) +;;