Skip to content
Permalink
Browse files

bug #20453 [Cache] Make directory hashing case insensitive (nicolas-g…

…rekas)

This PR was merged into the 3.1 branch.

Discussion
----------

[Cache] Make directory hashing case insensitive

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20450
| License       | MIT
| Doc PR        | -

Fixes this situation: a Windows OS, running a Debian via VirtualBox and Vagrant. So the cache folder is on a Windows partition while the PHP command is running inside Debian...

Not testable without this specific setup...

Commits
-------

6d4a658 [Cache] Make directory hashing case insensitive
  • Loading branch information...
fabpot committed Nov 9, 2016
2 parents 790e7dd + 6d4a658 commit a524ba5e77c4f2a5932626330995773a8ef21732
@@ -84,7 +84,7 @@ public function process(ContainerBuilder $container)
private function getNamespace($namespaceSuffix, $id)
{
return substr(str_replace('/', '-', base64_encode(md5($id.$namespaceSuffix, true))), 0, 10);
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$namespaceSuffix, true))), 0, 10);
}
/**
@@ -1037,7 +1037,7 @@ private function registerPropertyInfoConfiguration(array $config, ContainerBuild
private function registerCacheConfiguration(array $config, ContainerBuilder $container)
{
$version = substr(str_replace('/', '-', base64_encode(md5(uniqid(mt_rand(), true), true))), 0, -2);
$version = substr(str_replace('/', '-', base64_encode(hash('sha256', uniqid(mt_rand(), true), true))), 0, 22);
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
$container->getDefinition('cache.adapter.filesystem')->replaceArgument(2, $config['directory']);
@@ -41,7 +41,7 @@ public function testNamespaceArgumentIsReplaced()
$this->cachePoolPass->process($container);
$this->assertSame('VcRIZlUhEv', $cachePool->getArgument(0));
$this->assertSame('kRFqMp5odS', $cachePool->getArgument(0));
}
public function testArgsAreReplaced()
@@ -61,7 +61,7 @@ public function testArgsAreReplaced()
$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
$this->assertSame('VcRIZlUhEv', $cachePool->getArgument(1));
$this->assertSame('kRFqMp5odS', $cachePool->getArgument(1));
$this->assertSame(3, $cachePool->getArgument(2));
}
@@ -146,13 +146,13 @@ protected function doSave(array $values, $lifetime)
private function getFile($id, $mkdir = false)
{
$hash = str_replace('/', '-', base64_encode(md5($id, true)));
$dir = $this->directory.$hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR;
$hash = str_replace('/', '-', base64_encode(hash('sha256', $id, true)));
$dir = $this->directory.strtoupper($hash[0].DIRECTORY_SEPARATOR.$hash[1].DIRECTORY_SEPARATOR);
if ($mkdir && !file_exists($dir)) {
@mkdir($dir, 0777, true);
}
return $dir.substr($hash, 2, -2);
return $dir.substr($hash, 2, 20);
}
}

0 comments on commit a524ba5

Please sign in to comment.
You can’t perform that action at this time.