this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 80 lines 2.9 kB view raw
1type doc_entry = { 2 pkg : OpamPackage.t; 3 html_path : Fpath.t; 4 universe : string; 5 blessed : bool; 6} 7 8let scan_cache ~os_dir = 9 let layers = Day11_layer.Scan.list_layers os_dir in 10 List.filter_map (fun (name, path) -> 11 if not (Astring.String.is_prefix ~affix:"doc-" name) 12 || Astring.String.is_prefix ~affix:"doc-driver-" name 13 || Astring.String.is_prefix ~affix:"doc-odoc-" name then 14 None 15 else 16 let json_path = Fpath.(path / "layer.json") in 17 match 18 try Some (Yojson.Safe.from_file (Fpath.to_string json_path)) 19 with _ -> None 20 with 21 | None -> None 22 | Some json -> 23 try 24 let open Yojson.Safe.Util in 25 let pkg_str = json |> member "package" |> to_string in 26 let pkg = OpamPackage.of_string pkg_str in 27 let doc = json |> member "doc" in 28 let status = doc |> member "status" |> to_string in 29 if status <> "success" then None 30 else 31 let html_path = doc |> member "html_path" |> to_string in 32 let blessed = doc |> member "blessed" |> to_bool in 33 let dep_hashes = 34 json |> member "dep_doc_hashes" 35 |> to_list |> List.map to_string in 36 let universe = Command.compute_universe_hash dep_hashes in 37 Some { pkg; html_path = Fpath.v html_path; universe; blessed } 38 with _ -> None 39 ) layers 40 41let sync env ~entries ~destination ?(blessed_only = false) 42 ?(package_filter = fun _ -> true) ?(dry_run = false) () = 43 let filtered = 44 entries 45 |> List.filter (fun e -> 46 (not blessed_only || e.blessed) 47 && package_filter (OpamPackage.to_string e.pkg)) 48 in 49 let results = 50 List.map (fun entry -> 51 let src = Fpath.to_string entry.html_path ^ "/" in 52 let dst_subpath = 53 if entry.blessed then 54 Printf.sprintf "%s/%s/" 55 (OpamPackage.name_to_string entry.pkg) 56 (OpamPackage.version_to_string entry.pkg) 57 else 58 Printf.sprintf "universes/%s/%s/%s/" 59 entry.universe 60 (OpamPackage.name_to_string entry.pkg) 61 (OpamPackage.version_to_string entry.pkg) 62 in 63 let dst = destination ^ "/" ^ dst_subpath in 64 let cmd = 65 Bos.Cmd.(v "rsync" % "-av" 66 %% (if dry_run then Bos.Cmd.v "--dry-run" else Bos.Cmd.empty) 67 % "--delete" % src % dst) 68 in 69 match Day11_exec.Run.run env cmd None with 70 | run when run.Day11_exec.Run.status = `Exited 0 -> Ok () 71 | run -> 72 Rresult.R.error_msgf "rsync failed for %s: %s" 73 (OpamPackage.to_string entry.pkg) run.errors 74 | exception exn -> 75 Rresult.R.error_msgf "rsync: %s" (Printexc.to_string exn) 76 ) filtered 77 in 78 match List.find_opt Result.is_error results with 79 | Some (Error _ as e) -> e 80 | _ -> Ok ()