Module OpamSystem
Bindings of lots of filesystem and system operations
exceptionProcess_error of OpamProcess.resultException raised when subprocess fails
val process_error : OpamProcess.result -> 'araise
Process_error
val raise_on_process_error : OpamProcess.result -> unitraise
Process_errorif the process didn't return 0
val internal_error : ('a, unit, string, 'b) Stdlib.format4 -> 'aRaise
Internal_error
val with_tmp_dir_job : (string -> 'a OpamProcess.job) -> 'a OpamProcess.jobRuns a job with a temp dir that is cleaned up afterwards
val verbose_for_base_commands : unit -> boolReturns true if the default verbose level for base commands (cp, mv, etc.) is reached
val mk_temp_dir : ?prefix:string -> unit -> stringReturns a directory name, in the temporary directory, composed by opam (if
prefixis not set), pid, and random number.
val copy_file : string -> string -> unitcopy_file src dstcopiessrctodst. Removedstbefore the copy if it is a link.
val copy_dir : string -> string -> unitcopy_dir src dstcopies the contents of directorysrcinto directorydst, creating it if necessary, merging directory contents and ovewriting files otherwise
val mv : string -> string -> unitval install : ?exec:bool -> string -> string -> unitinstall ?exec src dstcopies filesrcas filedstusinginstall. Ifexec, make the resulting file executable (otherwise, look at the permissions of the original file to decide).
val is_exec : string -> boolChecks if a file is an executable (regular file with execution permission)
val file_is_empty : string -> boolval link : string -> string -> unitlink src dstlinkssrctodst. Removedstif it is a file, not a directory.
val real_path : string -> stringreal_path preturns the real path associated top:..are expanded and relative paths become absolute.
val string_of_channel : Stdlib.in_channel -> stringReturn the contents of a channel.
exceptionFile_not_found of stringRaised when a file or directory can't be accessed (doesn't exist, bad permissions, etc.)
val read : string -> stringread filenamereturns the contents offilename(while taking an advisory read lock to prevent concurrent writes)
val write : string -> string -> unitwrite filename contentswritecontentstofilename(while taking an advisory write lock to prevent concurrent reads or writes)
val remove : string -> unitremove filenameremovesfilename. Works whetherfilenameis a file or a directory
val remove_file : string -> unitremove_file filenameremovesfilename. Works only for normal files (or also at least for symlinks)
val remove_dir : string -> unitremove_dir filenameremovesfilename. Works only for directory (not for symlinks or other files).
val ls : string -> string listReturns the list of files and directories in the given directory (full names)
val files_with_links : string -> string listfiles_with_links dirreturns the files in the directorydir. Links simulating directory are ignored, others links are returned.
val rec_files : string -> string listrec_files dirreturns the list of all files indir, recursively. Links behaving like directory are crossed.
val rec_dirs : string -> string listrec_dirs dirreturn the list list of all directories recursively (going through symbolink links).
val dir_is_empty : string -> boolval directories_with_links : string -> string listdirectories_with_links dirreturns the directories in the directorydir. Links pointing to directory are also returned.
val make_command : ?verbose:bool -> ?env:string array -> ?name:string -> ?text:string -> ?metadata:(string * string) list -> ?allow_stdin:bool -> ?stdout:string -> ?dir:string -> ?resolve_path:bool -> string -> string list -> OpamProcess.commandMake a comman suitable for OpamProcess.Job. if
verbose, is set, command and output will be displayed (at command end for the latter, if concurrent commands are running).nameis used for naming log files.textis what is displayed in the status line for this command. May raise Command_not_found, unlessresolve_pathis set to false (in which case you can end up with a process error instead)
val resolve_command : ?env:string array -> ?dir:string -> string -> string optionTest whether a command exists in the environment, and returns it (resolved if found in PATH)
val command : ?verbose:bool -> ?env:string array -> ?name:string -> ?metadata:(string * string) list -> ?allow_stdin:bool -> command -> unitcommand cmdexecutes the commandcmdin the correct OPAM environment.
val commands : ?verbose:bool -> ?env:string array -> ?name:string -> ?metadata:(string * string) list -> ?keep_going:bool -> command list -> unitcommands cmdsexecutes the commandscmdsin the correct OPAM environment. It stops whenever one command fails unlesskeep_goingis set totrue. In this case, the first error is re-raised at the end.
val read_command_output : ?verbose:bool -> ?env:string array -> ?metadata:(string * string) list -> ?allow_stdin:bool -> command -> string listread_command_output cmdexecutes the commandcmdin the correct OPAM environment and return the lines from stdout if the command exists normally. If the command does not exist or if the command exited with a non-empty exit-code, throw an error.
val extract : dir:string -> string -> unitextract ~dir:dirname filenameextracts the archivefilenameintodirname.dirnameshould not exists andfilenameshould contain only one top-level directory.
val extract_job : dir:string -> string -> exn option OpamProcess.jobSame as
extract, but as an OpamProcess.job
val extract_in : dir:string -> string -> unitextract_in ~dir:dirname filenameextracts the archivefilenameintodirname.
val extract_in_job : dir:string -> string -> exn option OpamProcess.jobextract_in_jobis similar toextract_in, but as a job
File locking function
type actual_lock_flag=[|`Lock_read|`Lock_write]The different kinds of unix advisory locks available (`Lock_none doesn't actually lock anything, or even create the lock file)
type lock_flag=[|`Lock_none|actual_lock_flag]
val lock_none : lockDummy lock
val release_all_locks : unit -> unitForce releases all open locks in the process. Required for Windows if an exception has been raised, since Windows doesn't permit unlinking while handles are open.
val flock : [< lock_flag ] -> ?dontblock:bool -> string -> lockAcquires a lock on the given file. Raises
Lockedif the lock can't be acquired anddontblockis set. RaisesOpamStd.Sys.Exitifsafe_modeis set and a write lock is required. Also raises Unix errors if the lock file can't be opened.
val flock_update : [< lock_flag ] -> ?dontblock:bool -> lock -> unitUpdates an existing lock to the given level. Raises the same exceptions as
flock.
val funlock : lock -> unitReleases an acquired lock (equivalent to
flock_update `Lock_none)
val lock_max : lock_flag -> lock_flag -> lock_flagReturns the highest of the two lock flags (with the order no lock < read lock < write lock)
val lock_isatleast : [< lock_flag ] -> lock -> boolReturns true if the lock already has the lock_flag rights or more
val get_lock_fd : lock -> Unix.file_descrReturns the underlying fd for the lock or raises Not_found for `No_lock
Misc
val patch : ?preprocess:bool -> dir:string -> string -> exn option OpamProcess.jobApply a patch file in the current directory. If
preprocessis set to false, there is no CRLF translation. Returns the error if the patch didn't apply.
val temp_file : ?auto_clean:bool -> ?dir:string -> string -> stringCreate a temporary file in ~/.opam/logs/<name>XXX, if
diris not set. ?auto_clean controls whether the file is automatically deleted when opam terminates (default:true).
val register_printer : unit -> unitRegisters an exception printer that adds some OPAM version info, and details on process and Unix errors