updatedb: Add mcron job and dedicated script

The script allows for centralizing the code into one place, instead of having it
in both Helm and mcron.
master
Pierre Neidhardt 2018-04-02 11:42:26 +05:30
parent 78d5deeaa2
commit 5712eccf30
3 changed files with 35 additions and 4 deletions

View File

@ -13,5 +13,10 @@
;; (next-hour-from (next-day) (list (tm:hour (localtime (current-time)))))
(+ (next-second) (- 86400 (- current-time currency-time))))))
;; A string is nicer than Scheme code for `mcron --schedule' output.
;; Other we could return '(system* "units_cur" currency-file)
;; Otherwise we could return '(system* "units_cur" currency-file)
;; and use job's 3rd argument as a description.
(string-append "units_cur " currency-file))
(job '(next-hour)
;; '(next-hour '(3)) is broken in mcron 1.1.
"updatedb-local")

View File

@ -235,9 +235,10 @@ Requires `call-process-to-string' from `functions'."
(let ((was-missing (not (file-exists-p db))))
(when (or update was-missing)
(if (= (shell-command
(funcall helm-locate-create-db-function
db
root))
(or (executable-find "updatedb-local")
(funcall helm-locate-create-db-function
db
root)))
0)
(message "locatedb file `%s' %s" db (if was-missing "created" "updated"))
(error "Failed to %s locatedb file `%s'" (if was-missing "create" "update") db)))))

25
.local/bin/updatedb-local Executable file
View File

@ -0,0 +1,25 @@
#!/bin/sh
update() {
[ $# -ne 2 ] && set -- "$1" "$1/locate.db"
echo >&2 "Updating '$2' database for '$1'..."
## From https://git.archlinux.org/svntogit/packages.git/tree/trunk/updatedb.conf?h=packages/mlocate.
updatedb -l 0 -o "$2" -U "$1" \
--prune-bind-mounts=1 \
--prunefs="9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset cramfs debugfs devpts devtmpfs ecryptfs exofs ftpfs fuse fuse.encfs fuse.sshfs fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs shfs smbfs sockfs sshfs sysfs tmpfs ubifs udf usbfs vboxsf" \
--prunepaths="/gnu/store /afs /mnt /net /sfs /tmp /udev /var/cache /var/lib/pacman/local /var/lock /var/run /var/spool /var/tmp" \
--prunenames=".git .hg .svn .cache Trash .Trash-$(id -u)"
}
update "/" "$HOME/.cache/locate.db"
for i in "/run/media/$USER"/* "/media/$USER"/*; do
[ -d "$i" ] && update "$i"
done
if [ ! -d "/media/$USER" ]; then
for i in "/media/$USER"/*; do
[ -d "$i" ] && update "$i"
done
fi