package b0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0
doc/b0.std/B0_std/Os/Path/index.html
Module Os.PathSource
File system path operations.
These functions operate on files and directories equally. Specific function operating on either kind of path are in the File and Dir modules.
Existence
exists p is Ok true if p exists in the file system and Ok false otherwise. Symbolic links are followed.
must_exist p is Ok () if p exists in the file system and an error otherwise. Symbolic links are followed.
Deleting and renaming
delete ~recurse p deletes p from the file system. If p is a symbolic link this only deletes the link, not the linked object. If recurse is true and p is a non-empty directory, no error occurs, its contents is recursively deleted. The result is:
Ok true, ifpexisted and was deleted.Ok false, if the pathpdid not exist on the file system.Error _in case of error, in particular ifpis a non-empty directory andrecurseisfalse.
See also File.delete.
rename ~force ~make_path src ~dst renames src to dst.
- If
forceistrueanddstexists it tries to delete it usingFile.deletedst. Ifforceisfalseanddstexists the function errors. - If
make_pathistrueand the parent directory ofdstdoes not exist the whole path to the parent is created as needed with permission0o755(readable and traversable by everyone, writable by the user).
Resolving
realpath p expands all symbolic links and resolves all references to . and .. segments. The function errors if p does not exist.
Copying
val copy :
?rel:bool ->
?atomic:bool ->
?follow_symlinks:bool ->
?prune:(Unix.stats -> string -> Fpath.t -> bool) ->
make_path:bool ->
recurse:bool ->
Fpath.t ->
dst:Fpath.t ->
(unit, string) resultcopy ~make_path ~recurse src ~dst copies the file or file hierarchy rooted at src to dst. The function errors if dst exists. The semantics and arguments correspond to those of Os.Dir.copy, except this function also works if src is not a directory. Note that prune is never called on src itself FIXME is that a good idea ? also FIXME this should error if src is a directory and recurse is false.
See also Os.Dir.copy and Os.File.copy.
File mode, stat and mounts
See also File.is_executable.
get_mode p is the file mode of p. Symbolic links are followed.
set_mode file p sets the file mode of file to p. Symbolic links are followed.
stat p is p's file information. Symbolic links are followed.
is_mount_point p is true if p looks like a mount point. The criterion is if p and p/..'s stat have a differing Unix.stat.std_dev field.
Symbolic links
For hard links see Hard links.
symlink ~force ~src p symbolically links src to p.
- If
forceistrueandpexists it tries to delete it usingFile.deletep. Ifforceisfalseandpexists the function errors. - If
make_pathistrueand the parent directory offiledoes not exist the whole path to the parent is created as needed with permission0o755(readable and traversable by everyone, writable by the user).
symlink_link p is Ok l if p is a symbolic link to l.
Temporary paths
The type for temporary file name patterns. The string format is replaced by random hexadecimal ASCII characters.
val tmp :
?make_path:bool ->
?dir:Fpath.t ->
?name:tmp_name ->
unit ->
(Fpath.t, string) resulttmp ~make_path ~dir name () is a file system path in dir that did not exist when the name was devised. It may exist once the function returns though, prefer temporary files and directories creation functions to guarantee the creation of the temporary objects.
nameis used to construct the filename of the file, seetmp_namefor details. It defaults to"tmp-%s".diris the directory in which the temporary file is created. It defaults toB0_std.Os.Dir.default_tmp().- If
make_pathistrue(default) anddirdoes not exist the whole path to it is created as needed with permission0o755(readable and traversable by everyone, writable by the user).