While using the ArchiverManager Service to create a ZIP file, I stumbled across the /Drupal/Core/Archiver/Zip.php which doesn't support flags for ZipArchiver. These flags are usefull to tell ZipArchiver to create the file if it doesn't exist.

public function __construct($file_path) {
    $this->zip = new \ZipArchive();
    // this returned true for me
    // $test = $this->zip->open($file_path, \ZipArchive::CREATE);
    if ($this->zip->open($file_path) !== TRUE) {
      throw new ArchiverException(t('Cannot open %file_path', ['%file_path' => $file_path]));

Proposed resolution

There seems to be a possibility within the ArchiveManager when creating the Archiver Instance..

  public function createInstance($plugin_id, array $configuration = []) {
    $plugin_definition = $this->getDefinition($plugin_id);
    $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition, 'Drupal\Core\Archiver\ArchiverInterface');
    return new $plugin_class($configuration['filepath']);

the $configuration variables 'filepath' is all what gets used, so maybe there can something be passed along to the Zip Archiver.

Remaining tasks

User interface changes

API changes

Data model changes

Members fund testing for the Drupal project. Drupal Association Learn more


vierlex created an issue. See original summary.

nanak’s picture

Version: 8.3.6 » 8.5.x-dev
Status: Active » Needs review
3.42 KB

The attached patch updates the ArchiverManager by passing a configuration array to the plugin (Zip or Tar) instead of the filepath only. Zips can now receive a flag to use when the open() method is called in the constructor, and Tar can receive the compression format. Both parameters are still optional.

nanak’s picture

Status: Needs review » Needs work

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.