Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file fs_tree.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 DaiLambda, Inc. <contact@dailambda.jp> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openResult_lwt.SyntaxopenResult_lwt.InfixmoduletypeNAME=Fs_intf.NAMEmoduletypePATH=Fs_intf.PATHmoduleMake(Base:Fs_intf.BASE)=structmoduleName=Base.NamemodulePath=Base.PathmoduleFsError=Base.FsErrormoduleFSC=Fs_impl.Make(Base)openFSCtypename=Name.ttyperaw_cursor=Cursor.ttypetree=FSC.cursortypecursor=FSC.cursortypeview=Node_type.viewtypehash=Hash.Prefix.ttypeerror=FsError.tletmake=FSC.makeletempty=FSC.emptyletcontext=FSC.contextletget_raw_cursor=FSC.get_raw_cursorletrelativepathc=letcpath=List.revc.rev_pathinletrecloopcpathpath=matchcpath,pathwith|cn::cpath',n::path'->ifName.equalcnnthenloopcpath'path'elseList.lengthcpath,path|_->List.lengthcpath,pathinloopcpathpathletof_cursorc=cletto_cursorc=cmoduleOp=structincludeOp.Monadletlift_result=funrc->Result.map(funx->(c,x))rletcheck_tree_invariant=Op.check_cursor_invariantletfail=FSC.Op.failletraw_cursor=FSC.Op.raw_cursorletdo_then=FSC.Op.do_thenletrun=FSC.Op.runletrecchdir_parentsnc=matchnwith|0->Okc|n->Op.chdir_parentc>>?fun(c,())->chdir_parents(n-1)cletwith_movepathf=func->letups,path=relativepathcinchdir_parentsupsc>>?fpathletwith_move'pathf=func->letpath,n=splitpathinletups,path=relativepathcinchdir_parentsupsc>>?f(path@[n])letgetpathc=with_movepathOp.Loose.getc>|?fun(c,(c',v))->(c,({c'withrev_path=[]},v))letget_tree=getletcatpath=with_movepathOp.Loose.catletwritepathvalue=with_move'path@@funpath->Op.Loose.writepathvaluelet_unlinkpathcheck=with_move'path@@funpath->Op.Loose.unlinkpathcheckletsetpathc'=with_move'path@@funpath->Op.Loose.setpathc'letset_treepathtreec=Op.chdir_roottree>>?fun(tree,())->setpathtreecletcopyfromto_:unitt=func->getfromc>>?fun(c,(c_from,_v_from))->setto_c_fromcletrm?recursive?ignore_errorpath=with_move'path@@Op.Loose.rm?recursive?ignore_errorletrmdir?ignore_errorpath=with_move'path@@Op.Loose.rmdir?ignore_errorletcompute_hashpath=with_movepath@@funpathc->Op.Loose.seekpathc>>?fun(c,_v)->letcur,h=Cursor.compute_hashc.curinlethp=fsthinassert(sndh="");Ok({cwithcur},hp)letmay_forgetpath=with_movepath@@funpathc->Op.Loose.seekpathc>>?fun(c,_v)->letcur=matchCursor.may_forgetc.curwith|Somecur->cur|None->c.curinOk({cwithcur},())letcursorc=Ok(c,c)endmoduleOp_lwt=structincludeFSC.Op_lwt.Monadletlift=FSC.Op_lwt.liftletlift_op=FSC.Op_lwt.lift_opletlift_lwt=FSC.Op_lwt.lift_lwtletlift_result=FSC.Op_lwt.lift_resultletlift_result_lwt=FSC.Op_lwt.lift_result_lwtletfaile=lift(Op.faile)letraw_cursor=liftOp.raw_cursorletcopyfromto_=lift(Op.copyfromto_)letcatpath=lift(Op.catpath)letwritepathvalue=lift(Op.writepathvalue)letrm?recursive?ignore_errorpath=lift(Op.rm?recursive?ignore_errorpath)letrmdir?ignore_errorpath=lift(Op.rmdir?ignore_errorpath)letcompute_hashpath=lift@@Op.compute_hashpathletmay_forgetpath=lift@@Op.may_forgetpathletdo_thenfgc=fc;gcletget_treep=lift@@Op.get_treepletset_treept=lift@@Op.set_treeptletcursor=liftOp.cursorletrun=FSC.Op_lwt.runletat_dirnamepath(f:_t):_t=func->matchOp.getpathcwith|Error_ase->Lwt.returne|Ok(c,(_c,v))->matchvwith|Leaf_->Lwt.return@@FsError.error(Is_file(name,path))|Bud_->fc|Internal_|Extender_->assertfalseletfoldinitpathf:_t=at_dir"fold"path(Op_lwt.fold_hereinit(funapathc->fapath{cwithrev_path=[]}))letfold'?depthinitpathfc=at_dir"fold'"path(Op_lwt.fold'_here?depthinit(funapathc->fapath{cwithrev_path=[]}))c(* We assume that Buds and directories correspond with each other *)letls=funpath0c->letfapathtree=matchpathwith|[]|_::_::_->assertfalse|[name]->Lwt.return@@Ok((name,{treewithrev_path=[]})::a)infold'~depth:(`Eq1)[]path0fcendmoduleMerkle_proof=structtypet=FSC.Merkle_proof.ttypedetail=Path.t*Segment.segmentlist*Node_type.nodeoptionletencoding=FSC.Merkle_proof.encodingletcheck=FSC.Merkle_proof.checkletpp=FSC.Merkle_proof.ppletmakefrompathsc=FSC.Op.Loose.seekfromc>>?fun({cur;_}asc,_)->letCursor.Cursor(_,n,ctxt,_)=curinletproof,details=Plebeia__Merkle_proof.makectxtn(List.mapPath.to_segmentspaths)inlet+?details=FSC.Merkle_proof.convert_detailsdetailsin(c,(proof,details))endmoduleVc=FSC.Vcend