Skip to content
Snippets Groups Projects

Issue #3266092: Make sure staging root is unique for each Drupal site

Files
7
@@ -5,6 +5,7 @@ namespace Drupal\package_manager;
@@ -5,6 +5,7 @@ namespace Drupal\package_manager;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\FileSystem\FileSystem;
use Drupal\Component\FileSystem\FileSystem;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Crypt;
 
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\TempStore\SharedTempStoreFactory;
use Drupal\Core\TempStore\SharedTempStoreFactory;
@@ -66,6 +67,13 @@ class Stage {
@@ -66,6 +67,13 @@ class Stage {
*/
*/
private const TEMPSTORE_APPLY_TIME_KEY = 'apply_time';
private const TEMPSTORE_APPLY_TIME_KEY = 'apply_time';
 
/**
 
* The config factory service.
 
*
 
* @var \Drupal\Core\Config\ConfigFactoryInterface
 
*/
 
protected $configFactory;
 
/**
/**
* The path locator service.
* The path locator service.
*
*
@@ -134,6 +142,8 @@ class Stage {
@@ -134,6 +142,8 @@ class Stage {
/**
/**
* Constructs a new Stage object.
* Constructs a new Stage object.
*
*
 
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
 
* The config factory service.
* @param \Drupal\package_manager\PathLocator $path_locator
* @param \Drupal\package_manager\PathLocator $path_locator
* The path locator service.
* The path locator service.
* @param \PhpTuf\ComposerStager\Domain\BeginnerInterface $beginner
* @param \PhpTuf\ComposerStager\Domain\BeginnerInterface $beginner
@@ -151,7 +161,8 @@ class Stage {
@@ -151,7 +161,8 @@ class Stage {
* @param \Drupal\Component\Datetime\TimeInterface $time
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* The time service.
*/
*/
public function __construct(PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $shared_tempstore, TimeInterface $time) {
public function __construct(ConfigFactoryInterface $config_factory, PathLocator $path_locator, BeginnerInterface $beginner, StagerInterface $stager, CommitterInterface $committer, FileSystemInterface $file_system, EventDispatcherInterface $event_dispatcher, SharedTempStoreFactory $shared_tempstore, TimeInterface $time) {
 
$this->configFactory = $config_factory;
$this->pathLocator = $path_locator;
$this->pathLocator = $path_locator;
$this->beginner = $beginner;
$this->beginner = $beginner;
$this->stager = $stager;
$this->stager = $stager;
@@ -498,25 +509,32 @@ class Stage {
@@ -498,25 +509,32 @@ class Stage {
*
*
* @throws \LogicException
* @throws \LogicException
* If this method is called before the stage has been created or claimed.
* If this method is called before the stage has been created or claimed.
*
* @todo Make this method public in https://www.drupal.org/i/3251972.
*/
*/
public function getStageDirectory(): string {
public function getStageDirectory(): string {
if (!$this->lock) {
if (!$this->lock) {
throw new \LogicException(__METHOD__ . '() cannot be called because the stage has not been created or claimed.');
throw new \LogicException(__METHOD__ . '() cannot be called because the stage has not been created or claimed.');
}
}
return static::getStagingRoot() . DIRECTORY_SEPARATOR . $this->lock[0];
return $this->getStagingRoot() . DIRECTORY_SEPARATOR . $this->lock[0];
}
}
/**
/**
* Returns the directory where staging areas will be created.
* Returns the directory where staging areas will be created.
*
*
 
* The staging area is created in the system temporary directory. All staging
 
* areas created by the current site are kept in a subdirectory identified by
 
* the site's UUID, and then in another subdirectory with a randomly generated
 
* name. For example: /tmp/.package_managerSITE_UUID/RANDOM_NAME. This ensures
 
* that no staging area created by another user in the current site, or by
 
* another site in the current Drupal code base, will be performing file
 
* system operations in the same place at the same time.
 
*
* @return string
* @return string
* The absolute path of the directory containing the staging areas managed
* The absolute path of the directory containing the staging areas managed
* by this class.
* by this class.
*/
*/
protected static function getStagingRoot(): string {
protected function getStagingRoot(): string {
return FileSystem::getOsTemporaryDirectory() . DIRECTORY_SEPARATOR . '.package_manager';
$site_id = $this->configFactory->get('system.site')->get('uuid');
 
return FileSystem::getOsTemporaryDirectory() . DIRECTORY_SEPARATOR . '.package_manager' . $site_id;
}
}
}
}
Loading