1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192openCoreopenImportmoduleUnix=Unix_syscallsletargv=(Sys.argv[@warning"-3"])letget_argv=Sys.get_argvletexecutable_name=Sys_unix.executable_nameletwrap1fx1=In_thread.run(fun()->fx1)letwrap2fx1x2=In_thread.run(fun()->fx1x2)letwhen_file_changes?(time_source=Time_source.wall_clock())?(poll_delay=sec0.5)file=letlast_reported_mtime=refNoneinletreader,writer=Pipe.create()inletrecloop()=Monitor.try_with~run:`Schedule~rest:`Log~extract_exn:true(fun()->Unix.statfile)>>>funstat_result->ifnot(Pipe.is_closedwriter)then((matchstat_resultwith|Errorexn->last_reported_mtime:=None;Pipe.write_without_pushbackwriter(Errorexn)|Okst->letmtime=st.mtimeinletshould_report=match!last_reported_mtimewith|None->true|Somelast_reported_mtime->not(Time.equalmtimelast_reported_mtime)inifshould_reportthen(last_reported_mtime:=Somemtime;Pipe.write_without_pushbackwriter(Okmtime)));Time_source.aftertime_source(Time_ns.Span.of_span_float_round_nearestpoll_delay)>>>loop)inloop();reader;;letchdir=wrap1Sys_unix.chdirletcommand=wrap1Sys_unix.commandletcommand_exn=wrap1Sys_unix.command_exnletquote=Sys.quoteletconcat_quoted=Sys.concat_quotedletgetcwd=wrap1Sys_unix.getcwdlethome_directory=wrap1Sys_unix.home_directoryletls_dir=wrap1Sys_unix.ls_dirletreaddir=wrap1Sys_unix.readdirletremove=wrap1Sys_unix.removeletrename=wrap2Sys_unix.renameletwrap_isf?follow_symlinkspath=In_thread.run(fun()->f?follow_symlinkspath)letfile_exists=wrap_isSys_unix.file_existsletfile_exists_exn=wrap_isSys_unix.file_exists_exnletwhen_file_exists?follow_symlinks?(poll_delay=sec0.5)file=Deferred.create(funi->letrecloop()=file_exists?follow_symlinksfile>>>function|`Yes->Ivar.filli()|`No->upon(Clock.afterpoll_delay)loop|`Unknown->raise_s[%message"when_file_exists can not check file"(file:string)]inloop());;letis_directory=wrap_isSys_unix.is_directoryletis_directory_exn=wrap_isSys_unix.is_directory_exnletis_file=wrap_isSys_unix.is_fileletis_file_exn=wrap_isSys_unix.is_file_exnletc_int_size=Sys_unix.c_int_sizeletexecution_mode=Sys_unix.execution_modeletgetenv=Sys.getenvletgetenv_exn=Sys.getenv_exnletint_size=Sys.int_size_in_bitsletinteractive=Sys.interactiveletocaml_version=Sys.ocaml_versionletos_type=Sys.os_typeletword_size=Sys.word_size_in_bitsletopaque_identity=Sys.opaque_identityletbig_endian=Sys.big_endian