1
0
Fork 0

Skip non-empty directories in zip generation

Empty dirs get archived (leafs).

Previously it seemed ok to skip all directories in zip generation.

References:

- Ref: 6066359944

- Issue: #4865 Keep empty folders after re-zip a module
pull/5144/head
Tom Klingenberg 2016-04-02 20:50:20 +02:00
parent b2b4603215
commit 8389b4b829
2 changed files with 16 additions and 2 deletions

View File

@ -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();
} }
} }

View File

@ -37,8 +37,12 @@ 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);
if ($file->isDir()) {
$zip->addEmptyDir($localname);
} else {
$zip->addFile($filepath, $localname); $zip->addFile($filepath, $localname);
} }
}
if ($zip->close()) { if ($zip->close()) {
return $target; return $target;
} }