Rpm filetriggers
From Mandriva Community Wiki
Contents |
[edit] Introduction
Filetriggers allow to run some scripts when some file has been added or removed.
The typical use cases are:
- updating /etc/ld.so.cache when some libraries have been added/removed in /usr/lib or /lib
- running update-menus to update menus of non-XDG compliant desktops when some *.desktop have been added/removed in /usr/share/applications
[edit] Usage
Add the following to your macros to enable filetriggers:
%_filetriggers_dir /var/lib/rpm/filetriggers
Then install your watchers:
% cat /var/lib/rpm/filetriggers/ldconfig.filter ^.(/lib|/usr/lib)/[^/]*\.so\. % cat /var/lib/rpm/filetriggers/ldconfig.script #!/bin/sh ldconfig -X % cat /var/lib/rpm/filetriggers/gtk-icon-cache-hicolor.filter ^./usr/share/icons/hicolor/ % cat /var/lib/rpm/filetriggers/gtk-icon-cache-hicolor.script #!/bin/sh /usr/bin/gtk-update-icon-cache --force --quiet /usr/share/icons/hicolor
Note the "." in the regexp which matches both "+" and "-", and so matches both install and uninstall.
[edit] Implementation
A simple patch on rpm. Description:
[edit] files-awaiting-filetriggers
When a package is successfully installed (or removed), rpm will append the installed (resp. removed) files to /var/lib/rpm/files-awaiting-filetriggers.
The format is quite simple: <installed-or-removed> <filename>
where <installed-or-removed> ::= "+" | "-"
For example, after installing hexedit:
+/usr/bin/hexedit +/usr/share/doc/hexedit +/usr/share/doc/hexedit/COPYING +/usr/share/doc/hexedit/TODO +/usr/share/doc/hexedit/hexedit-1.2.12.lsm +/usr/share/man/man1/hexedit.1.lzma
[edit] rpmRunFileTriggers
This function is called before running %posttrans scriptlets. It can be disabled using --noscripts or --notriggers (no special command line option introduced for now).
For each %_filetriggers_dir/*.filter, the regexp (POSIX Extended Regular Expression) on the first line is applied on files-awaiting-filetriggers. If some files match, the corresponding %_filetriggers_dir/<name>.script is called, with matching lines passed in stdin.
Note that this is done in parallel, so multiple <name>.script may be running at the same time.
When it's done, /var/lib/rpm/files-awaiting-filetriggers is removed.
[edit] Comments
Characteristics of this implementation :
- if the transaction is aborted, the next successful transaction will run on every succesful package installation/removal. This is due to files-awaiting-filetriggers which allows to keep state of what is done or not.
- it needs only a light patch in rpm
- files-awaiting-filetriggers may be getting big (eg: 5MB on a big transaction of 1000 packages)
- not fully integrated in rpm:
- --nofiletriggers and RPMTRANS_FLAG_NOFILETRIGGERS should be added
- a new command rpm --run-filetriggers would be useful to force running filetriggers, and only them.
[edit] Suggestions
Filetriggers has been merged with some improvements and additional in rpm5 [HEAD http://rpm5.org/cvs/rlog?f=rpm/lib/filetriggers.c]:
- Use miRE in stead of regex(3)
- Pass filename as argument to filetrigger script so they can replace filetriggers requiring file arguments. (room for improval)
- info-install proposal:
[root@localhost filetriggers]# cat install_info.filter
^\+/usr/share/info/.*\.info.*
[root@localhost filetriggers]# cat install_info.script
#!/bin/sh
/sbin/install-info $1 --dir=/usr/share/info/dir
[root@localhost filetriggers]# cat remove_install_info.filter
^\-/usr/share/info/.*\.info.*
[root@localhost filetriggers]# cat remove_install_info.script
#!/bin/sh
if [ ! -f $1 ]; then
echo /sbin/install-info $1 --dir=/usr/share/info/dir --remove
fi
[edit] Candidates
- emacs elisp
- fc-cache
- gtk-update-icon-cache
- install-info [Proposed]
- ldconfig [Support in place]
- python .pyo
- scrollkeeper-update
- tetex
- update-desktop-database
- update-icon-caches
- update-menus [Support in place]
- update-mime-database
[edit] External links
Some links about filetriggers:
- triggers in dpkg:
- what may get in rpm.org:

