@@ -197,6 +197,8 @@ final public function getRecursiveMetadata($path, $recursive)
197197 $ recursive
198198 );
199199
200+ $ path = rtrim ($ path , '/ ' ) . '/ ' ;
201+
200202 $ treeMetadata = $ this ->extractMetaDataFromTreeInfo ($ info [self ::KEY_TREE ], $ path , $ recursive );
201203
202204 return $ this ->normalizeTreeMetadata ($ treeMetadata );
@@ -255,29 +257,24 @@ private function authenticate()
255257 */
256258 private function extractMetaDataFromTreeInfo (array $ tree , $ path , $ recursive )
257259 {
258- if (empty ($ path ) === false ) {
259- $ path = rtrim ($ path , '/ ' ) . '/ ' ;
260- $ metadata = array_filter ($ tree , function ($ entry ) use ($ path , $ recursive ) {
261- $ match = false ;
262-
263- if (strpos ($ entry [self ::KEY_PATH ], $ path ) === 0 ) {
264- if ($ recursive === true ) {
265- $ match = true ;
266- } else {
267- $ length = strlen ($ path );
268- $ match = (strpos ($ entry [self ::KEY_PATH ], '/ ' , $ length ) === false );
269- }
260+ $ matchPath = substr ($ path , 0 , -1 );
261+ $ length = strlen ($ matchPath ) - 1 ;
262+
263+ $ metadata = array_filter ($ tree , function ($ entry ) use ($ matchPath , $ recursive , $ length ) {
264+ $ match = false ;
265+
266+ $ entryPath = $ entry [self ::KEY_PATH ];
267+
268+ if ($ matchPath === '' || strpos ($ entryPath , $ matchPath ) === 0 ) {
269+ if ($ recursive === true ) {
270+ $ match = true ;
271+ } else {
272+ $ match = ($ matchPath !== '' && strpos ($ entryPath , '/ ' , $ length ) === false );
270273 }
274+ }
271275
272- return $ match ;
273- });
274- } elseif ($ recursive === false ) {
275- $ metadata = array_filter ($ tree , function ($ entry ) use ($ path ) {
276- return (strpos ($ entry [self ::KEY_PATH ], '/ ' , strlen ($ path )) === false );
277- });
278- } else {
279- $ metadata = $ tree ;
280- }
276+ return $ match ;
277+ });
281278
282279 return $ metadata ;
283280 }
0 commit comments