1
0

0.4.27-18-g7229954.fix-dont-raise-filenotfoundexception-on-symlinks.patch 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Subject: Fix: Don't raise FileNotFoundException on symlinks
  2. Origin: upstream, commit 0.4.27-18-g7229954 <https://github.com/ahupp/python-magic/commit/0.4.27-18-g7229954>
  3. Author: Marten Ringwelski <git@maringuu.de>
  4. Date: Wed Aug 23 22:17:30 2023 +0200
  5. The builtin `open` will always follow symlinks.
  6. Using `os.stat` is the easiest solution imo.
  7. An alternative would be using `os.access` but that does not raise
  8. a FileNotFoundException so I chose `os.stat`.
  9. --- a/magic/__init__.py
  10. +++ b/magic/__init__.py
  11. @@ -17,6 +17,7 @@
  12. """
  13. import sys
  14. +import os
  15. import glob
  16. import ctypes
  17. import ctypes.util
  18. @@ -25,9 +26,6 @@
  19. from ctypes import c_char_p, c_int, c_size_t, c_void_p, byref, POINTER
  20. -# avoid shadowing the real open with the version from compat.py
  21. -_real_open = open
  22. -
  23. class MagicException(Exception):
  24. def __init__(self, message):
  25. @@ -109,8 +107,7 @@
  26. def from_file(self, filename):
  27. # raise FileNotFoundException or IOError if the file does not exist
  28. - with _real_open(filename):
  29. - pass
  30. + os.stat(filename, follow_symlinks=self.flags & MAGIC_SYMLINK)
  31. with self.lock:
  32. try: