Skip to content

Commit

Permalink
check MTIME instead of relying on env var
Browse files Browse the repository at this point in the history
ker@d ~/github/PHP-CS-Fixer λ ./php-cs-fixer list-files --config=.php-cs-fixer.dist.php | xargs -n 400 -P 3 ./php-cs-fixer fix --config=.php-cs-fixer.dist.php --path-mode intersection
Loaded config default from .php-cs-fixer.dist.php.
Using cache file .php-cs-fixer.cache.
Loaded config default from .php-cs-fixer.dist.php.
Using cache file .php-cs-fixer.cache.
Loaded config default from .php-cs-fixer.dist.php.
Using cache file .php-cs-fixer.cache.
string(34)
  • Loading branch information
keradus committed Jul 14, 2023
1 parent e06771d commit 2aef0f8
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/Cache/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ final class FileHandler implements FileHandlerInterface
{
private string $file;

private int $fileLastModification = 0;

public function __construct(string $file)
{
$this->file = $file;
Expand All @@ -47,7 +49,8 @@ public function read(): ?CacheInterface
}

$cache = $this->readFromHandle($handle);

$this->fileLastModification = $this->getFileLastUpdate($handle);
var_dump("\n".getmypid().' !!! FRS !!! READ '.$this->fileLastModification);
fclose($handle);

return $cache;
Expand All @@ -62,23 +65,43 @@ public function write(CacheInterface $cache): void
return;
}

if (getenv('PHP_CS_FIXER_EXPERIMENTAL_PARALLEL_CACHE')) {
$actualLastModification = $this->getFileLastUpdate($handle);

var_dump("\n".getmypid().' !!! FRS !!! DECISION ???');
var_dump([
'property' => $this->fileLastModification,
'os' => $actualLastModification,
'should backfill' => $this->fileLastModification < $actualLastModification,
]);

if ($this->fileLastModification < $actualLastModification) {
flock($handle, LOCK_EX);

$oldCache = $this->readFromHandle($handle);
rewind($handle);

if ($oldCache && method_exists($cache, 'backfillHashes')) {

Check failure on line 83 in src/Cache/FileHandler.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (ubuntu-20.04, 8.1)

Only booleans are allowed in &&, PhpCsFixer\Cache\CacheInterface|null given on the left side.
var_dump("\n".getmypid().' !!! FRS !!! BACKFILL');
$cache->backfillHashes($oldCache);
}
}

var_dump("\n".getmypid().' !!! FRS !!! SAVE FILE');
ftruncate($handle, 0);
fwrite($handle, $cache->toJson());
fflush($handle);
fsync($handle);

var_dump("\n".getmypid().' !!! FRS !!! AFTER SAVE '.$this->getFileLastUpdate($handle));
fclose($handle);
}

private function getFileLastUpdate($handle): int

Check failure on line 98 in src/Cache/FileHandler.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (ubuntu-20.04, 8.1)

Method PhpCsFixer\Cache\FileHandler::getFileLastUpdate() has parameter $handle with no type specified.
{
clearstatcache(true, $this->file);

return fstat($handle)['mtime'] ?: 0;

Check failure on line 102 in src/Cache/FileHandler.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (ubuntu-20.04, 8.1)

Short ternary operator is not allowed. Use null coalesce operator if applicable or consider using long ternary.
}

/**
* @param resource $handle
*/
Expand Down

0 comments on commit 2aef0f8

Please sign in to comment.