1
0
Fork 0

Merge pull request #5208 from ktomk/patch-9

Support empty directories with tar-files, closes #5206
pull/5195/merge
Jordi Boggiano 2016-04-18 09:29:00 +01:00
commit 398feb3c90
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]); $phar = new \PharData($target, null, null, static::$formats[$format]);
$files = new ArchivableFilesFinder($sources, $excludes); $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])) { if (isset(static::$compressFormats[$format])) {
// Check can be compressed? // Check can be compressed?