Skip to content

Commit 79ae7a7

Browse files
Merge branch '4.4' into 5.2
* 4.4: [4.4] Add missing `@return` annotations Handle lock with long key
2 parents 26590d6 + 6ca476d commit 79ae7a7

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Lock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public function __construct(Key $key, PersistingStoreInterface $store, float $tt
4949
$this->logger = new NullLogger();
5050
}
5151

52+
/**
53+
* @return array
54+
*/
5255
public function __sleep()
5356
{
5457
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);

Store/FlockStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private function lock(Key $key, bool $read, bool $blocking)
9696
if (!$handle) {
9797
$fileName = sprintf('%s/sf.%s.%s.lock',
9898
$this->lockPath,
99-
preg_replace('/[^a-z0-9\._-]+/i', '-', $key),
99+
substr(preg_replace('/[^a-z0-9\._-]+/i', '-', $key), 0, 50),
100100
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
101101
);
102102

Tests/Store/FlockStoreTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,25 @@ public function testSaveSanitizeName()
7575

7676
$store->delete($key);
7777
}
78+
79+
public function testSaveSanitizeLongName()
80+
{
81+
$store = $this->getStore();
82+
83+
$key = new Key(str_repeat(__CLASS__, 100));
84+
85+
$file = sprintf(
86+
'%s/sf.Symfony-Component-Lock-Tests-Store-FlockStoreTestS.%s.lock',
87+
sys_get_temp_dir(),
88+
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
89+
);
90+
// ensure the file does not exist before the store
91+
@unlink($file);
92+
93+
$store->save($key);
94+
95+
$this->assertFileExists($file);
96+
97+
$store->delete($key);
98+
}
7899
}

0 commit comments

Comments
 (0)