Oihana PHP

preservePharFilePermissions.php

Table of Contents

Functions

preservePharFilePermissions()  : void
Preserves file permissions from a Phar archive to the extracted files.

Functions

preservePharFilePermissions()

Preserves file permissions from a Phar archive to the extracted files.

preservePharFilePermissions(PharData $phar, string $outputPath) : void

This function iterates over the contents of a PharData archive and applies the original file permissions (as stored in the archive) to the corresponding extracted files in the specified output directory.

This is especially useful when extracting .tar or .tar.gz archives where file modes (e.g., executable bits) should be retained.

If a file's permissions cannot be set, the function logs a warning using error_log().

Parameters
$phar : PharData

The PharData archive instance.

$outputPath : string

The absolute path to the directory where files were extracted.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0
example
use PharData;
use oihana\files\phar\assertPhar;
use oihana\files\phar\preservePharFilePermissions;

assertPhar();

$phar = new PharData('/archives/app.tar');
$phar->extractTo('/var/www/app', true);

preservePharFilePermissions($phar, '/var/www/app');

        
On this page

Search results