Additional operating system utilities
Author(s): Manuel Hermenegildo, Jose F. Morales.
A convenient extension to library system
Usage and interface
- Library usage:
:- use_module(library(system_extra)). - Exports:
- Predicates:
-/1, --/1, try_finally/3, del_dir_if_empty/1, empty_dir/1, move_files/2, move_file/2, copy_files/2, copy_files/3, copy_files_nofail/3, del_file_nofail/1, del_files_nofail/1, file_to_line/2, replace_strings_in_file/3, backup_file/1, move_if_diff/2, set_file_owner/2, set_file_perms/2, set_exec_perms/2, mkpath/1, mkpath/2, mkpath/3, mkpath_mode/3, mkpath_mode/2, mkpath_mode/1, mktempdir_in_tmp/2, rmtempdir/1, using_tty/0, datime_atom/1, datime_atom/2, datime_string/1, datime_string/2, datime_to_string/2, replace_strings/3.
- Predicates:
- Imports:
- System library modules:
regexp_code, system, pathnames, messages, terms, lists, file_utils, process, source_tree. - Packages:
prelude, nonpure, condcomp, assertions, regtypes, isomodes, hiord, regexp.
- System library modules:
Documentation on exports
Usage:-G
Call G and show warning messages if something went wrong (failure and exceptions).
Usage:--G
Call G and ignore if something went wrong (failure and exceptions).
Usage:try_finally(Start,Goal,End)
Calls initialization goal Start and then calls Goal Goal, but always continues with the evaluation of End. If Goal is non-deterministic, in case of backtracking Start is called again before redoing Goal.
Usage 1:move_files(Files,Dir)
Move Files to directory Dir (note that to move only one file to a directory, rename_file/2 can be used).
(True) Usage 2:
- The following properties should hold at call time:
(basic_props:list/2)Arg1 is a list of atms.
(basic_props:atm/1)Arg2 is an atom.
Usage 1:copy_files(Files,Dir)
Like copy_files/3, with empty options list.
(True) Usage 2:
- The following properties should hold at call time:
(basic_props:list/2)Arg1 is a list of atms.
(basic_props:atm/1)Arg2 is an atom.
Usage:copy_files(Files,Dir,Opts)
Copy Files to directory Dir, using Opts as the option list for copy. See copy_file/3 for the list of options. Note that to move only one file to a directory, rename_file/2 can be used.
Usage:move_if_diff(From,To)
If To does not exists of its contents are different than From, delete To and rename From to To. Otherwise remove From and fail.
Usage:set_file_owner(File,Owner)
Set user/group of a file. Do nothing if Owner is free.
Usage:set_exec_perms(File,Perms)
Set file permissions, but treat regular files as directories w.r.t. 'X' flag
Usage:mkpath(Path)
Creates the directories necessary to access the given Path (which can be absolute or relative).
- The following properties should hold at call time:
(streams_basic:sourcename/1)Path is a source name.
Usage:mkpath(Path,Perms)
Like mkpath, but sets permissions of new directories as Perms.
- The following properties should hold at call time:
(streams_basic:sourcename/1)Path is a source name.
(basic_props:term/1)Perms is any term.
Usage:mkpath(Path,Perms,Owner)
Like mkpath, but sets permissions and owner of new directories to Perms and Owner.
- The following properties should hold at call time:
(streams_basic:sourcename/1)Path is a source name.
(basic_props:term/1)Perms is any term.
(basic_props:term/1)Owner is any term.
Usage:
Equivalent to mkpath_mode(Path,Mode,_).
- The following properties should hold at call time:
(streams_basic:sourcename/1)Arg1 is a source name.
(basic_props:int/1)Arg2 is an integer.
Usage:
Equivalent to mkpath_mode(Path,0o777,_).
- The following properties should hold at call time:
(streams_basic:sourcename/1)Arg1 is a source name.
Usage:mktempdir_in_tmp(Template,Path)
Create a directory in the temporary directory using Template (see mktemp_in_tmp/2). An empty file CREATED_WITH_MKTEMPDIR is created inside Path as a safety check for rmtempdir/1.
Usage:rmtempdir(Path)
Remove the temporary directory Path (recursively) created with mktempdir_in_tmp/2. As a safety check, this predicate throws an exception if the CREATED_WITH_MKTEMPDIR file is not in Path.
Known bugs and planned improvements
- Much of this should probably end up eventually in system, but once we have worked out the best interface and, in some cases, the proper implementation (the implementations in here are in some cases just calls to Unix shell primitives or commands).
- All those predicates (including system too) use atoms to represent file names. This pollutes the atom table. We need atom garbage collection and/or native strings.