Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
opamHTTP.ml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123(**************************************************************************) (* *) (* Copyright 2012-2019 OCamlPro *) (* Copyright 2012 INRIA *) (* *) (* All rights reserved. This file is distributed under the terms of the *) (* GNU Lesser General Public License version 2.1, with the special *) (* exception on linking described in the file LICENSE. *) (* *) (**************************************************************************) open OpamTypes open OpamProcess.Job.Op let log msg = OpamConsole.log "CURL" msg let slog = OpamConsole.slog let index_archive_name = "index.tar.gz" let remote_index_archive url = OpamUrl.Op.(url / index_archive_name) let sync_state name repo_root url = OpamFilename.with_tmp_dir_job @@ fun dir -> let local_index_archive = OpamRepositoryRoot.Tgz.of_file OpamFilename.Op.(dir // index_archive_name) in OpamRepositoryRoot.Tgz.download_as ~quiet:true ~overwrite:true (remote_index_archive url) local_index_archive @@+ fun () -> match repo_root with | OpamRepositoryRoot.Tgz repo_root -> OpamRepositoryRoot.Tgz.copy ~src:local_index_archive ~dst:repo_root; Done () | OpamRepositoryRoot.Dir repo_root -> List.iter OpamFilename.rmdir (OpamRepositoryRoot.Dir.dirs repo_root); OpamProcess.Job.with_text (Printf.sprintf "[%s: unpacking]" (OpamConsole.colorise `green (OpamRepositoryName.to_string name))) @@ OpamRepositoryRoot.extract_in_job local_index_archive repo_root @@+ function | None -> Done () | Some err -> raise err module B = struct let name = `http let fetch_repo_update repo_name ?cache_dir:_ repo_root url = log "pull-repo-update"; let quarantine = OpamRepositoryRoot.quarantine repo_root in OpamRepositoryRoot.make_empty quarantine; let finalise () = OpamRepositoryRoot.remove quarantine in OpamProcess.Job.catch (fun e -> finalise (); Done (OpamRepositoryBackend.Update_err e)) @@ fun () -> OpamRepositoryBackend.job_text repo_name "sync" (sync_state repo_name quarantine url) @@+ fun () -> if OpamRepositoryRoot.is_empty repo_root <> Some false then Done (OpamRepositoryBackend.Update_full quarantine) else OpamStd.Exn.finally finalise @@ fun () -> OpamRepositoryBackend.get_diff repo_root quarantine |> function | None -> Done OpamRepositoryBackend.Update_empty | Some patch -> Done (OpamRepositoryBackend.Update_patch patch) let repo_update_complete _ _ = Done () let pull_url ?full_fetch:_ ?cache_dir:_ ?subpath:_ dirname checksum remote_url = log "pull-file into %a: %a" (slog OpamFilename.Dir.to_string) dirname (slog OpamUrl.to_string) remote_url; OpamProcess.Job.catch (fun e -> OpamStd.Exn.fatal e; let s,l = let str = Printf.sprintf "%s (%s)" (OpamUrl.to_string remote_url) in match e with | OpamDownload.Download_fail (s,l) -> s, str l | _ -> Some "Download failed", str "download failed" in Done (Not_available (s,l))) @@ fun () -> OpamDownload.download ~quiet:true ~overwrite:true ?checksum remote_url dirname @@+ fun local_file -> Done (Result (Some local_file)) let revision _ = Done None let sync_dirty ?subpath:_ dir url = pull_url dir None url (* do not propagate *) let get_remote_url ?hash:_ _ = Done None end (* Helper functions used by opam-admin *) let make_index_tar_gz repo_root = let open OpamRepositoryRoot.Dir.Op in let files_to_include = [ "version"; OpamRepositoryPathName.repo_f; ] in let dirs_to_include = [ OpamRepositoryPathName.packages_d; ] in let filtered = List.filter (fun i -> OpamFilename.exists (repo_root // i)) files_to_include @ List.filter (fun i -> OpamFilename.exists_dir (repo_root / i)) dirs_to_include in match filtered with | [] -> () | d -> OpamSystem.command ("tar" :: "czhf" :: "index.tar.gz" :: "-C" :: OpamRepositoryRoot.Dir.to_string repo_root :: "--exclude=.git*" :: d)