Skip to content

Commit

Permalink
Lock: Use temp by internal detection for safe run across environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Aug 22, 2021
1 parent b1037d2 commit d21bc9f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/PackageRegistrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Baraja\Console\Helpers as ConsoleHelpers;
use Baraja\Lock\Lock;
use Baraja\Lock\Transaction\FileTransactionProvider;
use Baraja\PackageManager\Composer\TaskManager;
use Baraja\PackageManager\Exception\PackageDescriptorException;
use Baraja\PathResolvers\Resolvers\RootDirResolver;
Expand Down Expand Up @@ -35,6 +36,7 @@ class PackageRegistrator implements TerminatorHandler
public function __construct(?string $rootDir = null, ?string $tempDir = null)
{
if (PHP_SAPI !== 'cli') {
self::setupInternalLock($tempDir);
Lock::wait(self::MAINTENANCE_LOCK, maxExecutionTimeMs: 120000, ttl: 50000);
}
static $created = false;
Expand Down Expand Up @@ -116,6 +118,7 @@ final public function processTerminatorHandler(): void
*/
public static function composerPostAutoloadDump(): void
{
self::setupInternalLock();
if (PHP_SAPI !== 'cli') {
throw new \RuntimeException('PackageRegistrator: Composer action can be called only in CLI environment.');
}
Expand Down Expand Up @@ -261,6 +264,15 @@ public static function getPackageDescriptorEntityStatic(): PackageDescriptorEnti
}


private static function setupInternalLock(?string $tempDir = null): void
{
if ($tempDir === null) {
$tempDir = (new TempDirResolver(new RootDirResolver(new VendorResolver)))->get();
}
Lock::setTransactionProvider(new FileTransactionProvider($tempDir . '/cache/lock/package-manager'));
}


public function getProjectRoot(): string
{
return self::$projectRoot;
Expand Down

0 comments on commit d21bc9f

Please sign in to comment.