Skip to content

magic.from_file(file) generate "File Not Found" exception when file is a linux (symbolic) link #336

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
Madpentiste opened this issue Oct 31, 2024 · 1 comment

Comments

@Madpentiste
Copy link

On a Linux/Ubuntu platform, if file is a symbolic link, magic.from_file(file) will throw a FileNotFoundError, instead of detecting that file is a link (inode/symlink).

So far, the only workaround I found is to embed the code containing the magic.from_file(file) line into a try/except block, and catch the exception.

@ddelange
Copy link
Contributor

ddelange commented Dec 10, 2024

the upcoming release adds support:

import magic
magic.Magic(follow_symlinks=True).from_file(file)

you can already install it from source using:

python-magic@https://github.com/ahupp/python-magic/archive/refs/heads/master.zip

in your requirements.txt, or install from wheel using:

export PIP_FIND_LINKS=https://github.com/ddelange/python-magic/releases/expanded_assets/0.4.28.post8
pip install --force-reinstall python-magic

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants