Skip to content
Snippets Groups Projects
Commit f545e70a authored by Sergei Trofimovich's avatar Sergei Trofimovich
Browse files

file: don't crash when hashing directory symlinks

Noticed the crash today when tried to compare glibc directories:

    $ diffoscope /nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/ /nix/store/bsin40d5wph9yr28rrd0j0zq6qm6982s-glibc-2.39-52/
      File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/directory.py", line 280, in compare
        differences.extend(my_container.compare(other_container))
      File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/container.py", line 164, in comparisons
        for my_name, other_name, score in self.perform_fuzzy_matching(
      File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/fuzzy.py", line 45, in perform_fuzzy_matching
        if file1.is_directory() or not file1.fuzzy_hash:
                                       ^^^^^^^^^^^^^^^^
      File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/file.py", line 380, in fuzzy_hash
        self._fuzzy_hash = calc()
                           ^^^^^^
      File "...-diffoscope-276/lib/python3.12/site-packages/diffoscope/comparators/utils/file.py", line 368, in calc
        with open(self.path, "rb") as f:
             ^^^^^^^^^^^^^^^^^^^^^
    IsADirectoryError: [Errno 21] Is a directory: '/nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/lib64'

It looks like `diffoscope` was confused by a symlink to a directory:

    $ ls -l /nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/lib64
    lrwxrwxrwx 907 root root 3 Jan  1  1970 /nix/store/shybiq9nx8j3sp3ax2gb6c4lni1djabl-glibc-2.39-52/lib64 -> lib

THe change ignores `IsADirectoryError` for this case.
parent 8878f55d
No related branches found
No related tags found
1 merge request!144file: don't crash when hashing directory symlinks
Pipeline #721505 passed
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment