]> pd.if.org Git - zpackage/commitdiff
add create package
authorNathan Wagner <nw@hydaspes.if.org>
Fri, 15 Feb 2019 18:29:36 +0000 (18:29 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Fri, 15 Feb 2019 18:29:36 +0000 (18:29 +0000)
lib/createpkg.c [new file with mode: 0644]

diff --git a/lib/createpkg.c b/lib/createpkg.c
new file mode 100644 (file)
index 0000000..b72e35b
--- /dev/null
@@ -0,0 +1,39 @@
+#define _POSIX_C_SOURCE 200809L
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "zpm.h"
+
+#define DMARK fprintf(stderr, "mark %s %s:%d\n", __FILE__, __func__, __LINE__)
+
+int zpm_create_pkgid(struct zpm *zpm, char *pkgstr) {
+       int release;
+       char version[32];
+       char package[64];
+       int found;
+
+       if (!pkgstr) {
+               return 0;
+       }
+
+       found = zpm_parse_package(pkgstr, package, version, &release);
+       if (found != 3) {
+               return 0;
+       }
+
+       return zpm_create_package(zpm, package, version, release);
+}
+
+int zpm_create_package(struct zpm *zpm, char *name, char *ver, int rel) {
+       char *ins = "insert into packages (package, version, release) values (%Q,%Q,%d);";
+
+       if (zpm->error) {
+               return 0;
+       }
+
+       zpm_db_run(zpm, ins, name, ver, rel);
+       return zpm->error ? 0 : 1;
+}