Module OpamSystem
Bindings of lots of filesystem and system operations
exception
Process_error of OpamProcess.result
Exception raised when subprocess fails
val process_error : OpamProcess.result -> 'a
raise
Process_error
val raise_on_process_error : OpamProcess.result -> unit
raise
Process_error
if the process didn't return 0
val internal_error : ('a, unit, string, 'b) Stdlib.format4 -> 'a
Raise
Internal_error
val with_tmp_dir_job : (string -> 'a OpamProcess.job) -> 'a OpamProcess.job
Runs a job with a temp dir that is cleaned up afterwards
val verbose_for_base_commands : unit -> bool
Returns true if the default verbose level for base commands (cp, mv, etc.) is reached
val mk_temp_dir : ?prefix:string -> unit -> string
Returns a directory name, in the temporary directory, composed by opam (if
prefix
is not set), pid, and random number.
val copy_file : string -> string -> unit
copy_file src dst
copiessrc
todst
. Removedst
before the copy if it is a link.
val copy_dir : string -> string -> unit
copy_dir src dst
copies the contents of directorysrc
into directorydst
, creating it if necessary, merging directory contents and ovewriting files otherwise
val mv : string -> string -> unit
val install : ?exec:bool -> string -> string -> unit
install ?exec src dst
copies filesrc
as filedst
usinginstall
. Ifexec
, make the resulting file executable (otherwise, look at the permissions of the original file to decide).
val is_exec : string -> bool
Checks if a file is an executable (regular file with execution permission)
val file_is_empty : string -> bool
val link : string -> string -> unit
link src dst
linkssrc
todst
. Removedst
if it is a file, not a directory.
val real_path : string -> string
real_path p
returns the real path associated top
:..
are expanded and relative paths become absolute.
val string_of_channel : Stdlib.in_channel -> string
Return the contents of a channel.
exception
File_not_found of string
Raised when a file or directory can't be accessed (doesn't exist, bad permissions, etc.)
val read : string -> string
read filename
returns the contents offilename
(while taking an advisory read lock to prevent concurrent writes)
val write : string -> string -> unit
write filename contents
writecontents
tofilename
(while taking an advisory write lock to prevent concurrent reads or writes)
val remove : string -> unit
remove filename
removesfilename
. Works whetherfilename
is a file or a directory
val remove_file : string -> unit
remove_file filename
removesfilename
. Works only for normal files (or also at least for symlinks)
val remove_dir : string -> unit
remove_dir filename
removesfilename
. Works only for directory (not for symlinks or other files).
val ls : string -> string list
Returns the list of files and directories in the given directory (full names)
val files_with_links : string -> string list
files_with_links dir
returns the files in the directorydir
. Links simulating directory are ignored, others links are returned.
val rec_files : string -> string list
rec_files dir
returns the list of all files indir
, recursively. Links behaving like directory are crossed.
val rec_dirs : string -> string list
rec_dirs dir
return the list list of all directories recursively (going through symbolink links).
val dir_is_empty : string -> bool
val directories_with_links : string -> string list
directories_with_links dir
returns 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.command
Make 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).name
is used for naming log files.text
is what is displayed in the status line for this command. May raise Command_not_found, unlessresolve_path
is 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 option
Test 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 -> unit
command cmd
executes the commandcmd
in the correct OPAM environment.
val commands : ?verbose:bool -> ?env:string array -> ?name:string -> ?metadata:(string * string) list -> ?keep_going:bool -> command list -> unit
commands cmds
executes the commandscmds
in the correct OPAM environment. It stops whenever one command fails unlesskeep_going
is 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 list
read_command_output cmd
executes the commandcmd
in 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 -> unit
extract ~dir:dirname filename
extracts the archivefilename
intodirname
.dirname
should not exists andfilename
should contain only one top-level directory.
val extract_job : dir:string -> string -> exn option OpamProcess.job
Same as
extract
, but as an OpamProcess.job
val extract_in : dir:string -> string -> unit
extract_in ~dir:dirname filename
extracts the archivefilename
intodirname
.
val extract_in_job : dir:string -> string -> exn option OpamProcess.job
extract_in_job
is 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 : lock
Dummy lock
val release_all_locks : unit -> unit
Force 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 -> lock
Acquires a lock on the given file. Raises
Locked
if the lock can't be acquired anddontblock
is set. RaisesOpamStd.Sys.Exit
ifsafe_mode
is 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 -> unit
Updates an existing lock to the given level. Raises the same exceptions as
flock
.
val funlock : lock -> unit
Releases an acquired lock (equivalent to
flock_update `Lock_none
)
val lock_max : lock_flag -> lock_flag -> lock_flag
Returns the highest of the two lock flags (with the order no lock < read lock < write lock)
val lock_isatleast : [< lock_flag ] -> lock -> bool
Returns true if the lock already has the lock_flag rights or more
val get_lock_fd : lock -> Unix.file_descr
Returns the underlying fd for the lock or raises Not_found for `No_lock
Misc
val patch : ?preprocess:bool -> dir:string -> string -> exn option OpamProcess.job
Apply a patch file in the current directory. If
preprocess
is 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 -> string
Create a temporary file in ~/.opam/logs/<name>XXX, if
dir
is not set. ?auto_clean controls whether the file is automatically deleted when opam terminates (default:true
).
val register_printer : unit -> unit
Registers an exception printer that adds some OPAM version info, and details on process and Unix errors