I have a setup script written in Python (on Linux) that runs as root and needs to check if certain files are read by a non-root user.
For this reason, I cannot use os.path.exists () or open (filename) (and catch any exceptions).
I'm currently going to check the permission bits on each file, but the only problem is that I have to check the permission bits in the path leading to the file name (directories need r + x bits set), which can be a very slow process if I have thousands of files.
Is my solution the best, or are there better alternatives?
edit: I need the script to run as root after checking the files, so giving up root privileges is not unfortunately.
source share