Просмотр исходного кода

Improve error handling when trying to remove non-empty directory

Some systems might raise errno.EEXIST rather than errno.ENOTEMPTY when trying to remove a non-empty directory with os.rmdir.
Jakub Kulík 2 месяцев назад
Родитель
Сommit
a68fe10cc2
1 измененных файлов с 2 добавлено и 2 удалено
  1. 2 2
      dulwich/index.py

+ 2 - 2
dulwich/index.py

@@ -2125,7 +2125,7 @@ def _remove_empty_parents(path: bytes, stop_at: bytes) -> None:
             # Directory doesn't exist - stop trying
             # Directory doesn't exist - stop trying
             break
             break
         except OSError as e:
         except OSError as e:
-            if e.errno == errno.ENOTEMPTY:
+            if e.errno in (errno.ENOTEMPTY, errno.EEXIST):
                 # Directory not empty - stop trying
                 # Directory not empty - stop trying
                 break
                 break
             raise
             raise
@@ -2314,7 +2314,7 @@ def _transition_to_file(
             try:
             try:
                 os.rmdir(full_path)
                 os.rmdir(full_path)
             except OSError as e:
             except OSError as e:
-                if e.errno == errno.ENOTEMPTY:
+                if e.errno in (errno.ENOTEMPTY, errno.EEXIST):
                     raise IsADirectoryError(
                     raise IsADirectoryError(
                         f"Cannot replace non-empty directory with file: {full_path!r}"
                         f"Cannot replace non-empty directory with file: {full_path!r}"
                     )
                     )