123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113(**************************************************************************)(* *)(* Copyright 2022 OCamlPro *)(* *)(* 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. *)(* *)(**************************************************************************)moduleSWHO=Swhid_core.ObjectmoduleSWH_ID=SWHO.Core_identifiermoduleSWH_Compute=Swhid_core.Computetypet=SWH_ID.tletcompare=SWH_ID.compareletequalab=compareab=0letof_string_opts=matchSWH_ID.of_stringswith|Oki->Somei|Error_->Noneletof_strings=matchof_string_optswith|None->invalid_arg"OpamSWHSWH_ID.of_string"|Somei->iletto_string=SWH_ID.to_stringletto_jsons=`String(to_strings)letof_json=function|`Strings->of_string_opts|_->Nonelethashs=SWHO.Hash.to_string(SWH_ID.get_hashs)moduleO=structtypenonrect=tletto_string=to_stringletto_json=to_jsonletof_json=of_jsonletcompare=SWH_ID.compareendmoduleSet=OpamStd.Set.Make(O)moduleMap=OpamStd.Map.Make(O)(** Url handling *)letprefix="swhid.opam.ocaml.org/"letis_validurl=letopenOpamUrlinurl.backend=`http&&(String.equalurl.transport"http"||String.equalurl.transport"https")&&OpamStd.String.starts_with~prefixurl.pathletof_urlurl=trySome(of_string(OpamStd.String.remove_prefix~prefixurl.OpamUrl.path))withInvalid_argument_->Noneletto_urlswh=letpath=Printf.sprintf"%s%s"prefix(to_stringswh)inOpamUrl.{transport="https";backend=`http;hash=None;path}(** Identifier computing *)moduleSHA1=structletdigest_string_to_hex=OpamSHA.sha1_stringendmoduleOS=structletcontentsdir=trySome(OpamSystem.lsdir)with_->Nonelettypname=trySome(ifSys.is_directorynamethenSWH_Compute.DirelseSWH_Compute.File)with_->Noneletread_filename=trySome(OpamSystem.readname)withOpamSystem.File_not_found_->None(*
- [0o120000] if [f] is a symlink
- [0o040000] if [f] is a directory
- [0o100755] if [f] is an executable file
- [0o100644] if [f] is a regular file *)letpermissionsname=ifnot(Sys.file_existsname)thenraiseNot_foundelselet{Unix.st_kind;_}=Unix.lstatnameinmatchst_kindwith|Unix.S_DIR->Some0o040000|Unix.S_LNK->Some0o120000|Unix.S_REG->Some(ifOpamSystem.is_execnamethen0o100755else0o100644)|Unix.S_CHR|Unix.S_BLK|Unix.S_FIFO|Unix.S_SOCK->Noneletbasename=OpamFilename.(Base.to_string(basename(of_stringname)))endmoduleCompute=SWH_Compute.Make(SHA1)(OS)letcomputedir=matchCompute.directory_identifier_deep(OpamFilename.Dir.to_stringdir)with|Error_->None|Okidentifier->Some(SWHO.Hash.to_string(SWHO.get_hashidentifier))