From d92a98237b9bccf4e7017dce7a294ece618cf1fc Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Fri, 2 Nov 2018 11:59:26 +0000 Subject: [PATCH] improve contents and packagehash Make contents have options more like ls. Added options to packagehash to show the existing hash. --- db.sql | 17 +++++++++ zpm-add | 4 +++ zpm-contents | 92 ++++++++++++++++++++++++++++++++++------------- zpm-packagehash.c | 53 ++++++++++++++++++--------- 4 files changed, 125 insertions(+), 41 deletions(-) diff --git a/db.sql b/db.sql index c704034..00c5df0 100644 --- a/db.sql +++ b/db.sql @@ -194,6 +194,23 @@ begin 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 diff --git a/zpm-add b/zpm-add index 28c12f9..6dc08b7 100755 --- a/zpm-add +++ b/zpm-add @@ -199,8 +199,12 @@ for path in $*; do # TODO check that we have such a package,version,release #cat < ...] [-S ] [package]\n"); } @@ -19,7 +17,7 @@ int main(int ac, char **av){ struct zpm pkg; char *dbfile; - int set = 0; + int set = 0, clear = 0, showcurrent = 0; int check = 0; int quiet = 0; @@ -28,12 +26,19 @@ int main(int ac, char **av){ 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); @@ -49,25 +54,39 @@ int main(int ac, char **av){ 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; } -- 2.40.0