OpamFilenameHigher level file and directory name manipulation AND file operations, wrappers on OpamSystem using the filename type
module Base : sig ... endBasenames
module Dir : OpamStd.ABSTRACTDirectory names
val cwd : unit -> Dir.tReturn the current working directory
val rmdir : Dir.t -> unitRemove a directory
val cleandir : Dir.t -> unitCleans the contents of a directory, but keeps the directory in place. Noop if directory doesn't exists.
val rmdir_cleanup : Dir.t -> unitRemoves an empty directory, as well as any empty leading path components. Must be called only on a directory that is known to not have empty parents, only internal opam directory (and not tmp dir).
val mkdir : Dir.t -> unitCreate a directory
val dir_is_empty : Dir.t -> bool optionReturns whether a directory is empty. Returns None if the directory could not be found.
val in_dir : Dir.t -> (unit -> 'a) -> 'aEvaluate a function in a given directory
Turns an assoc list into an array suitable to be provided as environment
val exec :
Dir.t ->
?env:(string * string) list ->
?name:string ->
?metadata:(string * string) list ->
?keep_going:bool ->
string list list ->
unitExecute a list of commands in a given directory
Copy directory src to dst, that is, recursively copy the contents of src into dst, overwriting any existing files.
Same as copy_dir except it avoids copying VCS directories (.git, .hg, _darcs)
val exists_dir : Dir.t -> boolDoes the directory exist?
val raw_dir : string -> Dir.tCreation from a raw string, without resolving symlinks etc.
val with_tmp_dir : (Dir.t -> 'a) -> 'aExecute a function in a temp directory
val with_tmp_dir_job : (Dir.t -> 'a OpamProcess.job) -> 'a OpamProcess.jobProvide an automatically cleaned up temp directory to a job
val mk_tmp_dir : unit -> Dir.tRaw function to create a temporary directory. No automatic cleanup
include OpamStd.ABSTRACTval of_string : string -> tval to_string : t -> stringval to_json : t OpamJson.encoderval of_json : t OpamJson.decodermodule Set : OpamStd.SET with type elt = tmodule Map : OpamStd.MAP with type key = tCreate a file from a basename and the current working directory as dirname
val raw : string -> tCreation from a raw string, without resolving symlinks, etc.
val prettify : t -> stringPrettify a filename:
val prettify_dir : Dir.t -> stringPrettify a dirname.
val read : t -> stringRetrieves the contents from the hard disk.
val open_in : t -> Stdlib.in_channelOpen a channel from a given file.
val open_in_bin : t -> Stdlib.in_channelval open_out : t -> Stdlib.out_channelval open_out_bin : t -> Stdlib.out_channelval with_open_out_bin : t -> (Stdlib.out_channel -> unit) -> unitwith_open_out_bin filename f opens f and passes the out_channel to f. If f raises an exception, then filename is deleted and then exception is propagated. The out_channel does not have to be closed by f.
val with_open_out_bin_atomic : t -> (Stdlib.out_channel -> unit) -> unitwith_open_out_bin_atomic filename f opens f and passes the out_channel to f. If f raises an exception, then filename will be unaltered and then exception is propagated. The out_channel does not have to be closed by f.
val remove : t -> unitRemoves everything in filename if existed.
val write : t -> string -> unitRemoves everything in filename if existed, then write contents instead.
val exists : t -> boolReturns true if the file exists and is a regular file or a symlink to one
Returns the argument as option if it exists and is either a regular file or a symlink to one
val with_tmp_file : (t -> 'a) -> 'aExecute a function with a file in a temp directory. It is always cleaned up afterwards.
val with_tmp_file_job : (t -> 'a OpamProcess.job) -> 'a OpamProcess.jobProvide an automatically cleaned up file in temp directory to a job
val check_suffix : t -> string -> boolCheck whether a file has a given suffix
Returns alll the files, including dangling symlinks (which means that not all entries will satisfy exists).
val with_contents : (string -> 'a) -> t -> 'aApply a function on the contents of a file
Copy a file in a directory. If root is set, copy also the sub-directories. For instance, copy_in ~root:"/foo" "/foo/bar/gni"
"/toto" creates "/toto/bar/gni".
val is_symlink : t -> boolIs a symlink?
val is_symlink_dir : Dir.t -> boolval is_exec : t -> boolIs an executable?
val install :
?warning:OpamSystem.install_warning_fn ->
?exec:bool ->
src:t ->
dst:t ->
unit ->
unitInstalls a file to a destination. Optionally set if the destination should be set executable
Symlink a file. If symlink is not possible on the system, use copy instead. With relative, creates a relative link through the closest common ancestor directory if possible. Otherwise, the symlink is absolute.
val is_archive : t -> boolReturns true if the given file is an archive (zip or tar)
Extract an archive in a given directory (it rewrites the root to match Dir.t dir if needed)
val extract_job : t -> Dir.t -> exn option OpamProcess.jobSame as extract, as an OpamProcess.job
val extract_in_job : t -> Dir.t -> exn option OpamProcess.jobval make_tar_gz_job : t -> Dir.t -> exn option OpamProcess.jobval extract_generic_file : generic_file -> Dir.t -> unitExtract a generic file
val ends_with : string -> t -> boolCheck whether a filename ends with a given suffix
dir starts_with pfx dir Check whether dir starts with pfx
val dir_ends_with : string -> Dir.t -> boolCheck whether a dirname ends with a given suffix
val patch :
allow_unclean:bool ->
[ `Patch_file of t | `Patch_diffs of Patch.t list ] ->
Dir.t ->
(Patch.operation list, exn) Stdlib.resultpatch ~allow_unclean patch_source dir applies a patch to directory dir. The patch source can be either `Patch_file filename for a patch file, or `Patch_diffs diffs for a list of file-level changes.
parse_patch ~dir patch_file processes and parses a patch file. Returns the parsed patch diffs or raises an exception if the patch file doesn't exist or can't be parsed.
val touch : t -> unitCreate an empty file
val chmod : t -> int -> unitChange file permissions
val written_since : t -> floatReturns delay since last file update, based on mtime
Returns the closest parent of a directory (including itself) for which the predicate holds, if any
val flock :
[< OpamSystem.lock_flag ] ->
?dontblock:bool ->
t ->
OpamSystem.lockSee OpamSystem.flock. Prefer the higher level with_flock functions when possible
val with_flock :
[< OpamSystem.lock_flag ] ->
?dontblock:bool ->
t ->
(Unix.file_descr -> 'a) ->
'aCalls f while holding a lock file. Ensures the lock is properly released on f exit. f is passed the file_descr of the lock.
val with_flock_upgrade :
[< OpamSystem.actual_lock_flag ] ->
?dontblock:bool ->
OpamSystem.lock ->
(Unix.file_descr -> 'a) ->
'aCalls f with the file lock upgraded to at least flag, then restores the previous lock level. Upgrade to `Lock_write should never be used in blocking mode as it would deadlock.
val with_flock_write_then_read :
?dontblock:bool ->
t ->
(Unix.file_descr -> 'a) ->
('a -> 'b) ->
'bRuns first function with a write lock on the given file, then releases it to a read lock and runs the second function.
module Op : sig ... endmodule Attribute : sig ... endSimple structure to handle file attributes
module SubPath : sig ... endval to_attribute : Dir.t -> t -> Attribute.tConvert a filename to an attribute, relatively to a root