Skip to content

Commit

Permalink
Add tool beeindextr
Browse files Browse the repository at this point in the history
The bee inventory file `/var/cache/bee/beecache/INVENTORY` contains the
filenames of the files installed from bee.

One problem is, that a file can have more than one name name because of
symlinks. For example, we currently have a symlink `/usr/doc ->
share/doc` and the inventory currently contains this entry:

   cunit-2.1_3-1.x86_64 1619448799 0 0 0100644 683 7eb1686ef4ebac0f4743c407da5aab52 /usr/doc/CUnit/CUnit_doc.css

So the file is not registerd by its canonical name
`/usr/share/doc/CUnit/CUnit_doc.css` but by the alias name
`/usr/doc/CUnit/CUnit_doc.css`. This can happen, if a package is
installed "through" a symlink in the system.

The problem with multiple paths to the same file is, that if one version
of a package installes a file through one path and another version of a
package installs the same file though another path, then the file is
lost after "bee update".

This is because, all files from the old package, which are not
registered by the new version of the same packahe (or any another
installed package) are removed.  While the removal works through a
symlink, the protection by its single registered ilename does not.

To mitigate this problem, bee should protect the file itself during
certain operations like `bee update`, not just the name variant used in
the inventory.

We want to achive this by translating the directory names used in the
inventory to their canonical form (if possible).

In this patch, add a filter tool for the bee index format, which translates
the filenames into a canonical form using above caching strategy.

Don't just use realpath(3) or canonicalize_file_name(3) for that,
because this would be much to slow. These functions do readlink() for
every path component of the provided name. As we have to do this for
every file of the inventory, the system call usage and file system
access would explode. Processing the inventory file this way, took more
than two minutes.

Instead, cache the results of readlink for a single invocation of the
tool, so that the operation is done only once per file. Use another
cache for complete translated path names to reduce the load to the
readlink-cache. This way, the same result can be achived in 0.3 seconds.

    $ ls -ld /usr/doc
    lrwxrwxrwx 1 root root 9 Mar  7  2011 /usr/doc -> share/doc
    $ grep CUnit_doc.css /var/cache/bee/bee-cache/INVENTORY
    cunit-2.1_3-1.x86_64 1619448799 0 0 0100644 683 7eb1686ef4ebac0f4743c407da5aab52 /usr/doc/CUnit/CUnit_doc.css
    $ ./beeindextr /var/cache/bee/bee-cache/INVENTORY | grep CUnit_doc.css
    cunit-2.1_3-1.x86_64 1619448799 0 0 0100644 683 7eb1686ef4ebac0f4743c407da5aab52 /usr/share/doc/CUnit/CUnit_doc.css
  • Loading branch information
donald committed Oct 24, 2023
1 parent 3090258 commit ccc5348
Show file tree
Hide file tree
Showing 2 changed files with 478 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PROGRAMS_C+=beesep
PROGRAMS_C+=beesort
PROGRAMS_C+=beeuniq
PROGRAMS_C+=beeversion
PROGRAMS_C+=beeindextr

PROGRAMS_SHELL+=bee
PROGRAMS_SHELL+=beefind
Expand Down Expand Up @@ -134,6 +135,7 @@ BEESORT_OBJECTS=bee_tree.o bee_version_compare.o bee_version_output.o bee_versio
BEEGETOPT_OBJECTS=bee_getopt.o beegetopt.o
BEEFLOCK_OBJECTS=bee_getopt.o beeflock.o
BEECACHEINVENTORY_OBJECTS=bee-cache-inventory.o bee_getopt.o
BEEICANONDIRS_OBJECTS=beeindextr.o

bee_BUILDTYPES=$(addsuffix .sh,$(addprefix buildtypes/,$(BUILDTYPES)))

Expand Down Expand Up @@ -166,6 +168,9 @@ beeflock: $(addprefix src/, ${BEEFLOCK_OBJECTS})
bee-cache-inventory: $(addprefix src/, ${BEECACHEINVENTORY_OBJECTS})
$(call quiet-command,${CC} ${LDFLAGS} -o $@ $^,"LD $@")

beeindextr: $(addprefix src/, ${BEEICANONDIRS_OBJECTS})
$(call quiet-command,${CC} ${LDFLAGS} -o $@ $^,"LD $@")

%.o: %.c
$(call quiet-command,${CC} ${CFLAGS} -o $@ -c $^,"CC $@")

Expand Down
Loading

0 comments on commit ccc5348

Please sign in to comment.