Commit 53c6cc8a authored by catch's avatar catch

Issue #3026588 by alexpott, plach, jibran, Berdir, larowlan, Sam152, Pancho,...

Issue #3026588 by alexpott, plach, jibran, Berdir, larowlan, Sam152, Pancho, hussainweb et al: Move ArchiveTar to composer
parent a33e47e5
......@@ -1052,6 +1052,218 @@
],
"time": "2018-07-04T16:31:37+00:00"
},
{
"name": "pear/archive_tar",
"version": "1.4.5",
"source": {
"type": "git",
"url": "https://github.com/pear/Archive_Tar.git",
"reference": "ff716ca697c5e9e8593212cb785ffd03ee11b01f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Archive_Tar/zipball/ff716ca697c5e9e8593212cb785ffd03ee11b01f",
"reference": "ff716ca697c5e9e8593212cb785ffd03ee11b01f",
"shasum": ""
},
"require": {
"pear/pear-core-minimal": "^1.10.0alpha2",
"php": ">=5.2.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"suggest": {
"ext-bz2": "Bz2 compression support.",
"ext-xz": "Lzma2 compression support.",
"ext-zlib": "Gzip compression support."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-0": {
"Archive_Tar": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"./"
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Vincent Blavet",
"email": "vincent@phpconcept.net"
},
{
"name": "Greg Beaver",
"email": "greg@chiaraquartet.net"
},
{
"name": "Michiel Rook",
"email": "mrook@php.net"
}
],
"description": "Tar file management class with compression support (gzip, bzip2, lzma2)",
"homepage": "https://github.com/pear/Archive_Tar",
"keywords": [
"archive",
"tar"
],
"time": "2019-01-02T21:45:13+00:00"
},
{
"name": "pear/console_getopt",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/pear/Console_Getopt.git",
"reference": "82f05cd1aa3edf34e19aa7c8ca312ce13a6a577f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Console_Getopt/zipball/82f05cd1aa3edf34e19aa7c8ca312ce13a6a577f",
"reference": "82f05cd1aa3edf34e19aa7c8ca312ce13a6a577f",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-0": {
"Console": "./"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"./"
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Greg Beaver",
"email": "cellog@php.net",
"role": "Helper"
},
{
"name": "Andrei Zmievski",
"email": "andrei@php.net",
"role": "Lead"
},
{
"name": "Stig Bakken",
"email": "stig@php.net",
"role": "Developer"
}
],
"description": "More info available on: http://pear.php.net/package/Console_Getopt",
"time": "2015-07-20T20:28:12+00:00"
},
{
"name": "pear/pear-core-minimal",
"version": "v1.10.7",
"source": {
"type": "git",
"url": "https://github.com/pear/pear-core-minimal.git",
"reference": "19a3e0fcd50492c4357372f623f55f1b144346da"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/pear-core-minimal/zipball/19a3e0fcd50492c4357372f623f55f1b144346da",
"reference": "19a3e0fcd50492c4357372f623f55f1b144346da",
"shasum": ""
},
"require": {
"pear/console_getopt": "~1.4",
"pear/pear_exception": "~1.0"
},
"replace": {
"rsky/pear-core-min": "self.version"
},
"type": "library",
"autoload": {
"psr-0": {
"": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"src/"
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Christian Weiske",
"email": "cweiske@php.net",
"role": "Lead"
}
],
"description": "Minimal set of PEAR core files to be used as composer dependency",
"time": "2018-12-05T20:03:52+00:00"
},
{
"name": "pear/pear_exception",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/pear/PEAR_Exception.git",
"reference": "8c18719fdae000b690e3912be401c76e406dd13b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/8c18719fdae000b690e3912be401c76e406dd13b",
"reference": "8c18719fdae000b690e3912be401c76e406dd13b",
"shasum": ""
},
"require": {
"php": ">=4.4.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"type": "class",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"PEAR": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"."
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Helgi Thormar",
"email": "dufuz@php.net"
},
{
"name": "Greg Beaver",
"email": "cellog@php.net"
}
],
"description": "The PEAR Exception base class.",
"homepage": "https://github.com/pear/PEAR_Exception",
"keywords": [
"exception"
],
"time": "2015-02-10T20:07:52+00:00"
},
{
"name": "psr/container",
"version": "1.0.0",
......
......@@ -46,7 +46,8 @@
"zendframework/zend-diactoros": "^1.1",
"composer/semver": "^1.0",
"paragonie/random_compat": "^1.0|^2.0",
"asm89/stack-cors": "^1.1"
"asm89/stack-cors": "^1.1",
"pear/archive_tar": "^1.4"
},
"conflict": {
"drush/drush": "<8.1.10"
......
<?php
// @codingStandardsIgnoreFile
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* File::CSV
*
* PHP versions 4 and 5
*
* Copyright (c) 1997-2008,
* Vincent Blavet <vincent@phpconcept.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @category File_Formats
* @package Archive_Tar
* @author Vincent Blavet <vincent@phpconcept.net>
* @copyright 1997-2010 The Authors
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id$
* @link http://pear.php.net/package/Archive_Tar
*/
/**
* Note on Drupal 8 porting.
* This file origin is Tar.php, release 1.4.5 (stable) with some code
* from PEAR.php, release 1.9.5 (stable) both at http://pear.php.net.
* To simplify future porting from pear of this file, you should not
* do cosmetic or other non significant changes to this file.
* The following changes have been done:
* Added namespace Drupal\Core\Archiver.
* Removed require_once 'PEAR.php'.
* Added definition of OS_WINDOWS taken from PEAR.php.
* Renamed class to ArchiveTar.
* Removed extends PEAR from class.
* Removed call parent:: __construct().
* Changed PEAR::loadExtension($extname) to this->loadExtension($extname).
* Added function loadExtension() taken from PEAR.php.
* Changed all calls of unlink() to drupal_unlink().
* Changed $this->error_object = &$this->raiseError($p_message)
* to throw new \Exception($p_message).
*/
// Drupal addition.
namespace {
// Drupal removal require_once 'PEAR.php'.
// Drupal addition OS_WINDOWS as defined in PEAR.php.
if (substr(PHP_OS, 0, 3) == 'WIN') {
define('OS_WINDOWS', true);
} else {
define('OS_WINDOWS', false);
}
namespace Drupal\Core\Archiver;
define('ARCHIVE_TAR_ATT_SEPARATOR', 90001);
define('ARCHIVE_TAR_END_BLOCK', pack("a512", ''));
if (!function_exists('gzopen') && function_exists('gzopen64')) {
function gzopen($filename, $mode, $use_include_path = 0)
{
return gzopen64($filename, $mode, $use_include_path);
}
}
if (!function_exists('gztell') && function_exists('gztell64')) {
function gztell($zp)
{
return gztell64($zp);
}
}
if (!function_exists('gzseek') && function_exists('gzseek64')) {
function gzseek($zp, $offset, $whence = SEEK_SET)
{
return gzseek64($zp, $offset, $whence);
}
}
}
// Drupal addition.
namespace Drupal\Core\Archiver {
/**
* Creates a (compressed) Tar archive
*
* @package Archive_Tar
* @author Vincent Blavet <vincent@phpconcept.net>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version $Revision$
* Extends Pear's Archive_Tar to use exceptions.
*/
// Drupal change class Archive_Tar extends PEAR.
class ArchiveTar
{
/**
* @var string Name of the Tar
*/
public $_tarname = '';
/**
* @var boolean if true, the Tar file will be gzipped
*/
public $_compress = false;
/**
* @var string Type of compression : 'none', 'gz', 'bz2' or 'lzma2'
*/
public $_compress_type = 'none';
/**
* @var string Explode separator
*/
public $_separator = ' ';
/**
* @var file descriptor
*/
public $_file = 0;
/**
* @var string Local Tar name of a remote Tar (http:// or ftp://)
*/
public $_temp_tarname = '';
/**
* @var string regular expression for ignoring files or directories
*/
public $_ignore_regexp = '';
/**
* @var object PEAR_Error object
*/
public $error_object = null;
/**
* Format for data extraction
*
* @var string
*/
public $_fmt ='';
/**
* Archive_Tar Class constructor. This flavour of the constructor only
* declare a new Archive_Tar object, identifying it by the name of the
* tar file.
* If the compress argument is set the tar will be read or created as a
* gzip or bz2 compressed TAR file.
*
* @param string $p_tarname The name of the tar archive to create
* @param string $p_compress can be null, 'gz', 'bz2' or 'lzma2'. This
* parameter indicates if gzip, bz2 or lzma2 compression
* is required. For compatibility reason the
* boolean value 'true' means 'gz'.
*
* @return bool
*/
public function __construct($p_tarname, $p_compress = null)
{
// Drupal removal parent::__construct().
$this->_compress = false;
$this->_compress_type = 'none';
if (($p_compress === null) || ($p_compress == '')) {
if (@file_exists($p_tarname)) {
if ($fp = @fopen($p_tarname, "rb")) {
// look for gzip magic cookie
$data = fread($fp, 2);
fclose($fp);
if ($data == "\37\213") {
$this->_compress = true;
$this->_compress_type = 'gz';
// Not sure it's enough for a magic code ....
} elseif ($data == "BZ") {
$this->_compress = true;
$this->_compress_type = 'bz2';
} elseif (file_get_contents($p_tarname, false, null, 1, 4) == '7zXZ') {
$this->_compress = true;
$this->_compress_type = 'lzma2';
}
}
} else {
// probably a remote file or some file accessible
// through a stream interface
if (substr($p_tarname, -2) == 'gz') {
$this->_compress = true;
$this->_compress_type = 'gz';
} elseif ((substr($p_tarname, -3) == 'bz2') ||
(substr($p_tarname, -2) == 'bz')
) {
$this->_compress = true;
$this->_compress_type = 'bz2';
} else {
if (substr($p_tarname, -2) == 'xz') {
$this->_compress = true;
$this->_compress_type = 'lzma2';
}
}
}
} else {
if (($p_compress === true) || ($p_compress == 'gz')) {
$this->_compress = true;
$this->_compress_type = 'gz';
} else {
if ($p_compress == 'bz2') {
$this->_compress = true;
$this->_compress_type = 'bz2';
} else {
if ($p_compress == 'lzma2') {
$this->_compress = true;
$this->_compress_type = 'lzma2';
} else {
$this->_error(
"Unsupported compression type '$p_compress'\n" .
"Supported types are 'gz', 'bz2' and 'lzma2'.\n"
);
return false;
}
}
}
}
$this->_tarname = $p_tarname;
if ($this->_compress) { // assert zlib or bz2 or xz extension support
if ($this->_compress_type == 'gz') {
$extname = 'zlib';
} else {
if ($this->_compress_type == 'bz2') {
$extname = 'bz2';
} else {
if ($this->_compress_type == 'lzma2') {
$extname = 'xz';
}
}
}
if (!extension_loaded($extname)) {
// Drupal change PEAR::loadExtension($extname).
$this->loadExtension($extname);
}
if (!extension_loaded($extname)) {
$this->_error(
"The extension '$extname' couldn't be found.\n" .
"Please make sure your version of PHP was built " .
"with '$extname' support.\n"
);
return false;
}
}
if (version_compare(PHP_VERSION, "5.5.0-dev") < 0) {
$this->_fmt = "a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" .
"a8checksum/a1typeflag/a100link/a6magic/a2version/" .
"a32uname/a32gname/a8devmajor/a8devminor/a131prefix";
} else {
$this->_fmt = "Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/" .
"Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/" .
"Z32uname/Z32gname/Z8devmajor/Z8devminor/Z131prefix";
}
}
public function __destruct()
{
$this->_close();
// ----- Look for a local copy to delete
if ($this->_temp_tarname != '') {
@drupal_unlink($this->_temp_tarname);
}
}
// Drupal addition from PEAR.php.
/**
* OS independent PHP extension load. Remember to take care
* on the correct extension name for case sensitive OSes.
*
* @param string $ext The extension name
* @return bool Success or not on the dl() call
*/
function loadExtension($ext)
{
if (extension_loaded($ext)) {
return true;
}
// if either returns true dl() will produce a FATAL error, stop that
if (
function_exists('dl') === false ||
ini_get('enable_dl') != 1 ||
ini_get('safe_mode') == 1
) {
return false;
}
if (OS_WINDOWS) {
$suffix = '.dll';
} elseif (PHP_OS == 'HP-UX') {
$suffix = '.sl';
} elseif (PHP_OS == 'AIX') {
$suffix = '.a';
} elseif (PHP_OS == 'OSX') {
$suffix = '.bundle';
} else {
$suffix = '.so';
}
return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
}
/**
* This method creates the archive file and add the files / directories
* that are listed in $p_filelist.
* If a file with the same name exist and is writable, it is replaced
* by the new tar.
* The method return false and a PEAR error text.
* The $p_filelist parameter can be an array of string, each string
* representing a filename or a directory name with their path if
* needed. It can also be a single string with names separated by a
* single blank.
* For each directory added in the archive, the files and
* sub-directories are also added.
* See also createModify() method for more details.
*
* @param array $p_filelist An array of filenames and directory names, or a
* single string with names separated by a single
* blank space.
*
* @return true on success, false on error.
* @see createModify()
*/
public function create($p_filelist)
{
return $this->createModify($p_filelist, '', '');
}
/**
* This method add the files / directories that are listed in $p_filelist in
* the archive. If the archive does not exist it is created.
* The method return false and a PEAR error text.
* The files and directories listed are only added at the end of the archive,
* even if a file with the same name is already archived.
* See also createModify() method for more details.
*
* @param array $p_filelist An array of filenames and directory names, or a
* single string with names separated by a single
* blank space.
*
* @return true on success, false on error.
* @see createModify()
* @access public
*/
public function add($p_filelist)
{
return $this->addModify($p_filelist, '', '');
}
/**
* @param string $p_path
* @param bool $p_preserve
* @return bool
*/
public function extract($p_path = '', $p_preserve = false)
{
return $this->extractModify($p_path, '', $p_preserve);
}
/**
* @return array|int
*/
public function listContent()
{
$v_list_detail = array();
if ($this->_openRead()) {
if (!$this->_extractList('', $v_list_detail, "list", '', '')) {
unset($v_list_detail);
$v_list_detail = 0;
}
$this->_close();
}
return $v_list_detail;
}
/**
* This method creates the archive file and add the files / directories
* that are listed in $p_filelist.
* If the file already exists and is writable, it is replaced by the
* new tar. It is a create and not an add. If the file exists and is
* read-only or is a directory it is not replaced. The method return
* false and a PEAR error text.
* The $p_filelist parameter can be an array of string, each string
* representing a filename or a directory name with their path if
* needed. It can also be a single string with names separated by a
* single blank.
* The path indicated in $p_remove_dir will be removed from the
* memorized path of each file / directory listed when this path
* exists. By default nothing is removed (empty path '')
* The path indicated in $p_add_dir will be added at the beginning of
* the memorized path of each file / directory listed. However it can
* be set to empty ''. The adding of a path is done after the removing
* of path.
* The path add/remove ability enables the user to prepare an archive
* for extraction in a different path than the origin files are.
* See also addModify() method for file adding properties.
*
* @param array $p_filelist An array of filenames and directory names,
* or a single string with names separated by
* a single blank space.
* @param string $p_add_dir A string which contains a path to be added
* to the memorized path of each element in
* the list.
* @param string $p_remove_dir A string which contains a path to be
* removed from the memorized path of each
* element in the list, when relevant.
*
* @return boolean true on success, false on error.
* @see addModify()
*/
public function createModify($p_filelist, $p_add_dir, $p_remove_dir = '')
{
$v_result = true;
if (!$this->_openWrite()) {
return false;
}
if ($p_filelist != '') {
if (is_array($p_filelist)) {
$v_list = $p_filelist;
} elseif (is_string($p_filelist)) {
$v_list = explode($this->_separator, $p_filelist);
} else {
$this->_cleanFile();
$this->_error('Invalid file list');
return false;
}
$v_result = $this->_addList($v_list, $p_add_dir, $p_remove_dir);
}
if ($v_result) {
$this->_writeFooter();
$this->_close();
} else {
$this->_cleanFile();
}
return $v_result;
}
/**
* This method add the files / directories listed in $p_filelist at the
* end of the existing archive. If the archive does not yet exists it
* is created.
* The $p_filelist parameter can be an array of string, each string
* representing a filename or a directory name with their path if
* needed. It can also be a single string with names separated by a
* single blank.
* The path indicated in $p_remove_dir will be removed from the
* memorized path of each file / directory listed when this path
* exists. By default nothing is removed (empty path '')
* The path indicated in $p_add_dir will be added at the beginning of
* the memorized path of each file / directory listed. However it can
* be set to empty ''. The adding of a path is done after the removing
* of path.
* The path add/remove ability enables the user to prepare an archive
* for extraction in a different path than the origin files are.
* If a file/dir is already in the archive it will only be added at the
* end of the archive. There is no update of the existing archived
* file/dir. However while extracting the archive, the last file will
* replace the first one. This results in a none optimization of the
* archive size.
* If a file/dir does not exist the file/dir is ignored. However an
* error text is send to PEAR error.
* If a file/dir is not readable the file/dir is ignored. However an
* error text is send to PEAR error.
*
* @param array $p_filelist An array of filenames and directory
* names, or a single string with names
* separated by a single blank space.
* @param string $p_add_dir A string which contains a path to be
* added to the memorized path of each
* element in the list.
* @param string $p_remove_dir A string which contains a path to be
* removed from the memorized path of
* each element in the list, when
* relevant.
*
* @return true on success, false on error.
*/
public function addModify($p_filelist, $p_add_dir, $p_remove_dir = '')
{
$v_result = true;
if (!$this->_isArchive()) {
$v_result = $this->createModify(
$p_filelist,