Make contents have options more like ls.
Added options to packagehash to show the existing hash.
end
;
+create trigger packagefiles_delete_trigger instead of
+delete on packagefiles_pkgid
+begin
+ delete from packagefiles
+ where package = OLD.package
+ and version = OLD.version
+ and release = OLD.release
+ and path = OLD.path
+ ;
+ update packages set hash = null
+ where package = OLD.package
+ and version = OLD.version
+ and release = OLD.release
+ ;
+end
+;
+
create view installed_ref_count as
select I.path, count(*) as refcount
from installedfiles I
# TODO check that we have such a package,version,release
#cat <<EOS
+ if [ $verbose -gt 2 ]; then
+ shellecho=".echo on"
+ fi
zpm shell $pkgfile <<EOS
begin;
+$shellecho
insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,configuration,target)
values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$isconfig,$target);
commit;
pkgfile=${ZPMDB:-/var/lib/zpm/db.zpm}
-verbose=0
+long=0
+pkgonly=0
+quiet=0
-while getopts f:v opt; do
+while getopts f:qln opt; do
case $opt in
f) pkgfile="$OPTARG" ;;
- v) verbose=1
+ l) long=1 ;;
+ n) pkgonly=1 ;;
+ q) quiet=1 ;;
esac
done
shift $((OPTIND - 1))
-set -e
-
if [ ! -f $pkgfile ]; then
echo cannot find $pkgfile
exit 1
fi
-cols=
-if [ $verbose -gt 0 ]; then
- cols="filetype,printf('%4.4s', mode) as mode,username,groupname,"
+if [ $long -gt 0 ]; then
+ cols="filetype,printf('%3.3s', mode) as mode,username,groupname,"
+fi
+
+if [ $pkgonly -eq 1 ]; then
+ cols="pkgid"
+elif [ $quiet -eq 0 ]; then
+ cols="pkgid,$cols"
fi
-for pkg in "$@"; do
- pkgid=$(zpm findpkg -f $pkgfile $pkg)
-
- zpm shell $pkgfile <<EOS
-.separator " "
-select pkgid, $cols
-case when filetype = 'd' then
- rtrim(path,'/') || '/'
-else
- path
-end as path
-from packagefiles_pkgid
-where pkgid = '$pkgid'
-order by path
-;
-EOS
+pkglist=
+while [ $# -gt 0 ]; do
+ pkg=$1
+ shift
+ if [ "$pkg" = '--' ]; then
+ break;
+ fi
+
+ pkgid=$(zpm findpkg -f $pkgfile "$pkg")
+ if [ -n "$pkgid" ]; then
+ q=$(zpm quote -q "$pkgid")
+ pkglist=",$q"
+ else
+ warn "package $pkg not found, ignoring"
+ fi
+done
+pkglist=${pkglist#,}
+globlist=
+for glob in "$@"; do
+ q=$(zpm quote -q "$glob")
+ globlist="or path glob $q"
done
+globlist=${globlist#'or '}
+
+cols=${cols%,}
+
+{
+ printf '.separator " "\n'
+ printf 'select %s\n' "$cols"
+
+ if [ $pkgonly -eq 0 ]; then
+ if [ -n "$cols" ]; then
+ printf ', '
+ fi
+
+ cat <<-EOC
+ case when filetype = 'd' then
+ rtrim(path,'/') || '/'
+ else
+ path
+ end as path
+ EOC
+ fi
+ printf 'from packagefiles_pkgid\nwhere true\n'
+ if [ -n "$globlist" ]; then
+ printf "and (%s)\n" "$globlist"
+ fi
+ if [ -n "$pkglist" ]; then
+ printf "and pkgid in (%s)\n" "$pkglist"
+ fi
+ printf 'order by pkgid,path\n'
+ printf ';\n'
+} | zpm shell $pkgfile
+#} | cat
#include "zpm.h"
-static int found = 0;
-
void usage(void) {
fprintf(stderr, "zpm-findpkg [-I] [-s <status> ...] [-S <status>] [package]\n");
}
struct zpm pkg;
char *dbfile;
- int set = 0;
+ int set = 0, clear = 0, showcurrent = 0;
int check = 0;
int quiet = 0;
dbfile = "/var/lib/zpm/local.db";
}
- while ((opt = getopt(ac, av, "f:scq")) != -1) {
+ /* set -s
+ * clear -S
+ * show current -e
+ * check -c
+ */
+ while ((opt = getopt(ac, av, "f:sScqe")) != -1) {
switch (opt) {
case 'f': dbfile = optarg; break;
case 's': set = 1; break;
+ case 'S': clear = 1; break;
case 'c': check = 1; break;
case 'q': quiet = 1; break;
+ case 'e': showcurrent = 1; break;
default:
usage();
exit(EXIT_FAILURE);
char *pkgid = av[argn];
char hash[ZPM_HASH_STRLEN+1];
+ char *current = 0, *display = hash;
+ int checkfail = 0;
if (zpm_open(&pkg, dbfile)) {
+ if (check || showcurrent) {
+ current = zpm_db_string(&pkg, "select hash from packages_pkgid where pkgid = %Q", pkgid);
+ }
+
if (check) {
- found = zpm_package_hash(&pkg, pkgid, hash);
- char *ehash = zpm_db_string(&pkg, "select hash from packages_pkgid where pkgid = %Q", pkgid);
- if (ehash && found && !strcmp(ehash, hash)) {
- found = 1;
- } else {
- found = 0;
+ checkfail = 1;
+ if (current) {
+ zpm_package_hash(&pkg, pkgid, hash);
+ checkfail = strcmp(current, hash);
}
} else if (set) {
- found = zpm_package_sethash(&pkg, pkgid, hash);
+ zpm_package_sethash(&pkg, pkgid, hash);
+ } else if (clear) {
+ zpm_package_sethash(&pkg, pkgid, NULL);
+ display = NULL;
+ } else if (showcurrent) {
+ display = current;
} else {
- found = zpm_package_hash(&pkg, pkgid, hash);
+ zpm_package_hash(&pkg, pkgid, hash);
+ }
+
+ zpm_close(&pkg);
+ if (current) {
+ free(current);
+ }
+ if (display && !quiet) {
+ printf("%s\n", display);
}
}
- zpm_close(&pkg);
- if (found && !quiet) {
- printf("%s\n", hash);
- }
- return found ? 0 : 1;
+
+ return checkfail ? EXIT_FAILURE : 0;
}