Browse Source

Fix lsdir crash on removed files

Assumption that paths yielded by `Path.iterdir` would always exist was
wrong. Real world example: Temporary files were disappearing during the
run leading to `lsidr` not finishing.
Benjamin Poldrack 1 year ago
parent
commit
6104340272
1 changed files with 8 additions and 3 deletions
  1. 8 3
      datalad_gooey/lsdir.py

+ 8 - 3
datalad_gooey/lsdir.py

@@ -88,7 +88,7 @@ def _list(path: Path):
         # not in a dataset
         ce = CapturedException(e)
         lgr.debug(
-            'git-ls-files failed, falling back on manual inspaction: %s',
+            'git-ls-files failed, falling back on manual inspection: %s',
             ce)
         # TODO apply standard filtering of results
         yield from _iterdir(path)
@@ -186,8 +186,13 @@ def _iterdir(path: Path):
         if c.name == '.git':
             # we do not report on this special name
             continue
-        # given that c is from iterdir, it will always exist
-        cmode = c.lstat().st_mode
+        # c could disappear while this is running. Example: temp files managed
+        # by other processes.
+        try:
+            cmode = c.lstat().st_mode
+        except FileNotFoundError as e:
+            CapturedException(e)
+            continue
         if stat.S_ISLNK(cmode):
             ctype = 'symlink'
         elif stat.S_ISDIR(cmode):