module FileUtil:sig
..end
A module to provide the core POSIX utilities to manipulate files and
directories. All functions try to mimic common POSIX utilities but are
written in pure OCaml.
Author(s): Sylvain Le Gall
exception FileDoesntExist of FilePath.filename
exception RecursiveLink of FilePath.filename
type'a
error_handler =string -> 'a -> unit
string
provided is the human readable version of 'a
. In most cases 'a
is a
polymorphic variant.exception Fatal of string
error_handler
the execution cannot
continue. The rest of the workflow logic cannot handle the default case and
the whole operation can be in the middle of transformation.type
action_link =
| |
Follow |
(* |
We consider link as simple directory (it is dangerous)
| *) |
| |
Skip |
(* |
Just skip it
| *) |
| |
SkipInform of |
(* |
Skip and execute an action
| *) |
| |
AskFollow of |
(* |
Ask and wait for input, false means skip
| *) |
type
interactive =
| |
Force |
(* |
Do it anyway
| *) |
| |
Ask of |
(* |
Promp the user
| *) |
type
base_permission = {
|
sticky : |
|
exec : |
|
write : |
|
read : |
type
permission = {
|
user : |
|
group : |
|
other : |
val permission_of_int : int -> permission
val int_of_permission : permission -> int
module Mode:sig
..end
type
size =
| |
TB of |
(* |
Tera bytes
| *) |
| |
GB of |
(* |
Giga bytes
| *) |
| |
MB of |
(* |
Mega bytes
| *) |
| |
KB of |
(* |
Kilo bytes
| *) |
| |
B of |
(* |
Bytes
| *) |
val byte_of_size : size -> int64
val size_add : size -> size -> size
val size_compare : ?fuzzy:bool -> size -> size -> int
val string_of_size : ?fuzzy:bool -> size -> string
type
kind =
| |
Dir |
| |
File |
| |
Dev_char |
| |
Dev_block |
| |
Fifo |
| |
Socket |
| |
Symlink |
type
stat = {
|
kind : |
|
is_link : |
|
permission : |
|
size : |
|
owner : |
|
group_owner : |
|
access_time : |
|
modification_time : |
|
creation_time : |
|
device : |
|
inode : |
val stat : ?dereference:bool -> FilePath.filename -> stat
stat fln
Return information about the file (like Unix.stat)
Non POSIX command.exception UmaskError of string
typeumask_error =
[ `Exc of exn | `NoStickyBit of int ]
val umask : ?error:umask_error error_handler ->
?mode:[< `Octal of int | `Symbolic of Mode.t ] ->
[< `Octal of int -> 'a | `Symbolic of Mode.t -> 'a ] -> 'a
val umask_apply : int -> int
type
test_file =
| |
Is_dev_block |
(* |
FILE is block special
| *) |
| |
Is_dev_char |
(* |
FILE is character special
| *) |
| |
Is_dir |
(* |
FILE is a directory
| *) |
| |
Exists |
(* |
FILE exists
| *) |
| |
Is_file |
(* |
FILE is a regular file
| *) |
| |
Is_set_group_ID |
(* |
FILE is set-group-ID
| *) |
| |
Has_sticky_bit |
(* |
FILE has its sticky bit set
| *) |
| |
Is_link |
(* |
FILE is a symbolic link
| *) |
| |
Is_pipe |
(* |
FILE is a named pipe
| *) |
| |
Is_readable |
(* |
FILE is readable
| *) |
| |
Is_writeable |
(* |
FILE is writeable
| *) |
| |
Size_not_null |
(* |
FILE has a size greater than zero
| *) |
| |
Size_bigger_than of |
(* |
FILE has a size greater than given size
| *) |
| |
Size_smaller_than of |
(* |
FILE has a size smaller than given size
| *) |
| |
Size_equal_to of |
(* |
FILE has the same size as given size
| *) |
| |
Size_fuzzy_equal_to of |
(* |
FILE has approximatively the same size as
given size
| *) |
| |
Is_socket |
(* |
FILE is a socket
| *) |
| |
Has_set_user_ID |
(* |
FILE its set-user-ID bit is set
| *) |
| |
Is_exec |
(* |
FILE is executable
| *) |
| |
Is_owned_by_user_ID |
(* |
FILE is owned by the effective user ID
| *) |
| |
Is_owned_by_group_ID |
(* |
FILE is owned by the effective group ID
| *) |
| |
Is_newer_than of |
(* |
FILE1 is newer (modification date) than
FILE2
| *) |
| |
Is_older_than of |
(* |
FILE1 is older than FILE2
| *) |
| |
Is_newer_than_date of |
(* |
FILE is newer than given date
| *) |
| |
Is_older_than_date of |
(* |
FILE is older than given date
| *) |
| |
And of |
(* |
Result of TEST1 and TEST2
| *) |
| |
Or of |
(* |
Result of TEST1 or TEST2
| *) |
| |
Not of |
(* |
Result of not TEST
| *) |
| |
Match of |
(* |
Compilable match (Str or PCRE or ...)
| *) |
| |
True |
(* |
Always true
| *) |
| |
False |
(* |
Always false
| *) |
| |
Has_extension of |
(* |
Check extension
| *) |
| |
Has_no_extension |
(* |
Check absence of extension
| *) |
| |
Is_parent_dir |
(* |
Basename is the parent dir
| *) |
| |
Is_current_dir |
(* |
Basename is the current dir
| *) |
| |
Basename_is of |
(* |
Check the basename
| *) |
| |
Dirname_is of |
(* |
Check the dirname
| *) |
| |
Custom of |
(* |
Custom operation on filename
| *) |
val test : ?match_compile:(FilePath.filename -> FilePath.filename -> bool) ->
test_file -> FilePath.filename -> bool
exception ChmodError of string
typechmod_error =
[ `Exc of exn ]
val chmod : ?error:chmod_error error_handler ->
?recurse:bool ->
[< `Octal of Unix.file_perm | `Symbolic of Mode.t ] ->
FilePath.filename list -> unit
exception MkdirError of string
typemkdir_error =
[ `DirnameAlreadyUsed of FilePath.filename
| `Exc of exn
| `MissingComponentPath of FilePath.filename
| `MkdirChmod of
FilePath.filename * Unix.file_perm * string * chmod_error ]
val mkdir : ?error:mkdir_error error_handler ->
?parent:bool ->
?mode:[< `Octal of Unix.file_perm | `Symbolic of FileUtilMode.t ] ->
FilePath.filename -> unit
~parent
to true
if you also want to create every directory of the path. Use mode to
provide some specific right.
See POSIX documentation.exception RmError of string
typerm_error =
[ `DirNotEmpty of FilePath.filename
| `Exc of exn
| `NoRecurse of FilePath.filename ]
val rm : ?error:rm_error error_handler ->
?force:interactive ->
?recurse:bool -> FilePath.filename list -> unit
~recurse
to true in order to
completely delete a directory.
See POSIX documentation.exception CpError of string
typecp_error =
[ `CannotChmodDstDir of FilePath.filename * exn
| `CannotCopyDir of FilePath.filename
| `CannotCopyFilesToFile of FilePath.filename list * FilePath.filename
| `CannotCreateDir of FilePath.filename * exn
| `CannotListSrcDir of FilePath.filename * exn
| `CannotOpenDstFile of FilePath.filename * exn
| `CannotOpenSrcFile of FilePath.filename * exn
| `CannotRemoveDstFile of FilePath.filename * exn
| `DstDirNotDir of FilePath.filename
| `ErrorRead of FilePath.filename * exn
| `ErrorWrite of FilePath.filename * exn
| `Exc of exn
| `NoSourceFile of FilePath.filename
| `PartialWrite of FilePath.filename * int * int
| `SameFile of FilePath.filename * FilePath.filename
| `UnhandledType of FilePath.filename * kind ]
val cp : ?follow:action_link ->
?force:interactive ->
?recurse:bool ->
?preserve:bool ->
?error:cp_error error_handler ->
FilePath.filename list -> FilePath.filename -> unit
exception MvError of string
typemv_error =
[ `Exc of exn
| `MvCp of FilePath.filename * FilePath.filename * string * cp_error
| `MvRm of FilePath.filename * string * rm_error
| `NoSourceFile ]
val mv : ?error:mv_error error_handler ->
?force:interactive -> FilePath.filename -> FilePath.filename -> unit
type
touch_time_t =
| |
Touch_now |
(* |
Use Unix.gettimeofday
| *) |
| |
Touch_file_time of |
(* |
Get mtime of file
| *) |
| |
Touch_timestamp of |
(* |
Use GMT timestamp
| *) |
val touch : ?atime:bool ->
?mtime:bool ->
?create:bool -> ?time:touch_time_t -> FilePath.filename -> unit
atime
: modify access time.mtime
: modify modification time.create
: if file doesn't exist, create it, default truetime
: what time to set, default Touch_nowval filter : test_file -> FilePath.filename list -> FilePath.filename list
val ls : FilePath.filename -> FilePath.filename list
val pwd : unit -> FilePath.filename
val readlink : FilePath.filename -> FilePath.filename
val which : ?path:FilePath.filename list -> FilePath.filename -> FilePath.filename
val cmp : ?skip1:int ->
FilePath.filename -> ?skip2:int -> FilePath.filename -> int option
cmp skip1 fln1 skip2 fln2
Compare files fln1
and fln2
starting at pos
skip1
skip2
and returning the first octect where a difference occurs.
Returns Some -1
if one of the file is not readable or if it is not a
file.
See POSIX documentation.val du : FilePath.filename list ->
size * (FilePath.filename * size) list
du fln_lst
Return the amount of space of all the file
which are subdir of fln_lst. Also return details for each
file scanned.
See POSIX documentation.val find : ?follow:action_link ->
?match_compile:(FilePath.filename -> FilePath.filename -> bool) ->
test_file ->
FilePath.filename -> ('a -> FilePath.filename -> 'a) -> 'a -> 'a
find ~follow:fol tst fln exec accu
Descend the directory tree starting
from the given filename and using the test provided. You cannot match
current_dir
and parent_dir
. For every file found, the action exec
is
done, using the accu
to start. For a simple file listing, you can use
find True "." (fun x y -> y :: x) []
See POSIX documentation.val pathchk: filename -> boolean * string
, check whether file names are
valid or portableval setfacl: filename -> permission -> unit
, set file access control
lists (UNIX + extended attribute)val getfacl: filename -> permission
, get file access control lists