tarCopyScript.php
Table of Contents
Functions
- tarCopyScript() : string
- Builds the bash script that copies part of a directory into another through two GNU tar.
Functions
tarCopyScript()
Builds the bash script that copies part of a directory into another through two GNU tar.
tarCopyScript(string $source, array<string|int, string> $members, string $destination[, array<string|int, string> $exclude = [] ]) : string
tar -cf - | tar -xf - rather than cp, because tar never reads what it excludes: a cache or
an archive left in the tree costs nothing to leave out. What this script adds is the reading of
the two exit codes, which set -o pipefail would merge into one:
- the tar that reads exits 0, 1 when files moved while it read them — modified, removed before being read, or shrunk — and 2 for a fatal error. On a directory that is in use, 1 happens by chance: the same copy passes a minute later. So the script exits with that code, for tarCopyOutcome() to judge from what tar said;
- the tar that writes must end in 0, always: a full disk shows there. When it does not, the script exits 3, a code the reading tar never uses for this.
It runs under LC_ALL=C: a tar that speaks the language of the machine reports a moved file in
that language, and tarCopyOutcome() reads the English messages of GNU tar. The script
runs tar as the PATH finds it, and relies on bash for PIPESTATUS: run it with bash -c.
Every path and pattern is escaped for the shell.
Parameters
- $source : string
-
The directory the members are read from.
- $members : array<string|int, string>
-
What is copied, relative to
$source. - $destination : string
-
The directory the copy is written to. It must exist.
- $exclude : array<string|int, string> = []
-
--excludepatterns, as GNU tar reads them (tarExcludesPath()).
Tags
Return values
string —The script, for bash -c.