Hello, in the version of debtags I'm currently working on I'm maintaining an on-disk index that needs to be updated whenever the apt index is updated. Otherwise, after the apt index is recreated, software using debtags would refuse to run until the debtags index is recreated as well (or would automatically recreate it if run as root). I've implemented a way to update the debtags indexes without trying to download stuff from the net: it's a simple "debtags --local update". mvo informed me that there is no way to plug a hook into apt database regeneration because every existing software reimplements the update function in a different way. Would you be happy to work out all together a standard place where to put hook scripts to be run after the apt reindex by whatever software performs it? The first thing that comes to my mind is a run-parts style directory with the hooks in /etc/apt, such as a "/etc/apt/hooks/update.d" or "/etc/apt/update-hook.d". The implementation could be as simple as: #include <sys/types.h> #include <dirent.h> #include <sys/stat.h> #include <unistd.h> void run_update_hooks() { static const string hookdir("/etc/apt/hooks/update.d"); DIR* dir = opendir(hookdir.c_str()); if (dir == NULL) return; while (struct dirent* d = readdir(dir)) { // Avoid upper directories and hidden files if (d->d_name[0] == '.') continue; string script(hookdir + "/" + d->d_name); // Avoid backup files if (script[script.size() - 1] == '~') continue; // Ensure that the file is a regular file struct stat st; if (stat(script.c_str(), &st) == -1) continue; if (!S_ISREG(st.st_mode)) continue; // Ensure that the file can be executed if (access(script.c_str(), X_OK) == -1) continue; // Execute the file (replace with your favourite // reimplementation of system) system(script.c_str()); } closedir(dir); } (code untested) Comments? Ciao, Enrico -- GPG key: 1024D/797EBFAB 2000-12-05 Enrico Zini <enrico@enricozini.org>
Attachment:
signature.asc
Description: Digital signature