diff --git a/src/Composer/Package/Archiver/ArchivableFilesFilter.php b/src/Composer/Package/Archiver/ArchivableFilesFilter.php new file mode 100644 index 000000000..0eda18bad --- /dev/null +++ b/src/Composer/Package/Archiver/ArchivableFilesFilter.php @@ -0,0 +1,44 @@ + + * Jordi Boggiano + * + * 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); + } + } +} diff --git a/src/Composer/Package/Archiver/PharArchiver.php b/src/Composer/Package/Archiver/PharArchiver.php index c14e7bd9d..5c9afe336 100644 --- a/src/Composer/Package/Archiver/PharArchiver.php +++ b/src/Composer/Package/Archiver/PharArchiver.php @@ -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?