Adding support for custom user data (notes etc) via %xdata% field
Hi all, Is this something pacman devs would be interested in adding to pacman? I found myself wanting such a feature a couple of times in the past, and after a recent reddit post I tried to make it a thing https://github.com/vixfwis/pacman https://github.com/vixfwis/pacman-xdata Common use case - adding and searching for user notes in installed packages. Those notes would be inside the %XDATA% field in localdb. My current implementation has a simple --xdata <key>=<value> param for -S-U operations, which is then added to the current transaction packages in sync_prepare_execute. As well as -Q --xdata-search <regex> param, which allows for searching. Changes affect pacman and libalpm, although no existing exported libalpm functions were changed What do you think?
On 10/5/24 20:27, vixfwis wrote:
Hi all,
Is this something pacman devs would be interested in adding to pacman? I found myself wanting such a feature a couple of times in the past, and after a recent reddit post I tried to make it a thing
https://github.com/vixfwis/pacman <https://github.com/vixfwis/pacman> https://github.com/vixfwis/pacman-xdata <https://github.com/vixfwis/pacman-xdata>
Common use case - adding and searching for user notes in installed packages. Those notes would be inside the %XDATA% field in localdb. My current implementation has a simple --xdata <key>=<value> param for -S-U operations, which is then added to the current transaction packages in sync_prepare_execute. As well as -Q --xdata-search <regex> param, which allows for searching. Changes affect pacman and libalpm, although no existing exported libalpm functions were changed
What do you think?
I am OK with this idea. Some immediate thoughts: 1) On -S operations, should notes be added to all packages installed or only those specifically mentioned on the command line. I think the latter (but potential interesting interaction with group selection?) 2) only user notes should be transferred across package upgrades. If a package file has an xdata field for one release and not the next, it should not be transferred. Does pacman need to add a "user:" prefix to the xdata to handle this? 2b) should notes with a "user:" prefix be printed with -Qi and not just -Qii? 3) we need a way to delete notes. -D seems the best place for this (and for adding notes to already installed packages). Allan
On Sun, May 12, 2024 at 5:19 AM Allan McRae <allan@archlinux.org> wrote:
I am OK with this idea.
Some immediate thoughts:
1) On -S operations, should notes be added to all packages installed or only those specifically mentioned on the command line. I think the latter (but potential interesting interaction with group selection?)
2) only user notes should be transferred across package upgrades. If a package file has an xdata field for one release and not the next, it should not be transferred. Does pacman need to add a "user:" prefix to the xdata to handle this?
2b) should notes with a "user:" prefix be printed with -Qi and not just -Qii?
3) we need a way to delete notes. -D seems the best place for this (and for adding notes to already installed packages).
Allan
1) Good point. I moved notes code before dependency resolution, that way it's only added to packages from CLI, without dependencies. Group resolution happens even before that, so there are no extra interactions. 2) Added "user:" prefix for user keys. Currently it's local on the latest git commit, but I later moved it to global const, it's needed not only in sync code. I have some working code with global user prefix kept inside pacman, but it's causing issues and duplicate code in other places, so I think I'll move it to libalpm and rewrite the public interface for user-notes. Alternatively, keep user-notes to be a pacman-specific thing, move key/value operations to util.c and have only a generic xdata interface in libalpm. Thoughts? 2b) Yes, with a print-out like "User Data: note=user note". I want to keep key=value format, with additional pacman param for common case (i.e. --note <note> and --note-extra <key>=<value>) -Qii will still print "Extended Data", without hiding "user:" prefix Also, I'm adding extra print-out for -Q search if there are notes to search for. Currently pacman can't do --info and --search, so, without rewriting that bit, seems like the easiest way to show matching note 3) -D operations, in progress. I need either a more generic function to update DESC pkg data, or a smaller one specifically for xdata field. There isn't much to take example from, only 1 public function alpm_pkg_set_reason, which immediately writes to localdb.
I've updated https://github.com/vixfwis/pacman (and https://github.com/vixfwis/pacman-xdata/blob/main/xdata.patch, all changes from 6.1.0-3), with my latest usernotes code. I've also modified pactest.py to account for %XDATA% and added tests for user notes. All tests are passing, no valgrind leaks. Please take a look and let me know what you think new pacman notes interface: -S/-U --note <note> --note-extra <key>=<value> (default user note key is "note") -Q --note-search <regex> (will print notes if used) -D --delete-note <key> --note <note> --note-extra <key>=<value> -Qi will print "User Notes" field new libalpm exported functions: alpm_db_search_usernote alpm_get_userdata_prefix alpm_pkg_user_notes_update alpm_pkg_user_notes_delete alpm_pkg_xdata_free alpm_pkg_parse_xdata alpm_pkg_set_user_notes
participants (2)
-
Allan McRae
-
vixfwis