ranger / ranger

A VIM-inspired filemanager for the console
https://ranger.fm
GNU General Public License v3.0
15.54k stars 890 forks source link

ranger sometimes crashes when switching to a tab whose directory is now unavailable #2993

Open vejkse opened 3 months ago

vejkse commented 3 months ago

Runtime Environment

Current Behavior

ranger crashes in various circumstances when going to a tab whose directory has become inaccessible.

There was already https://github.com/ranger/ranger/issues/2873 that applies only when update_title is set to true. There are two pull requests solving that issue.

I found two new methods to crash ranger when going to an unavailable tab in ranger --clean, without having to set any option.

Expected Behavior

ranger should not crash but signal that the directory is not available.

First steps to reproduce

  1. Open ranger in some directory (e.g. /tmp).
  2. Create a subdirectory a in that directory, e.g. by running :mkdir a.
  3. Open a second tab and browse to the new subdirectory a.
  4. Go back to the first tab.
  5. Rename the subdirectory a to b, e.g. by running :rename b on it.
  6. Go back to the second tab.
  7. Ranger crashes.

Second steps to reproduce

  1. Mount a drive.
  2. Open a new ranger tab in that drive.
  3. Go back to the other tab.
  4. Unmount the drive.
  5. Go back to the tab in the now unaccessible drive. It says ‘not available’, without crashing.
  6. Remount the same drive, while staying in that tab.
  7. Ranger crashes.

Traceback

The traceback is identical in both cases.


ranger version: ranger-master
Python version: 3.11.8 (main, Feb 12 2024, 14:50:05) [GCC 13.2.1 20230801]
Locale: en_US.UTF-8

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/ranger/core/main.py", line 214, in main
    fm.loop()
  File "/usr/lib/python3.11/site-packages/ranger/core/fm.py", line 417, in loop
    ui.redraw()
  File "/usr/lib/python3.11/site-packages/ranger/gui/ui.py", line 343, in redraw
    self.draw()
  File "/usr/lib/python3.11/site-packages/ranger/gui/ui.py", line 370, in draw
    DisplayableContainer.draw(self)
  File "/usr/lib/python3.11/site-packages/ranger/gui/displayable.py", line 268, in draw
    displayable.draw()
  File "/usr/lib/python3.11/site-packages/ranger/gui/widgets/statusbar.py", line 110, in draw
    self._calc_bar()
  File "/usr/lib/python3.11/site-packages/ranger/gui/widgets/statusbar.py", line 116, in _calc_bar
    self._get_right_part(bar)
  File "/usr/lib/python3.11/site-packages/ranger/gui/widgets/statusbar.py", line 268, in _get_right_part
    if self.fm.thisdir.flat:
       ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'flat'
vejkse commented 3 months ago

So, I ‘fixed’ this by adding a check before a bunch of three tests in statusbar.py which are using self.fm.thisdir.

if self.fm.thisdir:

But this doesn’t seem very robust.

I think I never experienced such crashes (including #2873) before 2023. Maybe before that time, when a directory was unavailable, self.fm.thisdir was a placeholder object instead of None, preventing those crashes?