tarExcludesPath.php
Table of Contents
Functions
- tarExcludesPath() : bool
- Tells whether GNU tar's `--exclude` patterns would leave a path out of an archive.
Functions
tarExcludesPath()
Tells whether GNU tar's `--exclude` patterns would leave a path out of an archive.
tarExcludesPath(string $path, array<string|int, string> $patterns) : bool
An archive made with tar --exclude=<pattern> … is missing two kinds of things compared with
the tree it was made from: what was added since, and what a pattern left out on purpose. A
caller that compares the two — to restore a tree to its archive, for instance — has to tell
them apart, or it removes what was never meant to be archived.
This reads the patterns the way GNU tar reads them by default:
- unanchored: a pattern may match from any
/of the member name, socachealso matchesapp/cache; - leading directory: a pattern matching a directory leaves out everything under it, so
cachematchesapp/cache/a.bin; - wildcards cross a slash:
*matches/too, as fnmatch() does with no flags.
Leading and trailing slashes of the path and the patterns are ignored, and an empty pattern matches nothing. Erring wide is the safe direction for the usual caller: a path taken for excluded is kept, never removed.
Parameters
- $path : string
-
A path relative to the directory tar was run from, e.g.
content/cache/a.bin. - $patterns : array<string|int, string>
-
The
--excludepatterns.
Tags
Return values
bool —True when one of the patterns leaves the path out.