This module defines predicates to operate on directory trees containing source code (source trees).
The possible operations include enumerating, copying, and cleaning files or selection of files based on filters. See source_filter/1 for a description of the available filters.
The walk algorithm (see internal walk/3) traverses a filtered directory structure and invokes actions (see internal action_hook/3, walk_action/1) parameterized by walk events (see internal walk_event/1) before entering a directory (enter event), when a file is processed (file event), and once the files in a directory are processed (exit event).
Filters restrict the walk to selected parts of the file tree. Filters are decomposed into formulas of basic filters, where a basic filter is a property of a regular file or directory (e.g., based on its name or path).
A normalized filter (see internal norm_filter/2) is given by the tuple of formulas (WalkP, DirP, FileP), where each component represents the following conditions for the walk algorithm:
Given a base directory, the walk algorithm will perform the following operation on each file F:
if F is a directory and WalkP(F): if DirP(F): Action 'enter' on F call recursively for each file in F Action 'exit' on F else: if FileP(F): Action 'file' on F
Find cleanable files in the current directory (recursively):
?- current_file_find([cleanable(src)], '.', X).
Find distributable packages:
?- current_file_find([proj(distributable), srctype(package)], '.', X).
Usage:current_file_find(Filter,BaseDir,FileName)
Enumerates recursively all files FileName (absolute file name) in BaseDir directory files that match the corresponding Filter.
Usage:copy_file_tree(Filter,SrcDir,DestDir,Perms)
Copy the file tree from SrcDir to DestDir with permissions Perms
Usage:copy_file_tree(Filter,SrcDir,DestDir,Perms,Owner)
Copy the file tree from SrcDir to DestDir with permissions Perms and owner Owner
Usage:clean_file_tree(PrecompLevel,Dir)
Unwind the precompilation level at directory Dir, cleaning the contents recursively (see untainted and cleanable(PrecompLevel) source_filter/1).
Usage:copy_file_or_dir(FileName,DestDir)
Copy FileName file into DestDir directory. The path for DestDir is created if it does not exists. If FileName is a directory, all its contents are copied recursively.
Usage:remove_dir(Dir)
Delete the directory Dir and all its contents recursively. Throws exception if file does not exist.
Usage:remove_file_or_dir(FileName)
Delete FileName. If FileName is a directory, all its contents are deleted recursively. Ignore errors if file does not exist.
Usage:delete_glob(Dir,Pattern)
Delete each file in directory Dir (non-recursively) that matches the glob pattern Pattern
Usage:remove_glob(Dir,Pattern)
Like delete_glob/2, but uses remove_dir/1 for each matching directory in Dir.
Basic filters:
Extended filters:
Additionally, excludes the build directory and some temporary files.
Additionally, excludes the build directory and some temporary files.
Usage:source_filter(Filter)
Filter is a source file filter
Usage:precomp_level(PrecompLevel)
PrecompLevel is a pre-compilation level
file_srctype(module). file_srctype(package). file_srctype(include).
Usage:file_srctype(T)
T is a source file type
Usage:get_file_srctype(FileName,Type)
FileName is a file of type Type (module, package, or include for included or user sources). Fails if the file does not seem Ciao code