8000 [Cache] Make directory hashing case insensitive by nicolas-grekas · Pull Request #20453 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Make directory hashing case insensitive #20453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Cache] Make directory hashing case insensitive
  • Loading branch information
nicolas-grekas committed Nov 9, 2016
commit 6d4a658ab7a6860f1106565aa1d97f004d37dd56
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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