Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a0d0c22

Browse filesBrowse files
committed
bug #42212 [Lock] Handle lock with long key (jderusse)
This PR was merged into the 4.4 branch. Discussion ---------- [Lock] Handle lock with long key | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When lock key is very long, the generated file exceeded the maximum length supported by the system, leading to an exception `fopen(/tmp/sf.username_xxxxxxxx[...].d3rUs2a.lock): Failed to open stream: File name too long` Commits ------- f826824 Handle lock with long key
2 parents a7642f7 + f826824 commit a0d0c22
Copy full SHA for a0d0c22

File tree

Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-1
lines changed

‎src/Symfony/Component/Lock/Store/FlockStore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Store/FlockStore.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private function lock(Key $key, bool $blocking)
7474

7575
$fileName = sprintf('%s/sf.%s.%s.lock',
7676
$this->lockPath,
77-
preg_replace('/[^a-z0-9\._-]+/i', '-', $key),
77+
substr(preg_replace('/[^a-z0-9\._-]+/i', '-', $key), 0, 50),
7878
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
7979
);
8080

‎src/Symfony/Component/Lock/Tests/Store/FlockStoreTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Tests/Store/FlockStoreTest.php
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,25 @@ public function testSaveSanitizeName()
7373

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.