# # # patch "automate.ml" # from [62bef3827396107a9fb8c65ac340cfda00abe7a0] # to [81cd3139b4ac5a13091737bf47b0c2e1b62eea62] # ============================================================ --- automate.ml 62bef3827396107a9fb8c65ac340cfda00abe7a0 +++ automate.ml 81cd3139b4ac5a13091737bf47b0c2e1b62eea62 @@ -407,20 +407,20 @@ let spawn mtn db = chunks = [] ; exit_cb = (fun _ -> assert false) } in - let head = String.create 4096 in - while not (String.contains head '\n') do - match Giochannel.read_chars p.p_out.out_w.w_chan head with - | `NORMAL read -> () + let rec check_version buf = + if String.contains buf '\n' then + String.length buf >= 18 && String.sub buf 0 18 = "format-version: 2\n" + else + match Giochannel.read_chars p.p_out.out_w.w_chan p.p_out.out_sb with + | `NORMAL read -> check_version (buf ^ String.sub p.p_out.out_sb 0 read) | `EOF -> Giochannel.shutdown p.p_out.out_w.w_chan false; Giochannel.shutdown p.p_err.out_w.w_chan false; failwith "mtn version 0.46 or above is required"; - | `AGAIN -> () - done; - let accept = - String.length head > 18 && String.sub head 0 18 = "format-version: 2\n" + | `AGAIN -> check_version buf in - if not accept then failwith "mtn stdio uses an unknown format-version"; + if not (check_version "") + then failwith "mtn stdio uses an unknown format-version"; let pid = some child.Gspawn.pid in ignore (Gspawn.add_child_watch ~prio:50 pid (reap_cb p pid)) ; p.p_out.out_cb <- out_cb p ;