-for path in $*; do
-hash=$(./zpm-addfile $pkgfile $path)
-
-sqlite3 $pkgfile <<EOS
-create table if not exists packagefiles (
- package text,
- subpackage text, -- libs, dev, client, server, whatever
- hash text,
- path text,
- filetype text -- e.g. config, etc?
-);
-insert into packagefiles
-values ('$package', nullif('$subpackage', ''), '$hash', '$path', NULL)
-;
-EOS
+item=$1
+shift
+#printf "pkg: %s\n" $pkg
+pkgid=$(zpm findpkg -f $pkgfile "$item")
+
+if [ -z "$pkgid" ]; then
+ die "can't find pkgid for $item in $pkgfile"
+fi
+
+(
+rv=0
+
+{
+printf "begin;\n"
+while [ $# -gt 0 ]; do
+ item=$1
+ shift
+ show=0
+ case "$item" in
+ :*)
+ pkgid=$(zpm findpkg -f $pkgfile "${item#:}")
+ continue
+ ;;
+ *=*)
+ field=${item%%=*}
+ value=${item#*=}
+ ;;
+ *=)
+ field=${item%%=*}
+ value=
+ ;;
+ *)
+ field=$item
+ show=1
+ ;;
+ esac
+
+ if [ -z "$pkgid" ]; then
+ warn "can't find pkgid for $item in $pkgfile"
+ break;
+ fi
+
+ vfield=$(zpm quote "$field")
+
+ hasfield=$(zpm shell $pkgfile "select name from pragma_table_info('packages') where name = '$vfield';")
+ if [ -z "$hasfield" ]; then
+ warn "$field is not a valid package field"
+ break
+ fi
+
+ field=$(zpm quote -i "$field")
+
+ if [ $show -eq 1 ]; then
+ printf "select %s from packages_pkgid where pkgid = '%s';\n" "$field" "$pkgid"
+ continue
+ fi
+
+ if [ -z "$value" ]; then
+ value=NULL
+ else
+ value=$(zpm quote -q "$value")
+ fi
+
+ printf "update packages_pkgid set %s = %s where pkgid = '$pkgid';\n" $field "$value"