package opam-core

  1. Overview
  2. Docs

doc/opam-core/OpamFilename/index.html

Module OpamFilenameSource

Higher level file and directory name manipulation AND file operations, wrappers on OpamSystem using the filename type

Sourceval might_escape : sep:[ `Unix | `Windows | `Unspecified ] -> string -> bool
Sourcemodule Base : sig ... end

Basenames

Directory names

Sourceval cwd : unit -> Dir.t

Return the current working directory

Sourceval rmdir : Dir.t -> unit

Remove a directory

Sourceval cleandir : Dir.t -> unit

Cleans the contents of a directory, but keeps the directory in place. Noop if directory doesn't exists.

Sourceval rmdir_cleanup : Dir.t -> unit

Removes 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).

Sourceval mkdir : Dir.t -> unit

Create a directory

Sourceval rec_dirs : Dir.t -> Dir.t list

List the sub-directory recursively

Sourceval dir_is_empty : Dir.t -> bool option

Returns whether a directory is empty. Returns None if the directory could not be found.

Sourceval dirs : Dir.t -> Dir.t list

List the sub-directory (do not recurse)

Sourceval in_dir : Dir.t -> (unit -> 'a) -> 'a

Evaluate a function in a given directory

Sourceval env_of_list : (string * string) list -> string array

Turns an assoc list into an array suitable to be provided as environment

Sourceval exec : Dir.t -> ?env:(string * string) list -> ?name:string -> ?metadata:(string * string) list -> ?keep_going:bool -> string list list -> unit

Execute a list of commands in a given directory

Sourceval move_dir : src:Dir.t -> dst:Dir.t -> unit

Move a directory

Sourceval copy_dir : src:Dir.t -> dst:Dir.t -> unit

Copy directory src to dst, that is, recursively copy the contents of src into dst, overwriting any existing files.

Sourceval copy_dir_except_vcs : src:Dir.t -> dst:Dir.t -> unit

Same as copy_dir except it avoids copying VCS directories (.git, .hg, _darcs)

Link a directory

Sourceval exists_dir : Dir.t -> bool

Does the directory exist?

Sourceval opt_dir : Dir.t -> Dir.t option

Returns the argument as option, if the directory exists

Sourceval dirname_dir : Dir.t -> Dir.t

Return the parent directory

Sourceval basename_dir : Dir.t -> Base.t

Return the deeper directory name

Sourceval to_list_dir : Dir.t -> Dir.t list

Turn a full path into a list of directory names

Sourceval raw_dir : string -> Dir.t

Creation from a raw string, without resolving symlinks etc.

Sourceval with_tmp_dir : (Dir.t -> 'a) -> 'a

Execute a function in a temp directory

Sourceval with_tmp_dir_job : (Dir.t -> 'a OpamProcess.job) -> 'a OpamProcess.job

Provide an automatically cleaned up temp directory to a job

Sourceval mk_tmp_dir : unit -> Dir.t

Raw function to create a temporary directory. No automatic cleanup

Sourceval concat_and_resolve : Dir.t -> string -> Dir.t

Create a new Dir.t and resolve symlinks

include OpamStd.ABSTRACT
Sourcetype t
Sourceval compare : t -> t -> int
Sourceval equal : t -> t -> bool
Sourceval of_string : string -> t
Sourceval to_string : t -> string
Sourcemodule Set : OpamStd.SET with type elt = t
Sourcemodule Map : OpamStd.MAP with type key = t
Sourcetype generic_file =
  1. | D of Dir.t
  2. | F of t

Generic filename

Sourceval create : Dir.t -> Base.t -> t

Create a filename from a Dir.t and a basename

Sourceval of_basename : Base.t -> t

Create a file from a basename and the current working directory as dirname

Sourceval raw : string -> t

Creation from a raw string, without resolving symlinks, etc.

Sourceval prettify : t -> string

Prettify a filename:

  • replace /path/to/opam/foo by <opam>/foo
  • replace /path/to/home/foo by ~/foo
Sourceval prettify_dir : Dir.t -> string

Prettify a dirname.

Sourceval dirname : t -> Dir.t

Return the directory name

Sourceval basename : t -> Base.t

Return the base name

Sourceval read : t -> string

Retrieves the contents from the hard disk.

Sourceval open_in : t -> in_channel

Open a channel from a given file.

Sourceval open_in_bin : t -> in_channel
Sourceval open_out : t -> out_channel
Sourceval open_out_bin : t -> out_channel
Sourceval with_open_out_bin : t -> (out_channel -> unit) -> unit

with_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.

  • deprecated use with_open_out_bin_atomic instead
Sourceval with_open_out_bin_atomic : t -> (out_channel -> unit) -> unit

with_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.

Sourceval remove : t -> unit

Removes everything in filename if existed.

Sourceval write : t -> string -> unit

Removes everything in filename if existed, then write contents instead.

Sourceval exists : t -> bool

Returns true if the file exists and is a regular file or a symlink to one

Sourceval opt_file : t -> t option

Returns the argument as option if it exists and is either a regular file or a symlink to one

Sourceval with_tmp_file : (t -> 'a) -> 'a

Execute a function with a file in a temp directory. It is always cleaned up afterwards.

Sourceval with_tmp_file_job : (t -> 'a OpamProcess.job) -> 'a OpamProcess.job

Provide an automatically cleaned up file in temp directory to a job

Sourceval check_suffix : t -> string -> bool

Check whether a file has a given suffix

Sourceval add_extension : t -> string -> t

Adds a dot and the given file extension

Sourceval chop_extension : t -> t

Remove the file extension

Sourceval rec_files : Dir.t -> t list

List all the filenames, recursively

Sourceval files : Dir.t -> t list

List all the filename. Do not recurse.

Returns alll the files, including dangling symlinks (which means that not all entries will satisfy exists).

Sourceval with_contents : (string -> 'a) -> t -> 'a

Apply a function on the contents of a file

Sourceval copy_in : ?root:Dir.t -> t -> Dir.t -> unit

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".

Sourceval move : src:t -> dst:t -> unit

Move a file

Read a symlinked file

Is a symlink?

Sourceval is_exec : t -> bool

Is an executable?

Sourceval copy : src:t -> dst:t -> unit

Copy a file

Sourceval install : ?warning:OpamSystem.install_warning_fn -> ?exec:bool -> src:t -> dst:t -> unit -> unit

Installs 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.

Sourceval is_archive : t -> bool

Returns true if the given file is an archive (zip or tar)

Sourceval extract : t -> Dir.t -> unit

Extract an archive in a given directory (it rewrites the root to match Dir.t dir if needed)

Sourceval extract_job : t -> Dir.t -> exn option OpamProcess.job

Same as extract, as an OpamProcess.job

Sourceval extract_in : t -> Dir.t -> unit

Extract an archive in a given directory

Sourceval extract_in_job : t -> Dir.t -> exn option OpamProcess.job
Sourceval make_tar_gz_job : t -> Dir.t -> exn option OpamProcess.job
Sourceval extract_generic_file : generic_file -> Dir.t -> unit

Extract a generic file

Sourceval starts_with : Dir.t -> t -> bool

Check whether a filename starts by a given Dir.t

Sourceval ends_with : string -> t -> bool

Check whether a filename ends with a given suffix

Sourceval dir_starts_with : Dir.t -> Dir.t -> bool

dir starts_with pfx dir Check whether dir starts with pfx

Sourceval dir_ends_with : string -> Dir.t -> bool

Check whether a dirname ends with a given suffix

Sourceval remove_prefix : Dir.t -> t -> string

Remove a prefix from a file name

Sourceval remove_prefix_dir : Dir.t -> Dir.t -> string
Sourceval remove_suffix : Base.t -> t -> string

Remove a suffix from a filename

Sourceval patch : ?preprocess:bool -> allow_unclean:bool -> t -> Dir.t -> exn option

Apply a patch in a directory. If preprocess is set to false, there is no CRLF translation. Returns None on success, the process error otherwise.

  • parameter allow_unclean

    decides if applying a patch on a directory which differs slightly from the one described in the patch file is allowed. Allowing unclean applications imitates the default behaviour of GNU Patch.

Sourceval touch : t -> unit

Create an empty file

Sourceval chmod : t -> int -> unit

Change file permissions

Sourceval written_since : t -> float

Returns delay since last file update, based on mtime

Sourceval find_in_parents : (Dir.t -> bool) -> Dir.t -> Dir.t option

Returns the closest parent of a directory (including itself) for which the predicate holds, if any

Locking

Sourceval flock : [< OpamSystem.lock_flag ] -> ?dontblock:bool -> t -> OpamSystem.lock

See OpamSystem.flock. Prefer the higher level with_flock functions when possible

Sourceval with_flock : [< OpamSystem.lock_flag ] -> ?dontblock:bool -> t -> (Unix.file_descr -> 'a) -> 'a

Calls f while holding a lock file. Ensures the lock is properly released on f exit. f is passed the file_descr of the lock.

Sourceval with_flock_upgrade : [< OpamSystem.actual_lock_flag ] -> ?dontblock:bool -> OpamSystem.lock -> (Unix.file_descr -> 'a) -> 'a

Calls 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.

  • raises OpamSystem.Locked

    (but keeps the lock as is) if dontblock is set and the lock can't be upgraded.

Sourceval with_flock_write_then_read : ?dontblock:bool -> t -> (Unix.file_descr -> 'a) -> ('a -> 'b) -> 'b

Runs first function with a write lock on the given file, then releases it to a read lock and runs the second function.

Sourcemodule Op : sig ... end
Sourcemodule Attribute : sig ... end

Simple structure to handle file attributes

Sourcemodule SubPath : sig ... end
Sourceval to_attribute : Dir.t -> t -> Attribute.t

Convert a filename to an attribute, relatively to a root

On This Page
  1. Locking