Filesystem_asyncSourceThe currently running executable.
OCaml semantics do not guarantee an absolute path here.
These functions abstract over either In_channel and Out_channel, or Async.Reader and Async.Writer.
val write_file :
?perm:Filesystem_types_unix.File_permissions.t ->
File_path.t ->
contents:string ->
unit Async_kernel.Deferred.tval load_as_sexps :
File_path.t ->
of_sexp:(Core.Sexp.t -> 'a) ->
'a list Async_kernel.Deferred.tval save_sexp :
?perm:Filesystem_types_unix.File_permissions.t ->
File_path.t ->
Core.Sexp.t ->
unit Async_kernel.Deferred.tval save_sexps :
?perm:Filesystem_types_unix.File_permissions.t ->
File_path.t ->
Core.Sexp.t list ->
unit Async_kernel.Deferred.tval save_as_sexp :
?perm:Filesystem_types_unix.File_permissions.t ->
File_path.t ->
'a ->
sexp_of:('a -> Core.Sexp.t) ->
unit Async_kernel.Deferred.tval save_as_sexps :
?perm:Filesystem_types_unix.File_permissions.t ->
File_path.t ->
'a list ->
sexp_of:('a -> Core.Sexp.t) ->
unit Async_kernel.Deferred.tFilename WrappersThese functions abstract over Filename_unix.
val realpath :
File_path.t ->
relative_to:File_path.Absolute.t ->
File_path.Absolute.t Async_kernel.Deferred.tSys WrappersThese functions abstract over either Core.Sys or Async.Sys.
val exists :
?follow_symlinks:bool ->
File_path.t ->
[ `Yes | `No | `Unknown ] Async_kernel.Deferred.tval is_directory :
?follow_symlinks:bool ->
File_path.t ->
[ `Yes | `No | `Unknown ] Async_kernel.Deferred.tval is_file :
?follow_symlinks:bool ->
File_path.t ->
[ `Yes | `No | `Unknown ] Async_kernel.Deferred.tUnix WrappersThese functions abstract over either Core_unix or Async.Unix.
Please note that rmdir raises on a non-empty directory. If you want to delete a directory and all of its contents, see rm.
val mkdir :
?parents:bool ->
?perm:Filesystem_types_unix.File_permissions.t ->
File_path.t ->
unit Async_kernel.Deferred.tval chmod :
File_path.t ->
perm:Filesystem_types_unix.File_permissions.t ->
unit Async_kernel.Deferred.tSet the file's access_time and modify_time to at.
val update_timestamps_separately :
File_path.t ->
access_time:Core.Time_ns.t ->
modify_time:Core.Time_ns.t ->
unit Async_kernel.Deferred.tSet the file's access_time and modify_time to the given values.
These functions provide similar functionality to command-line tools like rm, either by mimicking them or by calling them directly.
Removes files.
If ~recursive:true is supplied, also recursively removes directories.
If ~force:false is supplied, will raise if given nonexistent or write-protected files. Defaults to true because programmatically-called rm is not interactive, we expect it to just succeed silently.
Creates the given path as a hard link to referring_to.
Creates the given path as a symbolic link to referring_to.
Reads the contents of a symbolic link.
As symlink. Raises if referring_to is not a valid path, but preserves non-canonical paths such as "multiple//and//trailing/".
As readlink. Preserves non-canonical paths such as "multiple//and//trailing/".
These functions combine File_path and getcwd.
Like File_path.make_absolute ~under:(getcwd ()). Avoids calling getcwd unless necessary.
Like File_path.make_relative ~if_under:(getcwd ()). Avoids calling getcwd unless necessary.
Like make_relative_to_cwd. Raises instead of returning None.
Like make_relative_to_cwd. Returns the original path instead of None.
The system-determined default temporary directory.
Has the same value as Core.Filename.temp_dir_name. OCaml semantics do not guarantee an absolute path here.
val within_temp_dir :
?in_dir:File_path.t ->
?on_cleanup_error:
unit Async_kernel.Deferred.t Filesystem_types_unix.On_cleanup_error.t ->
?perm:Filesystem_types_unix.File_permissions.t ->
?prefix:string ->
?suffix:string ->
(unit -> 'a Async_kernel.Deferred.t) ->
'a Async_kernel.Deferred.tCreates a new directory with a unique name, chdirs to it, runs the given function, chdirs back, and then recursively deletes the temporary directory and its contents.
If the directory is renamed or removed before the function ends, there is a race condition. Some other function or process may create a temporary directory or file by the same name, and this function may attempt to delete that.
val with_temp_dir :
?in_dir:File_path.t ->
?on_cleanup_error:
unit Async_kernel.Deferred.t Filesystem_types_unix.On_cleanup_error.t ->
?perm:Filesystem_types_unix.File_permissions.t ->
?prefix:string ->
?suffix:string ->
(File_path.Absolute.t -> 'a Async_kernel.Deferred.t) ->
'a Async_kernel.Deferred.tCreates a new directory with a unique name, runs the given function with the directory's path, and then recursively deletes the temporary directory and its contents.
Has the same race condition as within_temp_dir if the path is renamed or removed before the function finishes.
val with_temp_file :
?in_dir:File_path.t ->
?on_cleanup_error:
unit Async_kernel.Deferred.t Filesystem_types_unix.On_cleanup_error.t ->
?perm:Filesystem_types_unix.File_permissions.t ->
?prefix:string ->
?suffix:string ->
(File_path.Absolute.t -> 'a Async_kernel.Deferred.t) ->
'a Async_kernel.Deferred.tCreates a new file with a unique name, runs the given function with the file's path, and then deletes the temporary file.
Has the same race condition as within_temp_dir if the path is renamed or removed before the function finishes. Overwriting the file atomically by renaming something else to it should not have the same race condition.
val create_temp_dir :
?in_dir:File_path.t ->
?perm:Filesystem_types_unix.File_permissions.t ->
?prefix:string ->
?suffix:string ->
unit ->
File_path.Absolute.t Async_kernel.Deferred.tCreates a new directory with a unique name.
val create_temp_file :
?in_dir:File_path.t ->
?perm:Filesystem_types_unix.File_permissions.t ->
?prefix:string ->
?suffix:string ->
unit ->
File_path.Absolute.t Async_kernel.Deferred.tCreates a new, empty file with a unique name.
The flock system call supports mutual exclusion. When an exclusive lock on a file is held, other attempts to lock it fail or block. When a shared lock on a file is held, other attempts at shared locks succeed and attempts at exclusive locks fail or block.
No other access is controlled by these locks. For locks to affect access such as reading and writing, processes must cooperate with a locking protocol.
As of Linux 2.6.12, flock-based locks do function over NFS.
Locks the given file via the flock system call, returning when the lock has been acquired. If the file does not exist, this call raises.
If the file cannot be locked immediately due to an existing lock, this call waits until the file can be locked. If this lock and existing locks are shared, the file can be locked immediately.
If the same process calls flock twice on the same file you will end up with two competing locks. You have been warned!
Like flock above. Uses an already-open file descriptor for locking.
val flock_create :
?perm:Filesystem_types_unix.File_permissions.t ->
?shared:bool ->
File_path.t ->
Flock.t Async_kernel.Deferred.tLike flock above. If the file does not exist, creates it with the given permissions before locking.
Like flock above. If the file cannot be locked immediately due to an existing lock, this call returns None instead of waiting.
Like try_flock above. Uses an already-open file descriptor for locking.
val try_flock_create :
?perm:Filesystem_types_unix.File_permissions.t ->
?shared:bool ->
File_path.t ->
Flock.t option Async_kernel.Deferred.tLike try_flock above. If the file does not exist, creates it with the given permissions before locking.
Releases the given lock. These locks are automatically released on exit or exec, so this only needs to be used if the lock needs to be released during the execution of the program. Does not close any file descriptors passed to *_of_fd creators.
val with_flock :
?shared:bool ->
File_path.t ->
f:(Flock.t -> 'a Async_kernel.Deferred.t) ->
'a Async_kernel.Deferred.tAcquires a lock for the duration of f. Calls flock before f, and funlock after f returns or raises.
val with_flock_of_fd :
?shared:bool ->
Fd.t ->
f:(Flock.t -> 'a Async_kernel.Deferred.t) ->
'a Async_kernel.Deferred.tLike with_flock. Uses an already-open file descriptor for locking.
val with_flock_create :
?perm:Filesystem_types_unix.File_permissions.t ->
?shared:bool ->
File_path.t ->
f:(Flock.t -> 'a Async_kernel.Deferred.t) ->
'a Async_kernel.Deferred.tLike with_flock above. Calls flock_create instead of flock.