Node:File sweeps, Neste:Log files, Forrige:Wildcards in directory names, Opp:More advanced concepts
File sweeps are searches through a directory tree in which many files are examined and considered for processing in some way. There are many instances where one uses cfengine to perform a file sweep.
files
action, for checking access rights and ownership
of files.
tidy
action, for checking files for deletion.
copy
action, while recursively checking whether to
copy a file tree.
editfiles
action, while recursively checking whether to
edit the files in a tree of files.
The problem with file sweeps is that they can be too sweeping! Often you are not interested in examining every single file in a file tree. You might wish to perform a search
ignore
.
The tidy action is slightly different in this respect, since it already
always expects to match a specific pattern. One is generally not
interested in a search which deletes everything except for a named
pattern: this would be too dangerous. For this reason, the syntax of
tidy
does not allow ignore,include and exclude. It is documented
in the section on tidying, (see Reference manual).
Items declared under the global ignore
section affect files,
copy, links and tidy. For file sweeps within files, copy and links, you
may provide private ignore lists using ignore=
. The difference between
exclude and ignore is that ignore can deal with absolute directories. It prunes
directories, while exclude only looks at the files within directories.
For file sweeps within files
and copy
you can specify
specific search parameters using the keywords include=
and exclude=
and as of version 1.6.x filter=
.
For example,
files: /usr/local/bin m=0755 exclude=*.ps action=fixall
In this example cfengine searches the entire file tree (omitting
any directories listed in the ignore-list and omitting
any files ending in the extension .ps
), (see Reference manual).
Specifying the include=
keyword is slightly different since it
automatically restricts the search to only named patterns (using *
and ?
wildcards), whenever
you have one or more instances of it. If you include patterns in this
way, cfengine ignores any files which do not match the given patterns.
It also ignores any patterns which you have specified in the global
ignore-list as well as patterns excluded with exclude=pattern
.
In other words, exclusions always override inclusions.
If you exclude a pattern or a directory and wish to treat it in
some special way, you need to code an explicit check for that pattern
as a separate entity. For example, to handle the exluded .ps
files above, you would need to code something like this:
files: /usr/local/bin m=0644 include=*.ps action=fixall
Note: don't be tempted to enclose your wildcards in quotes. The quotes will be treated literally and the pattern might not match the way you would expect.
For editfiles
the syntax is somewhat different. Here one needs to add
lines to the edit stanza:
editfiles: { /tmp/testdir Include .* Exclude bla.* Ignore "." Ignore ".." Recurse 6 ReplaceAll "search" With "replace" }