File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments