Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file fpath.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125letis_roott=Filename.dirnamet=tletinitial_cwd=Stdlib.Sys.getcwd()typemkdir_result=|Already_exists|Created|Missing_parent_directoryletmkdir?(perms=0o777)t_s=tryUnix.mkdirt_sperms;Createdwith|Unix.Unix_error(EEXIST,_,_)->Already_exists|Unix.Unix_error(ENOENT,_,_)->Missing_parent_directorytypemkdir_p_result=|Already_exists|Createdletrecmkdir_p?(perms=0o777)t_s=matchmkdir~permst_swith|Created->Created|Already_exists->Already_exists|Missing_parent_directory->(ifis_roott_sthenCode_error.raise"Impossible happened: [Fpath.mkdir] refused to create a directory at \
the root, allegedly because its parent was missing"[]elseletparent=Filename.dirnamet_sinmatchmkdir_p~permsparentwith|Created|Already_exists->(* The [Already_exists] case might happen if some other process managed
to create the parent directory concurrently. *)Unix.mkdirt_sperms;Created)letresolve_linkpath=matchUnix.readlinkpathwith|exceptionUnix.Unix_error(EINVAL,_,_)->OkNone|exceptionUnix.Unix_error(error,syscall,arg)->Error(Dune_filesystem_stubs.Unix_error.Detailed.create~syscall~argerror)|link->Ok(Some(ifFilename.is_relativelinkthenFilename.concat(Filename.dirnamepath)linkelselink))typefollow_symlink_error=|Not_a_symlink|Max_depth_exceeded|Unix_errorofDune_filesystem_stubs.Unix_error.Detailed.tletfollow_symlinkpath=letrecloopnpath=ifn=0thenErrorMax_depth_exceededelsematchresolve_linkpathwith|Errore->Error(Unix_errore)|OkNone->Okpath|Ok(Somepath)->loop(n-1)pathinmatchresolve_linkpathwith|OkNone->ErrorNot_a_symlink|Ok(Somep)->loop20p|Errore->Error(Unix_errore)letwin32_unlinkfn=tryUnix.unlinkfnwithUnix.Unix_error(Unix.EACCES,_,_)ase->(try(* Try removing the read-only attribute *)Unix.chmodfn0o666;Unix.unlinkfnwith_->raisee)letunlink=ifStdlib.Sys.win32thenwin32_unlinkelseUnix.unlinkletunlink_no_errt=tryunlinktwith_->()typeclear_dir_result=|Cleared|Directory_does_not_existletrecclear_dirdir=matchDune_filesystem_stubs.read_directory_with_kindsdirwith|Error(ENOENT,_,_)->Directory_does_not_exist|Error(error,_,_)->raise(Unix.Unix_error(error,dir,"Stdune.Path.rm_rf: read_directory_with_kinds"))|Oklisting->List.iterlisting~f:(fun(fn,kind)->letfn=Filename.concatdirfnin(* Note that by the time we reach this point, [fn] might have been
deleted by a concurrent process. Both [rm_rf_dir] and [unlink_no_err]
will tolerate such phantom paths and succeed. *)matchkindwith|Unix.S_DIR->rm_rf_dirfn|_->unlink_no_errfn);Clearedandrm_rf_dirpath=matchclear_dirpathwith|Directory_does_not_exist->()|Cleared->(matchUnix.rmdirpathwith|()->()|exceptionUnix.Unix_error(ENOENT,_,_)->(* How can we end up here? [clear_dir] cleared the directory successfully,
but by the time the above [Unix.rmdir] was called, another process
deleted the directory. *)())letrm_rf?(allow_external=false)fn=if(notallow_external)&¬(Filename.is_relativefn)thenCode_error.raise"Path.rm_rf called on external dir"[("fn",Stringfn)];matchUnix.lstatfnwith|exceptionUnix.Unix_error(ENOENT,_,_)->()|{Unix.st_kind=S_DIR;_}->rm_rf_dirfn|_->unlinkfn