12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 Functori, <contact@functori.com> *)(* *)(* 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. *)(* *)(*****************************************************************************)typet=V0|V1|V2|V3|V4letppppfv=Format.pp_print_stringppf@@matchvwithV0->"v0"|V1->"v1"|V2->"v2"|V3->"v3"|V4->"v4"letencoding=letopenData_encodinginconv(functionV0->0|V1->1|V2->2|V3->3|V4->4)(function|0->V0|1->V1|2->V2|3->V3|4->V4|v->Format.ksprintfStdlib.failwith"Unsupported store version %d"v)(obj1(req"store_version"int31))letpath~dir=Filename.concatdir"version"letread_version_file~dir=letopenLwt_result_syntaxinprotect@@fun()->letfilename=path~dirinlet*!exists=Lwt_unix.file_existsfilenameinifnotexiststhenreturn_noneelselet*json=Lwt_utils_unix.Json.read_filefilenameinreturn_some(Data_encoding.Json.destructencodingjson)letwrite_version_file~dirversion=letopenLwt_result_syntaxinprotect@@fun()->letfilename=path~dirinlet*!()=Lwt_utils_unix.create_dirdirinletjson=Data_encoding.Json.constructencodingversioninLwt_utils_unix.Json.write_filefilenamejson