summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2023-04-18 14:57:58 +0200
committerawerebea <awerebea.21@gmail.com>2023-04-18 14:57:58 +0200
commitaf9c5893e99a7e8e545bd48f84fc60f8a6942b27 (patch)
treef3a6e740c5282b83cbb9e81281329d91e6ef73ec
parent7a1f783ebba6351d371ed52c433605a98afb8729 (diff)
main: Refactor to avoid TOCTOU
-rw-r--r--ranger/core/main.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 11f194c1..7c765c25 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -166,10 +166,10 @@ def main(
# Remove dead entries if this behavior is defined in settings
if fm.settings.filter_dead_tabs_on_startup:
fm.start_paths = list(filter(os.path.isdir, fm.start_paths))
- if startup_path not in fm.start_paths:
- fm.start_paths.insert(0, startup_path)
- else:
+ try:
startup_path_tab_index = fm.start_paths.index(startup_path)
+ except ValueError:
+ fm.start_paths.insert(0, startup_path)
if tabs_saved[-1]:
with open(tabs_datapath, 'w', encoding="utf-8") as fobj:
fobj.write(tabs_saved[-1])