untarWithBinary.php
Table of Contents
Functions
- untarWithBinary() : void
- Extracts an archive with the system `tar`.
Functions
untarWithBinary()
Extracts an archive with the system `tar`.
untarWithBinary(string $binary, string $tarFile, string $outputPath[, bool $preservePermissions = false ]) : void
Why this exists, and it is not about speed. PharData extracts a plain .tar at a
perfectly good pace — measured on 2026-10-24, 0.98 s against 0.82 s for GNU tar on the
same 57 MB archive. It is the compressed case that breaks, and it breaks in three ways
at once, all from one line: PharData::decompress() has PharData write a new
.tar before reading it.
- It cannot read what this library writes. PharData's writer refuses any path
component over 100 bytes — the
ustarlimit — so a.tar.gzholding one long name fails to extract with "filename ... is too long for tar file format", while the same archive uncompressed extracts fine. Since 1.3.0tar()delegates to GNU tar, which stores those names without difficulty: the two halves of this library had stopped agreeing, and a stock WordPress has such a path. - Memory. The rebuild costs about twice the archive — measured at ×2.26 on 60 MB and ×2.04 on 200 MB, so around 5 GB for a 2.45 GB backup.
- Disk. The intermediate
.taris written beside the archive, uncompressed, for the length of the extraction.
tar streams instead, and knows nothing of the 100-byte limit.
Two flags carry decisions:
--no-same-owner, always. As root — which is how a restore runs — GNU tar restores the owner recorded in the archive, while PharData never could. Keeping it off is what makes the two engines produce the same tree, and stops an archive from deciding who owns the files it is unpacked into.-ponly when asked, matchingkeepPermissions. Without ittarapplies the umask, as PharData does.
Path traversal needs no flag: GNU tar strips a leading / and refuses any member
whose name contains .., extracting nothing and exiting non-zero — which this reports.
Parameters
- $binary : string
-
The GNU tar to run, from tarBinary().
- $tarFile : string
-
Path to the archive.
- $outputPath : string
-
Existing directory to extract into.
- $preservePermissions : bool = false
-
Whether to restore the recorded permissions.