From ef23dc44fb01f7cb94df065c1288398e8f08d3ed Mon Sep 17 00:00:00 2001 From: Wilmer Ricciotti Date: Mon, 3 Oct 2011 10:53:01 +0000 Subject: [PATCH] Matitaweb: implementation of file-flagging for keeping track of modified files proceeds. --- matitaB/matita/matitaAuthentication.ml | 20 +++++++++----------- matitaB/matita/matitaAuthentication.mli | 3 ++- matitaB/matita/matitaFilesystem.ml | 24 +++++++++++++++++++----- matitaB/matita/matitaFilesystem.mli | 2 +- matitaB/matita/matitadaemon.ml | 4 +++- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/matitaB/matita/matitaAuthentication.ml b/matitaB/matita/matitaAuthentication.ml index 86189fddf..2d9b377ca 100644 --- a/matitaB/matita/matitaAuthentication.ml +++ b/matitaB/matita/matitaAuthentication.ml @@ -136,19 +136,17 @@ let read_ft uid = [] ;; -let set_file_flag uid filename flag = - let filename = MatitaFilesystem.normalize_qfn filename in +let set_file_flag uid files_flags = let ft = read_ft uid in - let oldflag = - try List.assoc filename ft - with Not_found -> MatitaFilesystem.MSynchronized + let files = List.map fst files_flags in + let ft = List.filter (fun (x,_) -> not (List.mem x files)) ft in + let ft' = List.fold_left (fun acc (filename,flag) -> + let filename = MatitaFilesystem.normalize_qfn filename in + try + (filename,HExtlib.unopt flag)::acc + with Failure _ -> acc) [] files_flags in - if oldflag <> MatitaFilesystem.MConflict - then - let ft = (filename,flag):: - List.filter (fun (fn,_) -> fn <> filename) ft in - write_ft uid ft - else () + write_ft uid (ft'@ft) ;; let add_user uid pw = diff --git a/matitaB/matita/matitaAuthentication.mli b/matitaB/matita/matitaAuthentication.mli index 8a832eb81..feb139837 100644 --- a/matitaB/matita/matitaAuthentication.mli +++ b/matitaB/matita/matitaAuthentication.mli @@ -55,7 +55,8 @@ val read_ft : string -> (string * MatitaFilesystem.matita_flag) list val write_ft : string -> (string * MatitaFilesystem.matita_flag) list -> unit -val set_file_flag : string -> string -> MatitaFilesystem.matita_flag -> unit +val set_file_flag : + string -> (string * MatitaFilesystem.matita_flag option) list -> unit val add_user : string -> string -> unit diff --git a/matitaB/matita/matitaFilesystem.ml b/matitaB/matita/matitaFilesystem.ml index 77e658221..637a997dc 100644 --- a/matitaB/matita/matitaFilesystem.ml +++ b/matitaB/matita/matitaFilesystem.ml @@ -122,10 +122,17 @@ let stat_user user = ;; (* update and checkout *) -let up_classify line = +let up_classify line uid = + let basedir = (Helm_registry.get "matita.rt_base_dir") ^ "/users/" ^ uid ^ "/" in let rec aux n acc = match (line.[n], n) with - | _, n when n = 4 -> String.sub line 5 ((String.length line) - 5), acc + | _, n when n = 4 -> + let fn = String.sub line 5 ((String.length line) - 5) in + let prefix_len = String.length basedir in + let fn_len = String.length fn in + if String.sub fn 0 prefix_len = basedir + then String.sub fn prefix_len (fn_len - prefix_len), acc + else fn, acc | ' ', _ -> aux (n+1) acc | 'A',_ when n = 0 || n = 1 -> aux (n+1) (Add::acc) | 'C',_ when n = 0 || n = 1 -> aux (n+1) (Conflict::acc) @@ -136,6 +143,12 @@ let up_classify line = | _ -> raise (SvnAnomaly line) in aux 0 [] +let matita_flag_of_update fs = + if List.mem Conflict fs then Some MConflict + else if List.mem Delete fs then None + else if List.mem Merge fs then Some MModified + else Some MSynchronized + (* 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 @@ -147,7 +160,7 @@ let checkout user = let files, anomalies = List.fold_left (fun (facc,eacc) line -> try - (up_classify line::facc), eacc + (up_classify line user::facc), eacc with | SvnAnomaly l -> facc, l::eacc) ([],[]) outlines in @@ -254,12 +267,13 @@ let update_user user = let repo = Helm_registry.get "matita.weblib" in let errno, outlines, errlines = exec_process - ("svn up " ^ rt_dir ^ "/users/" ^ user ^ "/") + ("svn up " ^ rt_dir ^ "/users/" ^ user ^ "/ --non-interactive") in let files, anomalies = List.fold_left (fun (facc,eacc) line -> try - (up_classify line::facc), eacc + (let fname,flags = up_classify line user in + (fname,matita_flag_of_update flags)::facc), eacc with | SvnAnomaly l -> facc, l::eacc) ([],[]) outlines in diff --git a/matitaB/matita/matitaFilesystem.mli b/matitaB/matita/matitaFilesystem.mli index 4d1bd50d8..13d900bed 100644 --- a/matitaB/matita/matitaFilesystem.mli +++ b/matitaB/matita/matitaFilesystem.mli @@ -30,7 +30,7 @@ val add_user : string -> unit val do_global_commit : unit -> string list -val update_user : string -> (string * svn_flag list) list * string list +val update_user : string -> (string * matita_flag option) list * string list val stat_user : string -> (string * svn_flag list) list * string list diff --git a/matitaB/matita/matitadaemon.ml b/matitaB/matita/matitadaemon.ml index fb75e6579..0253eabc2 100644 --- a/matitaB/matita/matitadaemon.ml +++ b/matitaB/matita/matitadaemon.ml @@ -384,7 +384,8 @@ let save (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = (* prerr_endline ("done."); *) end; end; - MatitaAuthentication.set_file_flag uid rel_filename MatitaFilesystem.MModified; + MatitaAuthentication.set_file_flag uid + [rel_filename, Some MatitaFilesystem.MModified]; cgi # set_header ~cache:`No_cache ~content_type:"text/xml; charset=\"utf-8\"" @@ -440,6 +441,7 @@ let svn_update (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = let changed = String.concat "\n" changed in let anomalies = String.concat "\n" anomalies in prerr_endline ("Changed:\n" ^ changed ^ "\n\nAnomalies:\n" ^ anomalies); *) + MatitaAuthentication.set_file_flag uid files; cgi # set_header ~cache:`No_cache ~content_type:"text/xml; charset=\"utf-8\"" -- 2.39.2