Skip to content

Commit d2c9d91

Browse files
committed
Updated some outdated code from filepath generator in IOHelper.
1 parent 51d686e commit d2c9d91

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected function getFilePath($keyword, $skip = false): string
100100
);
101101
}
102102

103-
return $path . '/' . $filename . '.' . $this->getConfig()->getCacheFileExtension();
103+
return $path . \DIRECTORY_SEPARATOR . $filename . '.' . $this->getConfig()->getCacheFileExtension();
104104
}
105105

106106
/**
@@ -322,7 +322,7 @@ protected function readFile($file): string
322322
* @return bool
323323
* @throws PhpfastcacheIOException
324324
*/
325-
protected function writefile($file, $data, $secureFileManipulation = false): bool
325+
protected function writefile(string $file, string $data, bool $secureFileManipulation = false): bool
326326
{
327327
/**
328328
* @eventName CacheWriteFileOnDisk
@@ -335,11 +335,10 @@ protected function writefile($file, $data, $secureFileManipulation = false): boo
335335

336336
if ($secureFileManipulation) {
337337
$tmpFilename = Directory::getAbsolutePath(
338-
dirname($file) . '/tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()(
339-
\str_shuffle(\uniqid($this->getDriverName(), false))
340-
. \str_shuffle(\uniqid($this->getDriverName(), false))
338+
dirname($file) . \DIRECTORY_SEPARATOR . 'tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()(
339+
\bin2hex(\random_bytes(16))
341340
)
342-
);
341+
) . '.' . $this->getConfig()->getCacheFileExtension() . \random_int(1000, 9999);
343342

344343
$handle = \fopen($tmpFilename, 'w+b');
345344
if (\is_resource($handle)) {

tests/ReadWriteOperations.test.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040

4141
$instances[ $dirIndex ][ $cacheInstanceName ] = CacheManager::getInstance('Files', new FilesConfig([
4242
'path' => $dir . str_pad($i, 3, '0', STR_PAD_LEFT),
43-
'secureFileManipulation' => true
43+
'secureFileManipulation' => true,
44+
'securityKey' => '_cache',
4445
]));
4546

4647
foreach ($keys[ $dirIndex ] as $index => $key) {
@@ -75,4 +76,4 @@
7576
}
7677
}
7778

78-
$testHelper->terminateTest();
79+
$testHelper->terminateTest();

0 commit comments

Comments
 (0)