Skip to content
Snippets Groups Projects
Commit 56b95009 authored by Lucas Hedding's avatar Lucas Hedding Committed by Lucas Hedding
Browse files

Issue #3087190 by heddn: Move ignored_paths external to ModifiedFiles service

parent 4a7ed908
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\automatic_updates;
/**
* Provides an iterator filter for file paths which are ignored.
*/
class IgnoredPathsIteratorFilter extends \FilterIterator {
use IgnoredPathsTrait;
/**
* {@inheritdoc}
*/
public function accept() {
return !$this->isIgnoredPath($this->current());
}
}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\automatic_updates\ReadinessChecker; namespace Drupal\automatic_updates\ReadinessChecker;
use Drupal\automatic_updates\IgnoredPathsIteratorFilter;
use Drupal\automatic_updates\ProjectInfoTrait; use Drupal\automatic_updates\ProjectInfoTrait;
use Drupal\automatic_updates\Services\ModifiedFilesInterface; use Drupal\automatic_updates\Services\ModifiedFilesInterface;
use Drupal\Core\Extension\ExtensionList; use Drupal\Core\Extension\ExtensionList;
...@@ -92,7 +93,8 @@ class ModifiedFiles implements ReadinessCheckerInterface { ...@@ -92,7 +93,8 @@ class ModifiedFiles implements ReadinessCheckerInterface {
} }
} }
} }
foreach ($this->modifiedFiles->getModifiedFiles($extensions) as $file) { $filtered_modified_files = new IgnoredPathsIteratorFilter($this->modifiedFiles->getModifiedFiles($extensions));
foreach ($filtered_modified_files as $file) {
$messages[] = $this->t('The hash for @file does not match its original. Updates that include that file will fail and require manual intervention.', ['@file' => $file]); $messages[] = $this->t('The hash for @file does not match its original. Updates that include that file will fail and require manual intervention.', ['@file' => $file]);
} }
return $messages; return $messages;
......
...@@ -74,13 +74,13 @@ class ModifiedFiles implements ModifiedFilesInterface { ...@@ -74,13 +74,13 @@ class ModifiedFiles implements ModifiedFilesInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getModifiedFiles(array $extensions = []) { public function getModifiedFiles(array $extensions = []) {
$modified_files = []; $modified_files = new \ArrayIterator();
/** @var \GuzzleHttp\Promise\PromiseInterface[] $promises */ /** @var \GuzzleHttp\Promise\PromiseInterface[] $promises */
$promises = $this->getHashRequests($extensions); $promises = $this->getHashRequests($extensions);
// Wait until all the requests are finished. // Wait until all the requests are finished.
(new EachPromise($promises, [ (new EachPromise($promises, [
'concurrency' => 4, 'concurrency' => 4,
'fulfilled' => function ($resource) use (&$modified_files) { 'fulfilled' => function ($resource) use ($modified_files) {
$this->processHashes($resource, $modified_files); $this->processHashes($resource, $modified_files);
}, },
]))->promise()->wait(); ]))->promise()->wait();
...@@ -92,10 +92,10 @@ class ModifiedFiles implements ModifiedFilesInterface { ...@@ -92,10 +92,10 @@ class ModifiedFiles implements ModifiedFilesInterface {
* *
* @param array $resource * @param array $resource
* An array of http response and project info. * An array of http response and project info.
* @param array $modified_files * @param \ArrayIterator $modified_files
* The list of modified files. * The list of modified files.
*/ */
protected function processHashes(array $resource, array &$modified_files) { protected function processHashes(array $resource, \ArrayIterator $modified_files) {
$contents = $resource['contents']; $contents = $resource['contents'];
$info = $resource['info']; $info = $resource['info'];
$directory_root = $info['install path']; $directory_root = $info['install path'];
...@@ -112,16 +112,13 @@ class ModifiedFiles implements ModifiedFilesInterface { ...@@ -112,16 +112,13 @@ class ModifiedFiles implements ModifiedFilesInterface {
$directory_root, $directory_root,
$failed_checksum->filename, $failed_checksum->filename,
])); ]));
if ($this->isIgnoredPath($file_path)) {
continue;
}
if (!file_exists($file_path)) { if (!file_exists($file_path)) {
$modified_files[] = $file_path; $modified_files->append($file_path);
continue; continue;
} }
$actual_hash = @hash_file(strtolower($failed_checksum->algorithm), $file_path); $actual_hash = @hash_file(strtolower($failed_checksum->algorithm), $file_path);
if ($actual_hash === FALSE || empty($actual_hash) || strlen($actual_hash) < 64 || strcmp($actual_hash, $failed_checksum->hex_hash) !== 0) { if ($actual_hash === FALSE || empty($actual_hash) || strlen($actual_hash) < 64 || strcmp($actual_hash, $failed_checksum->hex_hash) !== 0) {
$modified_files[] = $file_path; $modified_files->append($file_path);
} }
} }
} }
......
...@@ -14,7 +14,7 @@ interface ModifiedFilesInterface { ...@@ -14,7 +14,7 @@ interface ModifiedFilesInterface {
* The list of extensions, keyed by extension name with values an info * The list of extensions, keyed by extension name with values an info
* array. * array.
* *
* @return array * @return \Iterator
* The modified files. * The modified files.
*/ */
public function getModifiedFiles(array $extensions = []); public function getModifiedFiles(array $extensions = []);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\test_automatic_updates\Controller; namespace Drupal\test_automatic_updates\Controller;
use Drupal\automatic_updates\IgnoredPathsIteratorFilter;
use Drupal\automatic_updates\ProjectInfoTrait; use Drupal\automatic_updates\ProjectInfoTrait;
use Drupal\automatic_updates\Services\ModifiedFilesInterface; use Drupal\automatic_updates\Services\ModifiedFilesInterface;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
...@@ -68,9 +69,9 @@ class ModifiedFilesController extends ControllerBase { ...@@ -68,9 +69,9 @@ class ModifiedFilesController extends ControllerBase {
} }
$response = Response::create('No modified files!'); $response = Response::create('No modified files!');
$messages = $this->modifiedFiles->getModifiedFiles($extensions); $filtered_modified_files = new IgnoredPathsIteratorFilter($this->modifiedFiles->getModifiedFiles($extensions));
if (!empty($messages)) { if (iterator_count($filtered_modified_files)) {
$response->setContent('Modified files include: ' . implode(', ', $messages)); $response->setContent('Modified files include: ' . implode(', ', iterator_to_array($filtered_modified_files)));
} }
return $response; return $response;
} }
......
...@@ -61,7 +61,7 @@ class InPlaceUpdateTest extends QuickStartTestBase { ...@@ -61,7 +61,7 @@ class InPlaceUpdateTest extends QuickStartTestBase {
$fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000);
$this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction');
$this->assertErrorOutputContains('Generating autoload files'); $this->assertErrorOutputContains('Generating autoload files');
$this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer require ocramius/package-versions:^1.4 webflo/drupal-finder:^1.1 composer/semver:^1.0 --no-interaction'); $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer require ocramius/package-versions:^1.4 webflo/drupal-finder:^1.1 composer/semver:^1.0 drupal/php-signify:^1.0@dev --no-interaction');
$this->assertErrorOutputContains('Generating autoload files'); $this->assertErrorOutputContains('Generating autoload files');
$this->installQuickStart('minimal'); $this->installQuickStart('minimal');
...@@ -120,7 +120,7 @@ class InPlaceUpdateTest extends QuickStartTestBase { ...@@ -120,7 +120,7 @@ class InPlaceUpdateTest extends QuickStartTestBase {
$fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000);
$this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction');
$this->assertErrorOutputContains('Generating autoload files'); $this->assertErrorOutputContains('Generating autoload files');
$this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer require ocramius/package-versions:^1.4 webflo/drupal-finder:^1.1 composer/semver:^1.0 --no-interaction'); $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer require ocramius/package-versions:^1.4 webflo/drupal-finder:^1.1 composer/semver:^1.0 drupal/php-signify:^1.0@dev --no-interaction');
$this->assertErrorOutputContains('Generating autoload files'); $this->assertErrorOutputContains('Generating autoload files');
$this->installQuickStart('standard'); $this->installQuickStart('standard');
......
...@@ -114,7 +114,6 @@ class ModifiedFilesTest extends QuickStartTestBase { ...@@ -114,7 +114,6 @@ class ModifiedFilesTest extends QuickStartTestBase {
* The modified files to assert. * The modified files to assert.
*/ */
protected function assertModifications($project_type, $project, array $modifications) { protected function assertModifications($project_type, $project, array $modifications) {
$this->destroyBuild = FALSE;
$this->symfonyFileSystem->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); $this->symfonyFileSystem->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000);
$this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction');
$this->assertErrorOutputContains('Generating autoload files'); $this->assertErrorOutputContains('Generating autoload files');
......
...@@ -28,7 +28,7 @@ class ModifiedFilesTest extends KernelTestBase { ...@@ -28,7 +28,7 @@ class ModifiedFilesTest extends KernelTestBase {
public function testModifiedFiles() { public function testModifiedFiles() {
/** @var \Prophecy\Prophecy\ObjectProphecy|\Drupal\automatic_updates\Services\ModifiedFilesInterface $service */ /** @var \Prophecy\Prophecy\ObjectProphecy|\Drupal\automatic_updates\Services\ModifiedFilesInterface $service */
$service = $this->prophesize(ModifiedFilesInterface::class); $service = $this->prophesize(ModifiedFilesInterface::class);
$service->getModifiedFiles(Argument::type('array'))->willReturn([]); $service->getModifiedFiles(Argument::type('array'))->willReturn(new \ArrayIterator());
$modules = $this->container->get('extension.list.module'); $modules = $this->container->get('extension.list.module');
$profiles = $this->container->get('extension.list.profile'); $profiles = $this->container->get('extension.list.profile');
$themes = $this->container->get('extension.list.theme'); $themes = $this->container->get('extension.list.theme');
...@@ -44,7 +44,7 @@ class ModifiedFilesTest extends KernelTestBase { ...@@ -44,7 +44,7 @@ class ModifiedFilesTest extends KernelTestBase {
$this->assertEmpty($messages); $this->assertEmpty($messages);
// Hash doesn't match i.e. modified code. // Hash doesn't match i.e. modified code.
$service->getModifiedFiles(Argument::type('array'))->willReturn(['core/LICENSE.txt']); $service->getModifiedFiles(Argument::type('array'))->willReturn(new \ArrayIterator(['core/LICENSE.txt']));
$messages = $modified_files->run(); $messages = $modified_files->run();
$this->assertCount(1, $messages); $this->assertCount(1, $messages);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment