93.1. plocate-1.1.25
Finds a file by name in a prebuilt index, per user and without a setgid bit
| Version | 1.1.25, release 1 |
| Shelf | files — File managers, disk-usage analysers, duplicate finders and file locators |
| Phase | 41_system (System), 499 of 1047 in build order |
| Licence | GPL-2.0-or-later |
| Homepage | https://plocate.sesse.net/ |
| Build time | 0.2 SBU |
| Installed size | 652.9 KiB in 9 files |
| Recipe | ports/core/files/plocate/kpkgbuild |
About
plocate finds files by name in a prebuilt index rather than by walking the disk: updatedb builds the index, and locate (a link to plocate) searches it. Upstream’s design is a setgid program reading one shared index of the whole machine. KDOS keeps an index per user instead, built from that user’s home directory into their own cache, and ships the binary without a setgid bit; the pieces (kdos-updatedb, the nightly timer and the LOCATE_PATH that /etc/profile.d/40-plocate.sh exports) are described in No setgid binaries, and a per-user locate index.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/files.txt:
The same question
fdanswers, asked of an INDEX instead of the disk:fdwalks the tree every time and is right where the tree is small, and a whole-disk "where is that file called…" is the case it is slow at. The index is built PER USER and the binary carries no setgid bit — the decision, and what upstream does instead, is in docs/kdos/03-architecture/security-model.md.
Sources
plocate-1.1.25.tar.gz(74.6 KiB)
sha25668c1d5fbb11864403ae39c1a5937f13afd80b03e68041368831ef58cb613578e
upstream: https://plocate.sesse.net/download/plocate-1.1.25.tar.gz
archive copy: sources-2/files--plocate-1.1.25.tar.gz
Dependencies
Required by: no port names it.
Patches
build.sh applies these; kpkg applies nothing by itself.
locate-path-replaces-default.patch— Makes a set, non-emptyLOCATE_PATHreplace the compiled-in database,/var/lib/plocate/plocate.db, instead of being searched after it. plocate exits on the first database it cannot open, so with the default kept in front every search would fail before the user’s own index is read. A database given with-dstill takes the default’s place, andLOCATE_PATHis searched after it.musl-statx.patch— Removes#include <linux/stat.h>fromio_uring_engine.h. musl’s<sys/stat.h>, whichliburing.hincludes, already declaresstruct statxand theSTATX_*masks, so the kernel header adds a second definition and every file that includesio_uring_engine.hfails to compile.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install plocate'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/files/plocate.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/files/plocate
echo '68c1d5fbb11864403ae39c1a5937f13afd80b03e68041368831ef58cb613578e plocate-1.1.25.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/plocate
SRC=$SRC_ROOT/plocate-1.1.25
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf plocate-1.1.25.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xzf "$PORT_SRC/${name}-${version}.tar.gz"
patch -p1 -i "$PORT_SRC/musl-statx.patch"
patch -p1 -i "$PORT_SRC/locate-path-replaces-default.patch"
meson setup build --buildtype=release \
--prefix=/usr --sysconfdir=/etc --libdir=lib \
--localstatedir=/var \
-Dinstall_systemd=false \
-Dinstall_cron=false
meson compile -C build
DESTDIR=$PKG meson install --no-rebuild -C build
chmod 0755 "$PKG/usr/bin/plocate"
ln -s plocate "$PKG/usr/bin/locate"
rm -rf "$PKG/var/lib/plocate"
rmdir --ignore-fail-on-non-empty "$PKG/var/lib" 2>/dev/null || true
The switches, and why each is set:
-Dinstall_systemd=false— Install no systemd service and timer forupdatedb. Upstream’s default is on, and installs them when it finds systemd; KDOS has no systemd, and the per-user index is rebuilt by a session timer.-Dinstall_cron=false— Install no/etc/cron.daily/plocatescript (it converts an mlocate database). Off is also upstream’s default.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/plocate, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf plocate-1.1.25-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/plocate, and runs the triggers its paths call for.
Contents
Installed programs: locate, plocate, plocate-build, updatedb.
Installed directories: /usr/share/licenses/plocate.
Short descriptions
plocate |
find files by name, post-haste |
plocate-build |
generate index for plocate |
updatedb |
update a database for plocate |
Notes
The release tarball is flat, with no wrapping directory, so the top-level strip kpkg applies to a first source would leave no meson.build; build.sh unpacks the tarball again into $SRC itself (see Sources, and what each one becomes).
meson install installs plocate mode rwxr-sr-x, group plocate, and an install script creates /var/lib/plocate with a CACHEDIR.TAG in it. build.sh resets the binary to 0755 and deletes the directory afterwards: the image carries no setgid file and no plocate group, and a shared database directory would hold nothing. With no plocate group, kdos-updatedb must pass --require-visibility no: with the visibility check on, updatedb looks the group up, prints Unknown group plocate and exits without writing an index.
plocate uses io_uring through liburing when meson finds it, and is built without it otherwise, with no error; the depends line is what guarantees it.