@@ -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,28 +257,24 @@ private function authenticate()
255257 */
256258 private function extractMetaDataFromTreeInfo (array $ tree , $ path , $ recursive )
257259 {
258- if (empty ($ path ) === false ) {
259- $ metadata = array_filter ($ tree , function ($ entry ) use ($ path , $ recursive ) {
260- $ match = false ;
261-
262- if (strpos ($ entry [self ::KEY_PATH ], $ path ) === 0 ) {
263- if ($ recursive === true ) {
264- $ match = true ;
265- } else {
266- $ length = strlen ($ path );
267- $ match = (strpos ($ entry [self ::KEY_PATH ], '/ ' , $ length ) === false );
268- }
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 );
269273 }
274+ }
270275
271- return $ match ;
272- });
273- } elseif ($ recursive === false ) {
274- $ metadata = array_filter ($ tree , function ($ entry ) use ($ path ) {
275- return (strpos ($ entry [self ::KEY_PATH ], '/ ' , strlen ($ path )) === false );
276- });
277- } else {
278- $ metadata = $ tree ;
279- }
276+ return $ match ;
277+ });
280278
281279 return $ metadata ;
282280 }
0 commit comments