Skip to content

Commit abeddc0

Browse files
committed
Merge pull request #753 from bshaffer/issue-574
fixes #574 - checks for cachedir trailing slash
2 parents 404bdbb + 9ce5849 commit abeddc0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Google/Cache/File.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ private function getCacheDir($file, $forWrite)
151151
// use the first 2 characters of the hash as a directory prefix
152152
// this should prevent slowdowns due to huge directory listings
153153
// and thus give some basic amount of scalability
154-
$storageDir = $this->path . '/' . substr(md5($file), 0, 2);
154+
$dirHash = substr(md5($file), 0, 2);
155+
// trim the directory separator from the path to prevent double separators
156+
$storageDir = rtrim($this->path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $dirHash;
155157
if ($forWrite && ! is_dir($storageDir)) {
156158
if (! mkdir($storageDir, 0700, true)) {
157159
$this->log(

tests/Google/CacheTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public function testFile()
3030
$this->getSetDelete($cache);
3131
}
3232

33+
public function testFileWithTrailingSlash()
34+
{
35+
$dir = sys_get_temp_dir() . '/google-api-php-client/tests/';
36+
$cache = new Google_Cache_File($dir);
37+
$cache->set('foo', 'bar');
38+
$this->assertEquals($cache->get('foo'), 'bar');
39+
40+
$this->getSetDelete($cache);
41+
}
42+
3343
public function testNull()
3444
{
3545
$cache = new Google_Cache_Null();

0 commit comments

Comments
 (0)