Searching for a Filename should be Faster than Searching *-Installed-Packages
I already mentioned reducing the number of searches in Issue #89
Some other considerations.
- The package name is unlikely to match the (package) file name because it doesn't have things like architecture and build number in it.
- Look for
*.files
first before searching*-Installed-Packages
, since the lookup speed for a single filename should be faster than a linear search of a text file (we can't actually search a text file before we look it up on the file system anyway). Also*.files
is created prior to this info being put into*-Installed-Pacakges
, so the info might not yet be in "*-Installed-Packages", when pkg is verifying whether or not a package is installed. - Avoid lookups until we require the information
The current pkg code might not make error # 1 (need to verify) but the following needs to be fixed:
[ "$check" = '' ] && check="$(find ${HOME}/.packages/ -name "$(get_pkg_filename ${PKGNAME//.$EX/.files})")"
https://gitlab.com/sc0ttj/Pkg/blob/master/usr/sbin/pkg#L838
I think what was intended was:
[ "$check" = '' ] && PKGFILENAME="$(get_pkg_filename ${PKGNAME})"
local PKGFILENAME_NO_EX="${PKGFILENAME//.$EX/}"
[ "$check" = '' ] && check="$(find ${HOME}/.packages/ -name "$PKGFILENAME_NO_EX".files -print -quit)"
https://gitlab.com/s243a/Pkg/blob/add-slack2pup_gawk&category_fix&opt/usr/sbin/pkg#L859
and I do this in my recent commit, where I played with some code optimizations (Note**I also mention this commit in Issue #89). Note that looking up the file name first might avoid a linear search of *-Installed-Packages. If you look at my trace output (line# 8242), you'll see that it shows that the function "is_installed_pkg" is called with the necessary architecture and dependency information as follows:
is_installed_pkg gimp-2.8.18-i586-1_slack14.2
after the package is installed. For this reason prior to doing the above that requires a linear search *-Installed-Packages, we should first do a fast check for *.files
. In the above mentioned commit I do this as follows:
local PKGNAME_GUESS="$(basename "$1" .$EX)" #I should of moved this line down after 821
https://gitlab.com/s243a/Pkg/blob/add-slack2pup_gawk&category_fix&opt/usr/sbin/pkg#L818
if [ -z "$EX" ]; then #$1 might not have an extension.
[ "$check" = '' ] && check="$(find ${HOME}/.packages/ -name "${PKGNAME_GUESS}.files" -print -quit)"
else
[ "$check" = '' ] && check="$(find ${HOME}/.packages/ -name "${PKGNAME_GUESS//.$EX/.files}" -print -quit)"
fi
[ "$check" = '' ] && check="$(find ${HOME}/.packages/ -name "$PKGNAME.files" -print -quit)"
https://gitlab.com/s243a/Pkg/blob/add-slack2pup_gawk&category_fix&opt/usr/sbin/pkg#L843
It occurred to me just now that the package list might have the architecture information and build number stripped off it ... or at least this is likely so if it was installed via the puppy package manager. When I installed gimp, this info wasn't stripped off the file list "gimp-2.8.18-i586-1_slack14.2.files". So for code robostness, we should try both possibilities as I do above.
Woof-Built-In packages, might have even more info stripped from the package name such as trailing numbers that are considered part of the package name rather than the version number from the perspective of the binary compatible distro. That said, It is probably not a good idea to look for these file lists that have their names stripped further, since it will cause us to loose distinctions between packages that we might want simultaneously installed on our system.
Anway, the reason that is_installed_pkg is called with architecture info and build number info is because we call, pkg_install with the filename of the package. For example:
pkg_install /root/pkg/gimp-2.8.18-i586-1_slack14.2.txz
Then later is called with this info (within the same function):
if [ "$(is_installed_pkg $PKGNAME)" = true ] && [ -s $HOME/.packages/${PKGNAME}.files ];then
https://gitlab.com/sc0ttj/Pkg/blob/master/usr/sbin/pkg#L5006