From fab07c6329e61987a853f993ceaec222aa14f9d2 Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Tue, 21 Nov 2023 19:14:57 +0100 Subject: [PATCH 1/2] fix common path in _ls_tree --- src/huggingface_hub/hf_file_system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py index 6a1eb5392e..878a01909f 100644 --- a/src/huggingface_hub/hf_file_system.py +++ b/src/huggingface_hub/hf_file_system.py @@ -323,7 +323,7 @@ def _ls_tree( # Get the parent directory if the common prefix itself is not a directory common_path = ( common_prefix.rstrip("/") - if common_prefix.endswith("/") or common_prefix == root_path + if common_prefix.endswith("/") or common_prefix == root_path or common_prefix in (dirs_not_in_dircache + dirs_not_expanded) else self._parent(common_prefix) ) out = [o for o in out if not o["name"].startswith(common_path + "/")] From f87f38037fd70d3b8dc1eabdcb09bafe4bf6b1b6 Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Tue, 21 Nov 2023 19:16:10 +0100 Subject: [PATCH 2/2] style --- src/huggingface_hub/hf_file_system.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/hf_file_system.py b/src/huggingface_hub/hf_file_system.py index 878a01909f..807771555c 100644 --- a/src/huggingface_hub/hf_file_system.py +++ b/src/huggingface_hub/hf_file_system.py @@ -4,6 +4,7 @@ from collections import deque from dataclasses import dataclass from datetime import datetime +from itertools import chain from typing import Any, Dict, List, NoReturn, Optional, Tuple, Union from urllib.parse import quote, unquote @@ -323,7 +324,9 @@ def _ls_tree( # Get the parent directory if the common prefix itself is not a directory common_path = ( common_prefix.rstrip("/") - if common_prefix.endswith("/") or common_prefix == root_path or common_prefix in (dirs_not_in_dircache + dirs_not_expanded) + if common_prefix.endswith("/") + or common_prefix == root_path + or common_prefix in chain(dirs_not_in_dircache, dirs_not_expanded) else self._parent(common_prefix) ) out = [o for o in out if not o["name"].startswith(common_path + "/")]