From 747396b26cf492ab4b974a96690a89777d6b590f Mon Sep 17 00:00:00 2001 From: Gyubong Date: Fri, 27 Oct 2023 17:39:08 +0900 Subject: [PATCH 1/6] Fix symbolic link loop error --- src/ai/backend/storage/vfs/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ai/backend/storage/vfs/__init__.py b/src/ai/backend/storage/vfs/__init__.py index df5da39430..709854da0f 100644 --- a/src/ai/backend/storage/vfs/__init__.py +++ b/src/ai/backend/storage/vfs/__init__.py @@ -251,21 +251,27 @@ def _scandir(target_path: Path, q: janus._SyncQueueProxy[Sentinel | DirEntry]) - break symlink_target = "" entry_type = DirEntryType.FILE + try: - if entry.is_dir(): + if entry.is_dir(follow_symlinks=False): entry_type = DirEntryType.DIRECTORY if entry.is_symlink(): entry_type = DirEntryType.SYMLINK - symlink_dst = Path(entry).resolve() + try: + symlink_dst = Path(entry).resolve() symlink_dst = symlink_dst.relative_to(target_path) - except ValueError: + except RuntimeError: + # ValueError and ELOOP pass - symlink_target = os.fsdecode(symlink_dst) + else: + symlink_target = os.fsdecode(symlink_dst) + entry_stat = entry.stat(follow_symlinks=False) except (FileNotFoundError, PermissionError): # the filesystem may be changed during scan continue + item = DirEntry( name=entry.name, path=Path(entry.path).relative_to(target_path), From 052be9479ca041564840472f86a7f4a9df38cbd4 Mon Sep 17 00:00:00 2001 From: Gyubong Date: Fri, 27 Oct 2023 17:42:47 +0900 Subject: [PATCH 2/6] Create new fragment --- changes/1665.fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1665.fix.md diff --git a/changes/1665.fix.md b/changes/1665.fix.md new file mode 100644 index 0000000000..eea9b93206 --- /dev/null +++ b/changes/1665.fix.md @@ -0,0 +1 @@ +Fix symbolic link loop error of vfolder From 77b4fec8de489f00ec5af53e920a695306ef8797 Mon Sep 17 00:00:00 2001 From: Gyubong Date: Fri, 27 Oct 2023 17:44:25 +0900 Subject: [PATCH 3/6] Remove useless newline --- src/ai/backend/storage/vfs/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ai/backend/storage/vfs/__init__.py b/src/ai/backend/storage/vfs/__init__.py index 709854da0f..3e3f5674b1 100644 --- a/src/ai/backend/storage/vfs/__init__.py +++ b/src/ai/backend/storage/vfs/__init__.py @@ -251,7 +251,6 @@ def _scandir(target_path: Path, q: janus._SyncQueueProxy[Sentinel | DirEntry]) - break symlink_target = "" entry_type = DirEntryType.FILE - try: if entry.is_dir(follow_symlinks=False): entry_type = DirEntryType.DIRECTORY @@ -266,12 +265,10 @@ def _scandir(target_path: Path, q: janus._SyncQueueProxy[Sentinel | DirEntry]) - pass else: symlink_target = os.fsdecode(symlink_dst) - entry_stat = entry.stat(follow_symlinks=False) except (FileNotFoundError, PermissionError): # the filesystem may be changed during scan continue - item = DirEntry( name=entry.name, path=Path(entry.path).relative_to(target_path), From e96981f204886166b3011b1c871946f773f80a82 Mon Sep 17 00:00:00 2001 From: Gyubong Date: Fri, 27 Oct 2023 19:13:16 +0900 Subject: [PATCH 4/6] Add missing ValueError handling --- src/ai/backend/storage/vfs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ai/backend/storage/vfs/__init__.py b/src/ai/backend/storage/vfs/__init__.py index 3e3f5674b1..d65224344e 100644 --- a/src/ai/backend/storage/vfs/__init__.py +++ b/src/ai/backend/storage/vfs/__init__.py @@ -260,7 +260,7 @@ def _scandir(target_path: Path, q: janus._SyncQueueProxy[Sentinel | DirEntry]) - try: symlink_dst = Path(entry).resolve() symlink_dst = symlink_dst.relative_to(target_path) - except RuntimeError: + except (ValueError, RuntimeError): # ValueError and ELOOP pass else: From e33d0d0ba7076eada45691db6654591b0e1117af Mon Sep 17 00:00:00 2001 From: Kyujin Cho Date: Mon, 30 Oct 2023 15:18:32 +0900 Subject: [PATCH 5/6] apply safety measure to netapp backend also --- src/ai/backend/storage/netapp/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ai/backend/storage/netapp/__init__.py b/src/ai/backend/storage/netapp/__init__.py index 856b23b3b0..9dc304104f 100644 --- a/src/ai/backend/storage/netapp/__init__.py +++ b/src/ai/backend/storage/netapp/__init__.py @@ -261,12 +261,13 @@ async def read_stdout() -> None: entry_type = DirEntryType.FILE symlink_target = "" if entry_type == DirEntryType.SYMLINK: - symlink_dst = Path(item_abspath).resolve() try: + symlink_dst = Path(item_abspath).resolve() symlink_dst = symlink_dst.relative_to(target_path) - except ValueError: + except (ValueError, RuntimeError): pass - symlink_target = os.fsdecode(symlink_dst) + else: + symlink_target = os.fsdecode(symlink_dst) await entry_queue.put( DirEntry( name=item_path.name, From 2bf2651ab38d4d96d4c8b580e7a44ba290f4aa42 Mon Sep 17 00:00:00 2001 From: Kyujin Cho Date: Mon, 30 Oct 2023 15:21:16 +0900 Subject: [PATCH 6/6] remove blank line --- src/ai/backend/storage/vfs/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ai/backend/storage/vfs/__init__.py b/src/ai/backend/storage/vfs/__init__.py index d65224344e..508c4d0194 100644 --- a/src/ai/backend/storage/vfs/__init__.py +++ b/src/ai/backend/storage/vfs/__init__.py @@ -256,7 +256,6 @@ def _scandir(target_path: Path, q: janus._SyncQueueProxy[Sentinel | DirEntry]) - entry_type = DirEntryType.DIRECTORY if entry.is_symlink(): entry_type = DirEntryType.SYMLINK - try: symlink_dst = Path(entry).resolve() symlink_dst = symlink_dst.relative_to(target_path)