Skip to content

Commit 0c866aa

Browse files
committed
Isolate updates in their own cache dir to avoid cache reuse issues
1 parent 242e097 commit 0c866aa

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ CDN_METADATA_PUBLIC_ENDPOINT=
2929
CDN_METADATA_API_KEY=
3030
CDN_API_KEY=
3131

32+
UPDATER_WORKER_CACHE_DIR=
33+
3234
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
3335
#TRUSTED_HOSTS='^(localhost|example\.com)$'
3436

config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ services:
4646
$fallbackGhTokens: "%fallback_gh_tokens%"
4747
$configDir: '%kernel.project_dir%/config/'
4848
$internalSecret: '%env(APP_SECRET)%'
49+
$updaterWorkerCacheDir: '%env(UPDATER_WORKER_CACHE_DIR)%'
4950

5051
# makes classes in src/ available to be used as services
5152
# this creates a service per class whose id is the fully-qualified class name

src/Service/UpdaterWorker.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function __construct(
8080
private StatsDClient $statsd,
8181
private readonly FallbackGitHubAuthProvider $fallbackGitHubAuthProvider,
8282
CacheItemPoolInterface $cache,
83+
private readonly string $updaterWorkerCacheDir,
8384
) {
8485
$this->cache = new Psr16Cache($cache);
8586
$this->logger = $logger;
@@ -130,6 +131,14 @@ public function process(Job $job, SignalHandler $signal): array
130131
$io = new BufferIO('', OutputInterface::VERBOSITY_VERY_VERBOSE, new HtmlOutputFormatter(Factory::createAdditionalStyles()));
131132
$io->loadConfiguration($config);
132133

134+
// sandbox into a unique cache dir per package id to avoid potential cache reuse issues
135+
if (trim($this->updaterWorkerCacheDir) !== '' && is_dir($this->updaterWorkerCacheDir)) {
136+
$subDir = str_pad((string)$package->getId(), 9, '0', STR_PAD_LEFT);
137+
$subDir = substr($subDir, 0, 6).'/'.$package->getId();
138+
$config->merge(['config' => ['cache-dir' => $this->updaterWorkerCacheDir.'/'.$subDir]]);
139+
unset($subDir);
140+
}
141+
133142
$usesPackagistToken = false;
134143
if (Preg::isMatch('{^https://github\.com/(?P<repo>[^/]+/[^/]+?)(?:\.git)?$}i', $package->getRepository(), $matches)) {
135144
$usesPackagistToken = true;

0 commit comments

Comments
 (0)