andrewgregory / pacutils

Helper library for libalpm based programs.
MIT License
107 stars 17 forks source link

Check the symlink itself, not the target of the symlink. Fixes issue #52 #53

Closed VorpalBlade closed 2 years ago

VorpalBlade commented 2 years ago

Switch to using lstat() instead of access(). This fixes the issue of incorrectly reporting an installed broken symlink as a missing file.

This can be triggered during normal operation by java-runtime-common, java-environment-common etc, as not all java version provides all binaries.

See also issue #52

I checked the performance impact of this, and there is basically none. If anything it is slightly faster:

$ # Old version (access)
$ time src/pacreport --missing-files > /dev/null
user=0,59s system=0,51s cpu=99% total=1,107
$ time src/pacreport --missing-files > /dev/null
user=0,61s system=0,50s cpu=99% total=1,116
$ time src/pacreport --missing-files > /dev/null
user=0,63s system=0,49s cpu=99% total=1,123
$ time src/pacreport --missing-files > /dev/null
user=0,62s system=0,50s cpu=99% total=1,115

$ # New version (lstat)
$ time src/pacreport --missing-files > /dev/null
user=0,62s system=0,44s cpu=99% total=1,063
$ time src/pacreport --missing-files > /dev/null
user=0,65s system=0,41s cpu=99% total=1,062
$ time src/pacreport --missing-files > /dev/null
user=0,62s system=0,43s cpu=99% total=1,053
$ time src/pacreport --missing-files > /dev/null
user=0,63s system=0,43s cpu=99% total=1,062

It is not clear to me why it would be faster, other than having to output less lines (since the false positive java results are gone).

I have tested that the new version still correctly reports actually missing files (including cases where the symlink itself is missing).

andrewgregory commented 2 years ago

Edited to print a warning on failures other than ENOENT and merged manually.