123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(**************************************************************************)(* *)(* 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. *)(* *)(**************************************************************************)openOpamTypesopenOpamStd.OpopenOpamProcess.Job.Opletlogmsg=OpamConsole.log"CURL"msgletslog=OpamConsole.slogletindex_archive_name="index.tar.gz"letremote_index_archiveurl=OpamUrl.Op.(url/index_archive_name)letsync_statenamedestdirurl=OpamFilename.with_tmp_dir_job@@fundir->letlocal_index_archive=OpamFilename.Op.(dir//index_archive_name)inOpamDownload.download_as~quiet:true~overwrite:true(remote_index_archiveurl)local_index_archive@@+fun()->List.iterOpamFilename.rmdir(OpamFilename.dirsdestdir);OpamProcess.Job.with_text(Printf.sprintf"[%s: unpacking]"(OpamConsole.colorise`green(OpamRepositoryName.to_stringname)))@@OpamFilename.extract_in_joblocal_index_archivedestdir@@+function|None->Done()|Someerr->raiseerrmoduleB=structletname=`httpletfetch_repo_updaterepo_name?cache_dir:_repo_rooturl=log"pull-repo-update";letquarantine=OpamFilename.Dir.(of_string(to_stringrepo_root^".new"))inOpamFilename.mkdirquarantine;letfinalise()=OpamFilename.rmdirquarantineinOpamProcess.Job.catch(fune->finalise();Done(OpamRepositoryBackend.Update_erre))@@fun()->OpamRepositoryBackend.job_textrepo_name"sync"(sync_staterepo_namequarantineurl)@@+fun()->ifnot(OpamFilename.exists_dirrepo_root)||OpamFilename.dir_is_emptyrepo_rootthenDone(OpamRepositoryBackend.Update_fullquarantine)elseOpamProcess.Job.finallyfinalise@@fun()->OpamRepositoryBackend.job_textrepo_name"diff"(OpamRepositoryBackend.get_diff(OpamFilename.dirname_dirrepo_root)(OpamFilename.basename_dirrepo_root)(OpamFilename.basename_dirquarantine))@@|function|None->OpamRepositoryBackend.Update_empty|Somepatch->OpamRepositoryBackend.Update_patchpatchletrepo_update_complete__=Done()letpull_url?cache_dir:_?subpath:_dirnamechecksumremote_url=log"pull-file into %a: %a"(slogOpamFilename.Dir.to_string)dirname(slogOpamUrl.to_string)remote_url;OpamProcess.Job.catch(fune->OpamStd.Exn.fatale;lets,l=letstr=Printf.sprintf"%s (%s)"(OpamUrl.to_stringremote_url)inmatchewith|OpamDownload.Download_fail(s,l)->s,strl|_->Some"Download failed",str"download failed"inDone(Not_available(s,l)))@@fun()->OpamDownload.download~quiet:true~overwrite:true?checksumremote_urldirname@@+funlocal_file->Done(Result(Somelocal_file))letrevision_=DoneNoneletsync_dirty?subpath:_dirurl=pull_urldirNoneurl(* do not propagate *)letget_remote_url?hash:__=DoneNoneend(* Helper functions used by opam-admin *)letmake_index_tar_gzrepo_root=OpamFilename.in_dirrepo_root(fun()->letto_include=["version";"packages";"repo"]inmatchList.filterSys.file_existsto_includewith|[]->()|d->OpamSystem.command("tar"::"czhf"::"index.tar.gz"::"--exclude=.git*"::d))