assertRemovableDirectory.php
Table of Contents
Functions
- assertRemovableDirectory() : void
- Asserts that a path is safe to hand to a recursive deletion.
Functions
assertRemovableDirectory()
Asserts that a path is safe to hand to a recursive deletion.
assertRemovableDirectory(string $path[, int $minDepth = 3 ]) : void
A path read from a configuration file ends up, sooner or later, in deleteDirectory() or
an rm -rf. A truncated, relative or mistyped value there turns a routine clean-up into the
loss of a system directory, so the path is checked as text before anything acts on it.
A path is accepted when it is:
- not empty ;
- absolute — a relative path depends on the current directory, which nobody checks ;
- free of
.and..segments —/var/www/site/..is/var/www; - deep enough — at least
$minDepthsegments, so/,/varand/var/wwware refused with the default of 3.
Nothing is read on disk: the directory need not exist, and a link is judged by its own path. This is a guard against a wrong value, not against a hostile one.
Parameters
- $path : string
-
The directory about to be deleted.
- $minDepth : int = 3
-
The number of segments the path must have, at least.