Verified Commit 38500b7d authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3527518 by phenaproxima, tim.plunkett: Package Manager's direct-write...

Issue #3527518 by phenaproxima, tim.plunkett: Package Manager's direct-write mode still tries to check for rsync

(cherry picked from commit 3b308073)
parent 18176939
Loading
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -203,8 +203,15 @@ services:
    class: PhpTuf\ComposerStager\Internal\Translation\Service\SymfonyTranslatorProxy
    public: false

  Drupal\package_manager\DirectWritePreconditionBypass:
  package_manager.direct_write_precondition.directories:
    class: Drupal\package_manager\DirectWritePreconditionBypass
    decorates: 'PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface'
    arguments:
      - '@.inner'
    public: false
  package_manager.direct_write_precondition.rsync:
    class: Drupal\package_manager\DirectWritePreconditionBypass
    decorates: 'PhpTuf\ComposerStager\API\Precondition\Service\RsyncIsAvailableInterface'
    arguments:
      - '@.inner'
    public: false
+3 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use PhpTuf\ComposerStager\API\Path\Value\PathInterface;
use PhpTuf\ComposerStager\API\Path\Value\PathListInterface;
use PhpTuf\ComposerStager\API\Precondition\Service\ActiveAndStagingDirsAreDifferentInterface;
use PhpTuf\ComposerStager\API\Precondition\Service\RsyncIsAvailableInterface;
use PhpTuf\ComposerStager\API\Process\Service\ProcessInterface;
use PhpTuf\ComposerStager\API\Translation\Value\TranslatableInterface;

@@ -22,7 +23,7 @@
 *    at any time without warning. External code should not interact with this
 *    class.
 */
final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDifferentInterface {
final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDifferentInterface, RsyncIsAvailableInterface {

  use StringTranslationTrait;

@@ -34,7 +35,7 @@ final class DirectWritePreconditionBypass implements ActiveAndStagingDirsAreDiff
  private static bool $isBypassed = FALSE;

  public function __construct(
    private readonly ActiveAndStagingDirsAreDifferentInterface $decorated,
    private readonly ActiveAndStagingDirsAreDifferentInterface|RsyncIsAvailableInterface $decorated,
  ) {}

  /**
+38 −0
Original line number Diff line number Diff line
@@ -18,12 +18,14 @@
use Drupal\package_manager\ValidationResult;
use PhpTuf\ComposerStager\API\Core\BeginnerInterface;
use PhpTuf\ComposerStager\API\Core\CommitterInterface;
use PhpTuf\ComposerStager\API\Path\Factory\PathFactoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
 * @covers \Drupal\package_manager\EventSubscriber\DirectWriteSubscriber
 * @covers \Drupal\package_manager\SandboxManagerBase::isDirectWrite
 * @covers \Drupal\package_manager\DirectWritePreconditionBypass
 *
 * @group package_manager
 */
@@ -231,4 +233,40 @@ public function testDirectWriteFlagIsLocked(): void {
    $this->assertFalse($sandbox_manager->isDirectWrite());
  }

  /**
   * Tests that direct-write bypasses certain Composer Stager preconditions.
   *
   * @param class-string $service_class
   *   The class name of the precondition service.
   *
   * @testWith ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\ActiveAndStagingDirsAreDifferentInterface"]
   *   ["PhpTuf\\ComposerStager\\API\\Precondition\\Service\\RsyncIsAvailableInterface"]
   */
  public function testPreconditionBypass(string $service_class): void {
    // Set up conditions where the active and sandbox directories are the same,
    // and the path to rsync isn't valid.
    $path = $this->container->get(PathFactoryInterface::class)
      ->create('/the/absolute/apex');
    $this->config('package_manager.settings')
      ->set('executables.rsync', "C:\Not Rsync.exe")
      ->save();

    /** @var \PhpTuf\ComposerStager\API\Precondition\Service\PreconditionInterface $precondition */
    $precondition = $this->container->get($service_class);
    // The precondition should be unfulfilled.
    $this->assertFalse($precondition->isFulfilled($path, $path));

    // Initializing a sandbox manager with direct-write support should bypass
    // the precondition.
    $this->setSetting('package_manager_allow_direct_write', TRUE);
    $sandbox_manager = $this->createStage(TestDirectWriteSandboxManager::class);
    $sandbox_manager->create();
    $this->assertTrue($sandbox_manager->isDirectWrite());

    // The precondition should be fulfilled, and clear that it's because we're
    // in direct-write mode.
    $this->assertTrue($precondition->isFulfilled($path, $path));
    $this->assertSame('This precondition has been skipped because it is not needed in direct-write mode.', (string) $precondition->getStatusMessage($path, $path));
  }

}