Skip directories in zip generation, empty dirs won't get archived
This seems ok as we currently rely on git generating archives which does not archive empty directories either.pull/1567/head
parent
deae50392f
commit
6066359944
|
@ -25,7 +25,7 @@ use Symfony\Component\Finder;
|
||||||
*
|
*
|
||||||
* @author Nils Adermann <naderman@naderman.de>
|
* @author Nils Adermann <naderman@naderman.de>
|
||||||
*/
|
*/
|
||||||
class ArchivableFilesFinder
|
class ArchivableFilesFinder extends \IteratorIterator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Symfony\Component\Finder\Finder
|
* @var Symfony\Component\Finder\Finder
|
||||||
|
@ -66,13 +66,24 @@ class ArchivableFilesFinder
|
||||||
})
|
})
|
||||||
->ignoreVCS(true)
|
->ignoreVCS(true)
|
||||||
->ignoreDotFiles(false);
|
->ignoreDotFiles(false);
|
||||||
|
|
||||||
|
parent::__construct($this->finder->getIterator());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function next()
|
||||||
* @return Symfony\Component\Finder\Finder
|
|
||||||
*/
|
|
||||||
public function getIterator()
|
|
||||||
{
|
{
|
||||||
return $this->finder->getIterator();
|
do {
|
||||||
|
$this->getInnerIterator()->next();
|
||||||
|
} while ($this->getInnerIterator()->valid() && $this->getInnerIterator()->current()->isDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function current()
|
||||||
|
{
|
||||||
|
return $this->getInnerIterator()->current();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function valid()
|
||||||
|
{
|
||||||
|
return $this->getInnerIterator()->valid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class PharArchiver implements ArchiverInterface
|
||||||
try {
|
try {
|
||||||
$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->getIterator(), $sources);
|
$phar->buildFromIterator($files, $sources);
|
||||||
return $target;
|
return $target;
|
||||||
} catch (\UnexpectedValueException $e) {
|
} catch (\UnexpectedValueException $e) {
|
||||||
$message = sprintf("Could not create archive '%s' from '%s': %s",
|
$message = sprintf("Could not create archive '%s' from '%s': %s",
|
||||||
|
|
|
@ -169,7 +169,7 @@ class ArchivableFilesFinderTest extends \PHPUnit_Framework_TestCase
|
||||||
protected function getArchivableFiles()
|
protected function getArchivableFiles()
|
||||||
{
|
{
|
||||||
$files = array();
|
$files = array();
|
||||||
foreach ($this->finder->getIterator() as $file) {
|
foreach ($this->finder as $file) {
|
||||||
if (!$file->isDir()) {
|
if (!$file->isDir()) {
|
||||||
$files[] = preg_replace('#^'.preg_quote($this->sources, '#').'#', '', $file->getRealPath());
|
$files[] = preg_replace('#^'.preg_quote($this->sources, '#').'#', '', $file->getRealPath());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue