Source

spotlib / lib / xunix.mli

open Unix

module Find : sig

  class type path = object
    method base : string
    method depth : int
    method dev_inode : (int * int, exn) Result.t
    method dir : string
    method is_dir : bool
    method is_ldir : bool
    method is_reg : bool
    method kind : (Unix.file_kind, exn) Result.t
    method lkind : (Unix.file_kind, exn) Result.t
    method path : string
    method stat : (Unix.stats, exn) Result.t
    method lstat : (Unix.stats, exn) Result.t
  end

  val prune : unit -> 'a
  val find : ?follow_symlink:bool -> f:(path -> unit) -> string list -> unit

end

module Process_status : sig

  type t = [ `Exited of int | `Signaled of int | `Stopped of int ]  

  val failwith : ?name:string -> [< t ] -> 'a

  val convert : Unix.process_status -> [> t ]
  (** Constructors of [Unix.process_status] are hard to remember,
      we here convert them to polyvars *)
end

val shell_command :
  ?f: ([> `Out | `Err] * [ `Read of string | `EOF ] -> unit) 
  -> string 
  -> [> Process_status.t ]
(** Execute a shell command using /bin/sh *)

val command :
  ?f: ([> `Out | `Err] * [ `Read of string | `EOF ] -> unit) 
  -> string list
  -> [> Process_status.t ]
(** Same as [shell_command] but it takes the command and arguments as a list of string,
    then directly executed by [Unix.execvp]. *)

val shell_command' :
  string 
  -> ('st -> [> `Out | `Err] * [ `Read of string | `EOF ] -> 'st) 
  -> init: 'st 
  -> [> Process_status.t ] * 'st
(** Execute a shell command using /bin/sh *)

val command' :
  string list
  -> ('st -> [> `Out | `Err] * [ `Read of string | `EOF ] -> 'st) 
  -> init: 'st
  -> [> Process_status.t ] * 'st
(** Same as [shell_command] but it takes the command and arguments as a list of string,
    then directly executed by [Unix.execvp]. *)

val shell_command_stdout :
  string -> [> Process_status.t ] * string list
(** Execute a shell command using /bin/sh
    Err is printed to stderr.
 *)

val cmp : string -> string -> [`Same | `Different | `Error]
(** Execute "cmp", the file comparison unix command by execvp *)
  
val file : string -> [> `Error of [> `Empty_result 
                                  | Process_status.t ]
                     | `Ok of string ]
(** Execute "file path" *)

val timed : ('a -> 'b) -> 'a -> 'b * float (* in sec *)

module Process_times : sig
  type t = process_times
  val (-) : t -> t -> t
  val timed : ('a -> 'b) -> 'a -> 'b * t
end

val mkdir : ?perm:Unix.file_perm -> string -> 
  [> `Ok 
  | `Already_exists of Unix.stats
  | `Error of Unix.error
  | `Not_a_directory of Unix.stats ]
  (** Create a directory of the given name. Does nothing if the
      directory exists already. 

      Bug: No chmod if the directroy already exists.
  *)

val mkdtemp : string -> string
(** Like mkdtemp(3). It must take a template whose postfix is "XXXXXX".
    It creates a new directory name by replacing "XXXXXX" by random number then creates a directory
    of permission 0o700 
*)

val with_dtemp : string -> (string -> 'a) -> 'a
(** [with_dtemp template f] creates a temp directory [dir] using 
    [mkdtemp template] then runs [f dir]. 
    The temp directory [dir] is automatically removed 
    (even if it is not empty) after [f dir].
*)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.