Merge pull request #5144 from ktomk/patch-6
Skip non-empty directories in zip generationpull/5150/head
commit
bc1d92aeee
|
@ -13,7 +13,9 @@
|
||||||
namespace Composer\Package\Archiver;
|
namespace Composer\Package\Archiver;
|
||||||
|
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
|
use FilesystemIterator;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Symfony Finder wrapper which locates files that should go into archives
|
* A Symfony Finder wrapper which locates files that should go into archives
|
||||||
|
@ -84,6 +86,14 @@ class ArchivableFilesFinder extends \FilterIterator
|
||||||
|
|
||||||
public function accept()
|
public function accept()
|
||||||
{
|
{
|
||||||
return !$this->getInnerIterator()->current()->isDir();
|
/** @var SplFileInfo $current */
|
||||||
|
$current = $this->getInnerIterator()->current();
|
||||||
|
|
||||||
|
if (!$current->isDir()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$iterator = new FilesystemIterator($current, FilesystemIterator::SKIP_DOTS);
|
||||||
|
return !$iterator->valid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,11 @@ class ZipArchiver implements ArchiverInterface
|
||||||
/** @var $file \SplFileInfo */
|
/** @var $file \SplFileInfo */
|
||||||
$filepath = $file->getPath()."/".$file->getFilename();
|
$filepath = $file->getPath()."/".$file->getFilename();
|
||||||
$localname = str_replace($sources."/", '', $filepath);
|
$localname = str_replace($sources."/", '', $filepath);
|
||||||
$zip->addFile($filepath, $localname);
|
if ($file->isDir()) {
|
||||||
|
$zip->addEmptyDir($localname);
|
||||||
|
} else {
|
||||||
|
$zip->addFile($filepath, $localname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($zip->close()) {
|
if ($zip->close()) {
|
||||||
return $target;
|
return $target;
|
||||||
|
|
Loading…
Reference in New Issue