Module OpamFilename
Higher 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.
val rmdir_cleanup : Dir.t -> unitRemoves an empty directory, as well as any empty leading path components
val mkdir : Dir.t -> unitCreate a directory
val dir_is_empty : Dir.t -> boolval dirs : Dir.t -> Dir.t listList the sub-directory (do not recurse)
val in_dir : Dir.t -> (unit -> 'a) -> 'aEvaluate a function in a given directory
val env_of_list : (string * string) list -> string arrayTurns 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
val copy_dir : src:Dir.t -> dst:Dir.t -> unitCopy directory
srctodst, that is, recursively copy the contents ofsrcintodst, overwriting any existing files.
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
include OpamStd.ABSTRACT
val of_string : string -> tval to_string : t -> stringval to_json : t -> OpamJson.t
module Set : OpamStd.SET with type elt = tmodule Map : OpamStd.MAP with type key = tval of_basename : Base.t -> 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:
- replace /path/to/opam/foo by <opam>/foo
- replace /path/to/home/foo by ~/foo
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_out : t -> Stdlib.out_channelval remove : t -> unitRemoves everything in
filenameif existed.
val write : t -> string -> unitRemoves everything in
filenameif existed, then writecontentsinstead.
val exists : t -> boolReturns true if the file exists and is a regular file or a symlink to one
val opt_file : t -> t optionReturns the argument as option if it exists and is either a regular file or a symlink to one
val check_suffix : t -> string -> boolCheck whether a file has a given suffix
val with_contents : (string -> 'a) -> t -> 'aApply a function on the contents of a file
val copy_in : ?root:Dir.t -> t -> Dir.t -> unitCopy a file in a directory. If
rootis 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 install : ?exec:bool -> src:t -> dst:t -> unit -> unitInstalls a file to a destination. Optionnally set if the destination should be set executable
val link : ?relative:bool -> target:t -> link:t -> unitSymlink 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)
val extract : t -> Dir.t -> unitExtract an archive in a given directory (it rewrites the root to match
Dir.tdir 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 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
val dir_starts_with : Dir.t -> Dir.t -> booldir starts_with pfx dirCheck whetherdirstarts withpfx
val dir_ends_with : string -> Dir.t -> boolCheck whether a dirname ends with a given suffix
val remove_prefix_dir : Dir.t -> Dir.t -> stringval remove_suffix : Base.t -> t -> stringRemove a suffix from a filename
val patch : ?preprocess:bool -> t -> Dir.t -> exn option OpamProcess.jobApply a patch in a directory. If
preprocessis set to false, there is no CRLF translation. ReturnsNoneon success, the process error otherwise
val touch : t -> unitCreate an empty file
val chmod : t -> int -> unitChange file permissions
val find_in_parents : (Dir.t -> bool) -> Dir.t -> Dir.t optionReturns the closest parent of a directory (including itself) for which the predicate holds, if any
Locking
val flock : [< OpamSystem.lock_flag ] -> ?dontblock:bool -> t -> OpamSystem.lockSee
OpamSystem.flock. Prefer the higher levelwith_flockfunctions when possible
val with_flock : [< OpamSystem.lock_flag ] -> ?dontblock:bool -> t -> (Unix.file_descr -> 'a) -> 'aCalls
fwhile holding a lock file. Ensures the lock is properly released onfexit. RaisesOpamSystem.Lockedifdontblockis set and the lock can't be acquired.fis passed the file_descr of the lock.
val with_flock_upgrade : [< OpamSystem.actual_lock_flag ] -> ?dontblock:bool -> OpamSystem.lock -> (Unix.file_descr -> 'a) -> 'aCalls
fwith the file lock upgraded to at leastflag, then restores the previous lock level. Upgrade to`Lock_writeshould never be used in blocking mode as it would deadlock. RaisesOpamSystem.Locked(but keeps the lock as is) ifdontblockis set and the lock can't be upgraded.
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 hanle file attributes
val to_attribute : Dir.t -> t -> Attribute.tConvert a filename to an attribute, relatively to a root