Skip to content

Commit e83cd62

Browse files
authored
fix: follow symlinks (#353)
- Correct symlink navigation by enabling the follow-symlinks action only for symlink entries and resolving their targets safely, including broken links.
1 parent 3c047e5 commit e83cd62

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/rovr/core/file_list_right_click_menu.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ def give_me_an_option(
108108
case "rovr:follow_symlinks":
109109
return PartialOption(
110110
id="follow_symlinks",
111-
disabled=app.file_list.highlighted_option is None or no_items,
111+
disabled=not (
112+
hasattr(app.file_list.highlighted_option, "dir_entry")
113+
and app.file_list.highlighted_option.dir_entry.is_symlink()
114+
),
112115
)
113116
case "system:copy_highlighted":
114117
return PartialOption(id="copy_highlighted", disabled=no_items)
@@ -245,20 +248,24 @@ async def on_option_list_option_selected(
245248
highlighted = self.app.file_list.highlighted_option
246249
if highlighted is None:
247250
return
248-
resolved_path = os.path.realpath(highlighted.dir_entry.path)
249-
if not os.path.exists(resolved_path):
251+
try:
252+
resolved_path = os.readlink(highlighted.dir_entry.path)
253+
except OSError:
254+
return
255+
if not os.path.lexists(resolved_path):
250256
self.notify(
251257
f"Path {resolved_path} does not exist\nTaking you to the closest parent directory",
252258
severity="warning",
253259
)
260+
is_real_dir = os.path.isdir(resolved_path) and not os.path.islink(resolved_path)
254261

255262
self.call_next(
256263
self.app.cd,
257264
resolved_path
258-
if highlighted.dir_entry.is_dir()
265+
if is_real_dir
259266
else os.path.dirname(resolved_path),
260267
focus_on=None
261-
if highlighted.dir_entry.is_dir()
268+
if is_real_dir
262269
else os.path.basename(resolved_path),
263270
)
264271
elif hasattr(self.app.file_list, f"action_{event.option.id}"):

0 commit comments

Comments
 (0)