1
0
Fork 0

Support empty directories with tar-files, closes #5206

- Report: #5206

- Ref: 8389b4b
pull/5208/head
Tom Klingenberg 2016-04-18 00:24:44 +02:00
parent 76350676b5
commit 73d04bf28b
2 changed files with 47 additions and 1 deletions

View File

@ -0,0 +1,44 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Package\Archiver;
use FilterIterator;
use PharData;
class ArchivableFilesFilter extends FilterIterator
{
private $dirs = array();
/**
* @return bool true if the current element is acceptable, otherwise false.
*/
public function accept()
{
$file = $this->getInnerIterator()->current();
if ($file->isDir()) {
$this->dirs[] = (string)$file;
return false;
}
return true;
}
public function addEmptyDir(PharData $phar, $sources)
{
foreach ($this->dirs as $filepath) {
$localname = str_replace($sources . "/", '', $filepath);
$phar->addEmptyDir($localname);
}
}
}

View File

@ -54,7 +54,9 @@ class PharArchiver implements ArchiverInterface
$phar = new \PharData($target, null, null, static::$formats[$format]);
$files = new ArchivableFilesFinder($sources, $excludes);
$phar->buildFromIterator($files, $sources);
$filesOnly = new ArchivableFilesFilter($files);
$phar->buildFromIterator($filesOnly, $sources);
$filesOnly->addEmptyDir($phar, $sources);
if (isset(static::$compressFormats[$format])) {
// Check can be compressed?