Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: gahr/pkgng
base: 113c7c0169
...
head fork: gahr/pkgng
compare: 9c5bb06ad6
Checking mergeability… Don't worry, you can still create the pull request.
  • 17 commits
  • 30 files changed
  • 0 commit comments
  • 3 contributors
Commits on Aug 10, 2011
@bapt bapt Merge pull request #89 from gahr/master
Remove left-over \n from pkg info
3fc7ef4
@bapt bapt Fix pkg version -t, Add portmaster support
This is a preliminary support for portmaster.
The patch is against portmaster trunk
in order to use it, please add use_pkgng=yes to your portmasterrc
So far only portmaster -a has been tested
3cd19fa
@bapt bapt Fix pkg2ng with glob conflicts d430bcf
@bapt bapt No need set -x :) fo portmaster 4433eaf
@bapt bapt Fix typos in portmaster 51a7b8c
@bapt bapt Refactoring of package manifest, now consumes less memory and is a bi…
…t faster
5e1a841
@jlaffaye jlaffaye Replace emit macros by functions.
Fixed misuse of said functions.
Removed line and file parameters which are not very relevant.
dce4a68
@bapt bapt Add -y to pkg delete and support pkg_create 0225742
@jlaffaye jlaffaye Do not print anything if there is nothing to do.
Cleanup retcode usage.
Cleanup upgrade. The summary should be done on pkg_jobs() because it may add
new packages and so on.
501a479
@bapt bapt Options are actually mapping not sequence 1c4ab80
@bapt bapt Fix opion_new/_free ae7327e
@bapt bapt Register options 69a10eb
Commits on Aug 11, 2011
@bapt bapt Register options in pkg2ng, show them in pkg info -f 75c642d
@bapt bapt Fix category/license registration 7e22b2c
@bapt bapt Fix pkg2legacy with python egg port 99f7eef
@bapt bapt Document options/users/groups in manifest + add a command to simply a…
…dd the bsd.pkgng.mk
0e1e37b
@gahr Fix spacing 9c5bb06
View
8 README.md
@@ -66,6 +66,9 @@ information about the package:
licenselogic: or
licenses: [MIT, MPL]
flatsize: 482120
+ users: [USER1, USER2]
+ groups: [GROUP1, GROUP2]
+ options: { OPT1: off, OPT2: on }
desc: |-
This is the descrpition
Of foo
@@ -178,6 +181,11 @@ Directory leftovers are automatically removed if they are not in the MTREE.
To use pkgng from ports currently we need to include *bsd.pkgng.mk* in *bsd.port.mk*,
the line before *.if defined(USE_LOCAL_MK)*
+You can also simply run this command after having install bsd.pkgng.mk to your
+/usr/ports/Mk diretory or the suitable PORTSDIR:
+
+ $> sed -i'' -e '/.if.*USE_LOCAL_MK.*$/{G;s/\(.if.*USE_LOCAL_MK)\)\(\n\)/.include "${PORTSDIR}\/Mk\/bsd.pkgng.mk"\2\1/;}' /usr/ports/Mk/bsd.port.mk
+
<a name="usageintro"></a>
### A quick usage introduction to pkgng
View
3  libpkg/backup.c
@@ -61,7 +61,8 @@ pkgdb_load(struct pkgdb *db, char *dest)
archive_read_support_format_tar(a);
if (archive_read_open_filename(a, dest, 4096) != ARCHIVE_OK) {
- EMIT_PKG_ERROR("archive_read_open_filename(%s): %s", dest, archive_error_string(a));
+ pkg_emit_error("archive_read_open_filename(%s): %s", dest,
+ archive_error_string(a));
retcode = EPKG_FATAL;
goto cleanup;
}
View
10 libpkg/fetch.c
@@ -29,7 +29,7 @@ pkg_fetch_file(const char *url, const char *dest)
int retcode = EPKG_OK;
if ((fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0600)) == -1) {
- EMIT_ERRNO("open", dest);
+ pkg_emit_errno("open", dest);
return(EPKG_FATAL);
}
@@ -38,7 +38,7 @@ pkg_fetch_file(const char *url, const char *dest)
if (remote == NULL) {
--retry;
if (retry == 0) {
- EMIT_PKG_ERROR("%s: %s", url, fetchLastErrString);
+ pkg_emit_error("%s: %s", url, fetchLastErrString);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -52,7 +52,7 @@ pkg_fetch_file(const char *url, const char *dest)
break;
if (write(fd, buf, r) != r) {
- EMIT_ERRNO("write", dest);
+ pkg_emit_errno("write", dest);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -61,13 +61,13 @@ pkg_fetch_file(const char *url, const char *dest)
now = time(NULL);
/* Only call the callback every second */
if (now > last || done == st.size) {
- EMIT_FETCHING(url, st.size, done, (now - begin_dl));
+ pkg_emit_fetching(url, st.size, done, (now - begin_dl));
last = now;
}
}
if (ferror(remote)) {
- EMIT_PKG_ERROR("%s: %s", url, fetchLastErrString);
+ pkg_emit_error("%s: %s", url, fetchLastErrString);
retcode = EPKG_FATAL;
goto cleanup;
}
View
16 libpkg/packing.c
@@ -30,7 +30,7 @@ packing_init(struct packing **pack, const char *path, pkg_formats format)
assert(pack != NULL);
if ((*pack = calloc(1, sizeof(struct packing))) == NULL) {
- EMIT_ERRNO("malloc", "");
+ pkg_emit_errno("malloc", "packing");
return (EPKG_FATAL);
}
@@ -98,13 +98,13 @@ packing_append_file_attr(struct packing *pack, const char *filepath, const char
archive_entry_copy_sourcepath(pack->entry, filepath);
if (lstat(filepath, &st) != 0) {
- EMIT_ERRNO("lstat", filepath);
+ pkg_emit_errno("lstat", filepath);
retcode = EPKG_FATAL;
goto cleanup;
}
retcode = archive_read_disk_entry_from_file(pack->aread, pack->entry, -1, &st);
if (retcode != ARCHIVE_OK) {
- EMIT_PKG_ERROR("%s: %s", filepath, archive_error_string(pack->aread));
+ pkg_emit_error("%s: %s", filepath, archive_error_string(pack->aread));
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -130,7 +130,7 @@ packing_append_file_attr(struct packing *pack, const char *filepath, const char
if (archive_entry_size(pack->entry) > 0) {
if ((fd = open(filepath, O_RDONLY)) < 0) {
- EMIT_ERRNO("open", filepath);
+ pkg_emit_errno("open", filepath);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -220,19 +220,19 @@ packing_set_format(struct archive *a, pkg_formats format)
if (archive_write_set_compression_xz(a) == ARCHIVE_OK) {
return ("txz");
} else {
- EMIT_PKG_ERROR("%s", "xz is not supported, trying bzip2");
+ pkg_emit_error("%s", "xz is not supported, trying bzip2");
}
case TBZ:
if (archive_write_set_compression_bzip2(a) == ARCHIVE_OK) {
return ("tbz");
} else {
- EMIT_PKG_ERROR("%s", "bzip2 is not supported, trying gzip");
+ pkg_emit_error("%s", "bzip2 is not supported, trying gzip");
}
case TGZ:
if (archive_write_set_compression_gzip(a) == ARCHIVE_OK) {
return ("tgz");
} else {
- EMIT_PKG_ERROR("%s", "gzip is not supported, trying plain tar");
+ pkg_emit_error("%s", "gzip is not supported, trying plain tar");
}
case TAR:
archive_write_set_compression_none(a);
@@ -254,6 +254,6 @@ packing_format_from_string(const char *str)
return TGZ;
if (strcmp(str, "tar") == 0)
return TAR;
- EMIT_PKG_ERROR("unknown format %s, using txz", str);
+ pkg_emit_error("unknown format %s, using txz", str);
return TXZ;
}
View
17 libpkg/pkg.c
@@ -15,7 +15,7 @@ int
pkg_new(struct pkg **pkg, pkg_t type)
{
if ((*pkg = calloc(1, sizeof(struct pkg))) == NULL) {
- EMIT_ERRNO("malloc", "");
+ pkg_emit_errno("malloc", "pkg");
return EPKG_FATAL;
}
@@ -135,7 +135,7 @@ pkg_get(struct pkg const * const pkg, const pkg_attr attr)
assert(attr < PKG_NUM_FIELDS);
if ((pkg->fields[attr].type & pkg->type) == 0)
- EMIT_PKG_ERROR("%s", "wrong usage of `attr` for this type of `pkg`");
+ pkg_emit_error("wrong usage of `attr` for this type of `pkg`");
return (sbuf_get(pkg->fields[attr].value));
}
@@ -475,7 +475,8 @@ pkg_addlicense(struct pkg *pkg, const char *name)
assert(name != NULL && name[0] != '\0');
if (pkg->licenselogic == LICENSE_SINGLE && !STAILQ_EMPTY(&pkg->licenses)) {
- EMIT_PKG_ERROR("%s is said a have a single license which is already set", pkg_get(pkg, PKG_NAME));
+ pkg_emit_error("%s is have a single license which is already set",
+ pkg_get(pkg, PKG_NAME));
return (EPKG_FATAL);
}
@@ -604,7 +605,7 @@ pkg_addcategory(struct pkg *pkg, const char *name)
while (pkg_categories(pkg, &c) == EPKG_OK) {
if (strcmp(name, pkg_category_name(c)) == 0) {
- EMIT_PKG_ERROR("Duplicate category listing: %s, ignoring", name);
+ pkg_emit_error("duplicate category listing: %s, ignoring", name);
return (EPKG_OK);
}
}
@@ -633,7 +634,7 @@ pkg_adddir_attr(struct pkg *pkg, const char *path, const char *uname, const char
while (pkg_dirs(pkg, &d) == EPKG_OK) {
if (strcmp(path, pkg_dir_path(d)) == 0) {
- EMIT_PKG_ERROR("Duplicate directory listing: %s, ignoring", path);
+ pkg_emit_error("duplicate directory listing: %s, ignoring", path);
return (EPKG_OK);
}
}
@@ -734,7 +735,7 @@ pkg_addscript_file(struct pkg *pkg, const char *path)
strcmp(filename, "+UPGRADE") == 0) {
type = PKG_SCRIPT_UPGRADE;
} else {
- EMIT_PKG_ERROR("unknown script '%s'", filename);
+ pkg_emit_error("unknown script '%s'", filename);
return EPKG_FATAL;
}
@@ -991,7 +992,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con
archive_read_support_format_tar(*a);
if (archive_read_open_filename(*a, path, 4096) != ARCHIVE_OK) {
- EMIT_PKG_ERROR("archive_read_open_filename(%s): %s", path,
+ pkg_emit_error("archive_read_open_filename(%s): %s", path,
archive_error_string(*a));
retcode = EPKG_FATAL;
goto cleanup;
@@ -1038,7 +1039,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con
}
if (ret != ARCHIVE_OK && ret != ARCHIVE_EOF) {
- EMIT_PKG_ERROR("archive_read_next_header(): %s",
+ pkg_emit_error("archive_read_next_header(): %s",
archive_error_string(*a));
retcode = EPKG_FATAL;
}
View
19 libpkg/pkg.h
@@ -2,6 +2,7 @@
#define _PKG_H
#include <stdarg.h>
+#include <stdbool.h>
#include <sys/types.h>
#include <openssl/pem.h>
@@ -659,6 +660,11 @@ void pkg_jobs_free(struct pkg_jobs *jobs);
int pkg_jobs_add(struct pkg_jobs *jobs, struct pkg *pkg);
/**
+ * Returns true if there are no jobs.
+ */
+bool pkg_jobs_empty(struct pkg_jobs *jobs);
+
+/**
* Iterates over the packages in the jobs queue.
* @param pkg Must be set to NULL for the first call.
* @return An error code.
@@ -762,8 +768,6 @@ typedef enum {
struct pkg_event {
pkg_event_t type;
- uint16_t line;
- const char *file;
union {
struct {
const char *func;
@@ -786,10 +790,13 @@ struct pkg_event {
} e_install_begin;
struct {
struct pkg *pkg;
+ } e_install_finished;
+ struct {
+ struct pkg *pkg;
} e_deinstall_begin;
struct {
struct pkg *pkg;
- } e_install_finished;
+ } e_deinstall_finished;
struct {
struct pkg *pkg;
} e_upgrade_begin;
@@ -798,18 +805,12 @@ struct pkg_event {
} e_upgrade_finished;
struct {
struct pkg *pkg;
- } e_install_end;
- struct {
- struct pkg *pkg;
struct pkg_dep *dep;
} e_missing_dep;
struct {
struct pkg *pkg;
int force;
} e_required;
- struct {
- struct pkg *pkg;
- } e_failed_cksum;
};
};
View
22 libpkg/pkg_add.c
@@ -42,7 +42,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
do {
if (archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS) != ARCHIVE_OK) {
- EMIT_PKG_ERROR("archive_read_extract(): %s",
+ pkg_emit_error("archive_read_extract(): %s",
archive_error_string(a));
retcode = EPKG_FATAL;
break;
@@ -60,7 +60,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
&& lstat(path, &st) == ENOENT) {
archive_entry_set_pathname(ae, path);
if (archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS) != ARCHIVE_OK) {
- EMIT_PKG_ERROR("archive_read_extract(): %s",
+ pkg_emit_error("archive_read_extract(): %s",
archive_error_string(a));
retcode = EPKG_FATAL;
break;
@@ -69,7 +69,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
} while ((ret = archive_read_next_header(a, &ae)) == ARCHIVE_OK);
if (ret != ARCHIVE_EOF) {
- EMIT_PKG_ERROR("archive_read_next_header(): %s",
+ pkg_emit_error("archive_read_next_header(): %s",
archive_error_string(a));
retcode = EPKG_FATAL;
}
@@ -119,7 +119,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
pkg_setautomatic(pkg);
if (uname(&u) != 0) {
- EMIT_ERRNO("uname", "");
+ pkg_emit_errno("uname", "");
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -128,7 +128,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
* Check the architecture
*/
if (strcmp(u.machine, pkg_get(pkg, PKG_ARCH)) != 0) {
- EMIT_PKG_ERROR("wrong architecture: %s instead of %s",
+ pkg_emit_error("wrong architecture: %s instead of %s",
pkg_get(pkg, PKG_ARCH), u.machine);
retcode = EPKG_FATAL;
goto cleanup;
@@ -151,7 +151,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
pkgdb_it_free(it);
if (ret == EPKG_OK) {
- EMIT_ALREADY_INSTALLED(pkg);
+ pkg_emit_already_installed(pkg);
retcode = EPKG_INSTALLED;
goto cleanup;
} else if (ret != EPKG_END) {
@@ -165,7 +165,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
basedir = dirname(path);
if ((ext = strrchr(path, '.')) == NULL) {
- EMIT_PKG_ERROR("%s has no extension", path);
+ pkg_emit_error("%s has no extension", path);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -183,7 +183,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
}
} else {
retcode = EPKG_FATAL;
- EMIT_MISSING_DEP(pkg, dep);
+ pkg_emit_missing_dep(pkg, dep);
goto cleanup;
}
}
@@ -196,7 +196,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
goto cleanup_reg;
if (!upgrade)
- EMIT_INSTALL_BEGIN(pkg);
+ pkg_emit_install_begin(pkg);
/*
* Execute pre-install scripts
@@ -223,9 +223,9 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL);
if (upgrade)
- EMIT_UPGRADE_FINISHED(pkg);
+ pkg_emit_upgrade_finished(pkg);
else
- EMIT_INSTALL_FINISHED(pkg);
+ pkg_emit_install_finished(pkg);
cleanup_reg:
pkgdb_register_finale(db, retcode);
View
22 libpkg/pkg_attributes.c
@@ -135,7 +135,7 @@ int
pkg_conflict_new(struct pkg_conflict **c)
{
if ((*c = calloc(1, sizeof(struct pkg_conflict))) == NULL) {
- EMIT_ERRNO("calloc", "pkg_conflict");
+ pkg_emit_errno("calloc", "pkg_conflict");
return (EPKG_FATAL);
}
@@ -165,7 +165,7 @@ int
pkg_license_new(struct pkg_license **l)
{
if ((*l = calloc(1, sizeof(struct pkg_license))) == NULL) {
- EMIT_ERRNO("calloc", "pkg_license");
+ pkg_emit_errno("calloc", "pkg_license");
return (EPKG_FATAL);
}
@@ -196,7 +196,7 @@ int
pkg_user_new(struct pkg_user **u)
{
if ((*u = calloc(1, sizeof(struct pkg_user))) == NULL) {
- EMIT_ERRNO("calloc", "pkg_user");
+ pkg_emit_errno("calloc", "pkg_user");
return (EPKG_FATAL);
}
@@ -226,7 +226,7 @@ int
pkg_group_new(struct pkg_group **g)
{
if ((*g = calloc(1, sizeof(struct pkg_group))) == NULL) {
- EMIT_ERRNO("calloc", "pkg_group");
+ pkg_emit_errno("calloc", "pkg_group");
return (EPKG_FATAL);
}
@@ -257,7 +257,7 @@ int
pkg_script_new(struct pkg_script **script)
{
if ((*script = calloc(1, sizeof(struct pkg_script))) == NULL) {
- EMIT_ERRNO("calloc", "pkg_script");
+ pkg_emit_errno("calloc", "pkg_script");
return (EPKG_FATAL);
}
@@ -293,16 +293,22 @@ pkg_script_type(struct pkg_script *s)
int
pkg_option_new(struct pkg_option **option)
{
- if ((*option = calloc(1, sizeof(struct pkg_option))))
- return (-1);
- return (0);
+ if ((*option = calloc(1, sizeof(struct pkg_option))) == NULL) {
+ pkg_emit_errno("calloc", "pkg_user");
+ return (EPKG_FATAL);
+ }
+ return (EPKG_OK);
}
void
pkg_option_free(struct pkg_option *option)
{
+ if (option == NULL)
+ return;
+
sbuf_free(option->key);
sbuf_free(option->value);
+ free(option);
}
const char *
View
4 libpkg/pkg_create.c
@@ -88,7 +88,7 @@ pkg_create_archive(const char *outdir, struct pkg *pkg, pkg_formats format, int
return NULL;
if (asprintf(&pkg_path, "%s/%s-%s", outdir, pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION)) == -1) {
- EMIT_ERRNO("asprintf", "");
+ pkg_emit_errno("asprintf", "");
return (NULL);
}
@@ -165,7 +165,7 @@ pkg_create_installed(const char *outdir, pkg_formats format, const char *rootdir
pkg_archive = pkg_create_archive(outdir, pkg, format, required_flags);
if (pkg_archive == NULL) {
- EMIT_PKG_ERROR("%s", "unable to create archive");
+ pkg_emit_error("unable to create archive");
return (EPKG_FATAL);
}
View
17 libpkg/pkg_delete.c
@@ -48,13 +48,13 @@ pkg_delete2(struct pkg *pkg, struct pkgdb *db, int force, int upgrade)
return (ret);
if (!upgrade)
- EMIT_DEINSTALL_BEGIN(pkg);
+ pkg_emit_deinstall_begin(pkg);
else
- EMIT_UPGRADE_BEGIN(pkg);
+ pkg_emit_upgrade_begin(pkg);
/* If there are dependencies */
if (pkg_rdeps(pkg, &rdep) == EPKG_OK) {
- EMIT_REQUIRED(pkg, force);
+ pkg_emit_required(pkg, force);
if (!force)
return (EPKG_REQUIRED);
}
@@ -78,7 +78,7 @@ pkg_delete2(struct pkg *pkg, struct pkgdb *db, int force, int upgrade)
return (ret);
if (!upgrade)
- EMIT_DEINSTALL_FINISHED(pkg);
+ pkg_emit_deinstall_finished(pkg);
return (pkgdb_unregister_pkg(db, pkg_get(pkg, PKG_ORIGIN)));
}
@@ -97,16 +97,17 @@ pkg_delete_files(struct pkg *pkg, int force)
/* check sha256 */
if (!force && pkg_file_sha256(file)[0] != '\0') {
if (sha256_file(path, sha256) == -1) {
- EMIT_PKG_ERROR("sha256 calculation failed for '%s'",
+ pkg_emit_error("sha256 calculation failed for '%s'",
path);
} else if (strcmp(sha256, pkg_file_sha256(file)) != 0) {
- EMIT_PKG_ERROR("%s fails original SHA256 checksum, not removing", path);
+ pkg_emit_error("%s fails original SHA256 checksum,"
+ " not removing", path);
continue;
}
}
if (unlink(path) == -1) {
- EMIT_ERRNO("unlink", path);
+ pkg_emit_errno("unlink", path);
continue;
}
}
@@ -130,7 +131,7 @@ pkg_delete_dirs(struct pkgdb *db, struct pkg *pkg, int force)
continue;
if (rmdir(pkg_dir_path(dir)) == -1 && errno != ENOTEMPTY && force != 1)
- EMIT_ERRNO("rmdir", pkg_dir_path(dir));
+ pkg_emit_errno("rmdir", pkg_dir_path(dir));
}
return (EPKG_OK);
View
4 libpkg/pkg_elf.c
@@ -75,7 +75,9 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
found = true;
}
if (!found) {
- EMIT_PKG_ERROR("adding forgotten depends (%s): %s-%s", map->l_name, pkg_get(p, PKG_NAME), pkg_get(p, PKG_VERSION));
+ pkg_emit_error("adding forgotten depends (%s): %s-%s",
+ map->l_name, pkg_get(p, PKG_NAME),
+ pkg_get(p, PKG_VERSION));
pkg_adddep(pkg, pkg_get(p, PKG_NAME), pkg_get(p, PKG_ORIGIN), pkg_get(p, PKG_VERSION));
}
}
View
151 libpkg/pkg_event.c
@@ -11,12 +11,153 @@ pkg_event_register(pkg_event_cb cb, void *data)
_data = data;
}
-void
-pkg_emit_event(struct pkg_event *ev, const char *file, uint16_t line)
+static void
+pkg_emit_event(struct pkg_event *ev)
{
- ev->file = file;
- ev->line = line;
-
if (_cb != NULL)
_cb(_data, ev);
}
+
+void
+pkg_emit_error(const char *fmt, ...)
+{
+ struct pkg_event ev;
+ va_list ap;
+
+ ev.type = PKG_EVENT_ERROR;
+
+ va_start(ap, fmt);
+ vasprintf(&ev.e_pkg_error.msg, fmt, ap);
+ va_end(ap);
+
+ pkg_emit_event(&ev);
+ free(ev.e_pkg_error.msg);
+}
+
+void
+pkg_emit_errno(const char *func, const char *arg)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_ERRNO;
+ ev.e_errno.func = func;
+ ev.e_errno.arg = arg;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_already_installed(struct pkg *p)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_ALREADY_INSTALLED;
+ ev.e_already_installed.pkg = p;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_fetching(const char *url, off_t total, off_t done, time_t elapsed)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_FETCHING;
+ ev.e_fetching.url = url;
+ ev.e_fetching.total = total;
+ ev.e_fetching.done = done;
+ ev.e_fetching.elapsed = elapsed;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_install_begin(struct pkg *p)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_INSTALL_BEGIN;
+ ev.e_install_begin.pkg = p;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_install_finished(struct pkg *p)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_INSTALL_FINISHED;
+ ev.e_install_finished.pkg = p;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_deinstall_begin(struct pkg *p)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_DEINSTALL_BEGIN;
+ ev.e_deinstall_begin.pkg = p;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_deinstall_finished(struct pkg *p)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_DEINSTALL_FINISHED;
+ ev.e_deinstall_finished.pkg = p;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_upgrade_begin(struct pkg *p)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_UPGRADE_BEGIN;
+ ev.e_upgrade_begin.pkg = p;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_upgrade_finished(struct pkg *p)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_UPGRADE_FINISHED;
+ ev.e_upgrade_finished.pkg = p;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_missing_dep(struct pkg *p, struct pkg_dep *d)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_MISSING_DEP;
+ ev.e_missing_dep.pkg = p;
+ ev.e_missing_dep.dep = d;
+
+ pkg_emit_event(&ev);
+}
+
+void
+pkg_emit_required(struct pkg *p, int force)
+{
+ struct pkg_event ev;
+
+ ev.type = PKG_EVENT_REQUIRED;
+ ev.e_required.pkg = p;
+ ev.e_required.force = force;
+
+ pkg_emit_event(&ev);
+}
+
View
121 libpkg/pkg_event.h
@@ -1,114 +1,17 @@
#ifndef _PKG_EVENT
#define _PKG_EVENT
-#define _EV_START \
- do { \
- struct pkg_event ev
-
-#define _EV_EMIT \
- pkg_emit_event(&ev, __FILE__, __LINE__)
-
-#define _EV_END \
- } while(0)
-
-#define EMIT_PKG_ERROR(fmt, ...) \
- _EV_START; \
- ev.type = PKG_EVENT_ERROR; \
- asprintf(&ev.e_pkg_error.msg, fmt, __VA_ARGS__); \
- _EV_EMIT; \
- free(ev.e_pkg_error.msg); \
- _EV_END
-
-#define EMIT_ERRNO(f, a) \
- _EV_START; \
- ev.type = PKG_EVENT_ERRNO; \
- ev.e_errno.func = f; \
- ev.e_errno.arg = a; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_ALREADY_INSTALLED(p) \
- _EV_START; \
- ev.type = PKG_EVENT_ALREADY_INSTALLED; \
- ev.e_already_installed.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_FETCHING(u, t, d, e) \
- _EV_START; \
- ev.type = PKG_EVENT_FETCHING; \
- ev.e_fetching.url = u; \
- ev.e_fetching.total = t; \
- ev.e_fetching.done = d; \
- ev.e_fetching.elapsed = e; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_INSTALL_BEGIN(p) \
- _EV_START; \
- ev.type = PKG_EVENT_INSTALL_BEGIN; \
- ev.e_install_begin.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_INSTALL_FINISHED(p) \
- _EV_START; \
- ev.type = PKG_EVENT_INSTALL_FINISHED; \
- ev.e_install_finished.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_DEINSTALL_BEGIN(p) \
- _EV_START; \
- ev.type = PKG_EVENT_DEINSTALL_BEGIN; \
- ev.e_deinstall_begin.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_DEINSTALL_FINISHED(p) \
- _EV_START; \
- ev.type = PKG_EVENT_DEINSTALL_FINISHED; \
- ev.e_install_finished.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_UPGRADE_BEGIN(p) \
- _EV_START; \
- ev.type = PKG_EVENT_UPGRADE_BEGIN; \
- ev.e_upgrade_begin.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_UPGRADE_FINISHED(p) \
- _EV_START; \
- ev.type = PKG_EVENT_UPGRADE_FINISHED; \
- ev.e_upgrade_finished.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_MISSING_DEP(p, d) \
- _EV_START; \
- ev.type = PKG_EVENT_MISSING_DEP; \
- ev.e_missing_dep.pkg = p; \
- ev.e_missing_dep.dep = d; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_REQUIRED(p, f) \
- _EV_START; \
- ev.type = PKG_EVENT_REQUIRED; \
- ev.e_required.pkg = p; \
- ev.e_required.force = f; \
- _EV_EMIT; \
- _EV_END
-
-#define EMIT_FAILED_CKSUM(p) \
- _EV_START; \
- ev.type = PKG_EVENT_FAILED_CKSUM; \
- ev.e_failed_cksum.pkg = p; \
- _EV_EMIT; \
- _EV_END
-
-void pkg_emit_event(struct pkg_event *, const char *, uint16_t);
+void pkg_emit_error(const char *fmt, ...);
+void pkg_emit_errno(const char *func, const char *arg);
+void pkg_emit_already_installed(struct pkg *p);
+void pkg_emit_fetching(const char *url, off_t total, off_t done, time_t elapsed);
+void pkg_emit_install_begin(struct pkg *p);
+void pkg_emit_install_finished(struct pkg *p);
+void pkg_emit_deinstall_begin(struct pkg *p);
+void pkg_emit_deinstall_finished(struct pkg *p);
+void pkg_emit_upgrade_begin(struct pkg *p);
+void pkg_emit_upgrade_finished(struct pkg *p);
+void pkg_emit_missing_dep(struct pkg *p, struct pkg_dep *d);
+void pkg_emit_required(struct pkg *p, int force);
#endif
View
15 libpkg/pkg_jobs.c
@@ -1,4 +1,5 @@
#include <assert.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@@ -14,7 +15,7 @@ pkg_jobs_new(struct pkg_jobs **j, pkg_jobs_t t, struct pkgdb *db)
assert(t != PKG_JOBS_INSTALL || db->type == PKGDB_REMOTE);
if((*j = calloc(1, sizeof(struct pkg_jobs))) == NULL) {
- EMIT_ERRNO("calloc", "pkg_jobs");
+ pkg_emit_errno("calloc", "pkg_jobs");
return (EPKG_FATAL);
}
@@ -53,6 +54,14 @@ pkg_jobs_add(struct pkg_jobs *j, struct pkg *pkg)
return (EPKG_OK);
}
+bool
+pkg_jobs_empty(struct pkg_jobs *j)
+{
+ assert(j != NULL);
+
+ return (STAILQ_FIRST(&j->jobs) == NULL ? true : false);
+}
+
int
pkg_jobs(struct pkg_jobs *j, struct pkg **pkg)
{
@@ -162,7 +171,7 @@ pkg_jobs_apply(struct pkg_jobs *j, int force)
if (j->type == PKG_JOBS_UPGRADE)
return (pkg_jobs_upgrade(j));
- EMIT_PKG_ERROR("%s", "bad jobs argument");
+ pkg_emit_error("bad jobs argument");
return (EPKG_FATAL);
}
@@ -214,7 +223,7 @@ add_dep(struct pkg_jobs *j, struct pkg_jobs_node *n)
if (ndep->pkg == NULL) {
ndep->pkg = pkgdb_query_remote(j->db, pkg_dep_origin(dep));
if (ndep->pkg == NULL)
- EMIT_MISSING_DEP(n->pkg, dep);
+ pkg_emit_missing_dep(n->pkg, dep);
else {
pkg_setautomatic(ndep->pkg);
add_dep(j, ndep);
View
679 libpkg/pkg_manifest.c
@@ -29,51 +29,47 @@
#define PKG_USERS -12
#define PKG_GROUPS -13
-static void parse_mapping(struct pkg *, yaml_node_pair_t *, yaml_document_t *, int);
-static void parse_node(struct pkg *, yaml_node_t *, yaml_document_t *, int);
+static int pkg_set_from_node(struct pkg *, yaml_node_t *, yaml_document_t *, int);
+static int pkg_set_flatsize_from_node(struct pkg *, yaml_node_t *, yaml_document_t *, int);
+static int pkg_set_licenselogic_from_node(struct pkg *, yaml_node_t *, yaml_document_t *, int);
+static int pkg_set_deps_from_node(struct pkg *, yaml_node_t *, yaml_document_t *, const char *);
+static int pkg_set_files_from_node(struct pkg *, yaml_node_t *, yaml_document_t *, const char *);
+static int pkg_set_dirs_from_node(struct pkg *, yaml_node_t *, yaml_document_t *, const char *);
+static int parse_sequence(struct pkg *, yaml_node_t *, yaml_document_t *, int);
+static int parse_mapping(struct pkg *, yaml_node_t *, yaml_document_t *, int);
static struct manifest_key {
const char *key;
int type;
+ yaml_node_type_t valid_type;
+ int (*parse_data)(struct pkg *, yaml_node_t *, yaml_document_t *, int);
} manifest_key[] = {
- { "name", PKG_NAME },
- { "origin", PKG_ORIGIN },
- { "version", PKG_VERSION },
- { "arch", PKG_ARCH },
- { "osversion", PKG_OSVERSION },
- { "www", PKG_WWW },
- { "comment", PKG_COMMENT},
- { "maintainer", PKG_MAINTAINER},
- { "prefix", PKG_PREFIX},
- { "deps", PKG_DEPS},
- { "conflicts", PKG_CONFLICTS},
- { "files", PKG_FILES},
- { "dirs", PKG_DIRS},
- { "flatsize", PKG_FLATSIZE},
- { "licenselogic", PKG_LICENSELOGIC },
- { "licenses", PKG_LICENSES },
- { "desc", PKG_DESC },
- { "scripts", PKG_SCRIPTS},
- { "message", PKG_MESSAGE},
- { "categories", PKG_CATEGORIES},
- { "options", PKG_OPTIONS},
- { "users", PKG_USERS},
- { "groups", PKG_GROUPS}
+ { "name", PKG_NAME, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "origin", PKG_ORIGIN, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "version", PKG_VERSION, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "arch", PKG_ARCH, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "osversion", PKG_OSVERSION, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "www", PKG_WWW, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "comment", PKG_COMMENT, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "maintainer", PKG_MAINTAINER, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "prefix", PKG_PREFIX, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "deps", PKG_DEPS, YAML_MAPPING_NODE, parse_mapping},
+ { "conflicts", PKG_CONFLICTS, YAML_SEQUENCE_NODE, parse_sequence},
+ { "files", PKG_FILES, YAML_MAPPING_NODE, parse_mapping},
+ { "dirs", PKG_DIRS, YAML_SEQUENCE_NODE, parse_sequence},
+ { "flatsize", -1, YAML_SCALAR_NODE, pkg_set_flatsize_from_node},
+ { "licenselogic", -1, YAML_SCALAR_NODE, pkg_set_licenselogic_from_node},
+ { "licenses", PKG_LICENSES, YAML_SEQUENCE_NODE, parse_sequence},
+ { "desc", PKG_DESC, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "scripts", PKG_SCRIPTS, YAML_MAPPING_NODE, parse_mapping},
+ { "message", PKG_MESSAGE, YAML_SCALAR_NODE, pkg_set_from_node},
+ { "categories", PKG_CATEGORIES, YAML_SEQUENCE_NODE, parse_sequence},
+ { "options", PKG_OPTIONS, YAML_MAPPING_NODE, parse_mapping},
+ { "users", PKG_USERS, YAML_SEQUENCE_NODE, parse_sequence},
+ { "groups", PKG_GROUPS, YAML_SEQUENCE_NODE, parse_sequence},
+ { NULL, -99, -99, NULL}
};
-#define manifest_key_len (int)(sizeof(manifest_key)/sizeof(manifest_key[0]))
-
-static int manifest_type(const char *key) {
- int i = 0;
-
- for (i = 0; i < manifest_key_len; i++) {
- if (!strcasecmp(key, manifest_key[i].key))
- return (manifest_key[i].type);
- }
-
- return (PKG_UNKNOWN);
-}
-
int
pkg_load_manifest_file(struct pkg *pkg, const char *fpath)
{
@@ -90,265 +86,376 @@ pkg_load_manifest_file(struct pkg *pkg, const char *fpath)
return (ret);
}
-static void
-parse_mapping(struct pkg *pkg, yaml_node_pair_t *pair, yaml_document_t *document, int pkgtype)
+static int
+pkg_set_from_node(struct pkg *pkg, yaml_node_t *val, __unused yaml_document_t *doc, int attr)
{
- int type;
- yaml_node_t *key, *subkey;
- yaml_node_t *val, *subval;
- yaml_node_pair_t *subpair;
- char origin[BUFSIZ];
- char version[BUFSIZ];
- char sum[SHA256_DIGEST_LENGTH * 2 + 1];
- char uname[MAXLOGNAME + 1];
- char gname[MAXLOGNAME + 1];
- void *set;
- mode_t perm;
+ while (val->data.scalar.length > 0 &&
+ val->data.scalar.value[val->data.scalar.length - 1] == '\n') {
+ val->data.scalar.value[val->data.scalar.length - 1] = '\0';
+ val->data.scalar.length--;
+ }
+
+ return (pkg_set(pkg, attr, val->data.scalar.value));
+}
+
+static int
+pkg_set_flatsize_from_node(struct pkg *pkg, yaml_node_t *val, __unused yaml_document_t *doc, __unused int attr)
+{
+ int64_t flatsize;
+ const char *errstr = NULL;
+ flatsize = strtonum(val->data.scalar.value, 0, INT64_MAX, &errstr);
+ if (errstr) {
+ pkg_emit_error("Unable to convert %s to int64: %s",
+ val->data.scalar.value, errstr);
+ return (EPKG_FATAL);
+ }
+
+ return (pkg_setflatsize(pkg, flatsize));
+}
+static int
+pkg_set_licenselogic_from_node(struct pkg *pkg, yaml_node_t *val, __unused yaml_document_t *doc, __unused int attr)
+{
+ if (!strcmp(val->data.scalar.value, "single"))
+ pkg_set_licenselogic(pkg, LICENSE_SINGLE);
+ else if ( !strcmp(val->data.scalar.value, "and") || !strcmp(val->data.scalar.value, "dual"))
+ pkg_set_licenselogic(pkg, LICENSE_AND);
+ else if ( !strcmp(val->data.scalar.value, "or") || !strcmp(val->data.scalar.value, "multi"))
+ pkg_set_licenselogic(pkg, LICENSE_OR);
+ else {
+ pkg_emit_error("Unknown license logic: %s", val->data.scalar.value);
+ return (EPKG_FATAL);
+ }
+ return (EPKG_OK);
+}
+
+static int
+parse_sequence(struct pkg * pkg, yaml_node_t *node, yaml_document_t *doc, int attr)
+{
+ yaml_node_item_t *item;
+ yaml_node_t *val;
+
+ item = node->data.sequence.items.start;
+ while (item < node->data.sequence.items.top) {
+ val = yaml_document_get_node(doc, *item);
+ switch (attr) {
+ case PKG_CONFLICTS:
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0)
+ pkg_emit_error("Skipping malformed conflict");
+ else
+ pkg_addconflict(pkg, val->data.scalar.value);
+ break;
+ case PKG_CATEGORIES:
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0)
+ pkg_emit_error("Skipping malformed category");
+ else
+ pkg_addcategory(pkg, val->data.scalar.value);
+ break;
+ case PKG_LICENSES:
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0)
+ pkg_emit_error("Skipping malformed license");
+ else
+ pkg_addlicense(pkg, val->data.scalar.value);
+ break;
+ case PKG_USERS:
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0)
+ pkg_emit_error("Skipping malformed license");
+ else
+ pkg_adduser(pkg, val->data.scalar.value);
+ break;
+ case PKG_GROUPS:
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0)
+ pkg_emit_error("Skipping malformed license");
+ else
+ pkg_addgroup(pkg, val->data.scalar.value);
+ break;
+ case PKG_DIRS:
+ if (val->type == YAML_SCALAR_NODE && val->data.scalar.length > 0)
+ pkg_adddir(pkg, val->data.scalar.value);
+ else if (val->type == YAML_MAPPING_NODE)
+ parse_mapping(pkg, val, doc, attr);
+ else
+ pkg_emit_error("Skipping malformed dirs");
+ }
+ ++item;
+ }
+ return (EPKG_OK);
+}
+
+static int
+parse_mapping(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, int attr)
+{
+ yaml_node_pair_t *pair;
+ yaml_node_t *key;
+ yaml_node_t *val;
pkg_script_t script_type;
- key = yaml_document_get_node(document, pair->key);
- val = yaml_document_get_node(document, pair->value);
-
- switch (pkgtype) {
- case PKG_FILES:
- if (val->type == YAML_SCALAR_NODE) {
- pkg_addfile(pkg, key->data.scalar.value, val->data.scalar.length == 64 ? val->data.scalar.value : NULL);
- } else {
- subpair = val->data.mapping.pairs.start;
- sum[0] = '\0';
- uname[0] = '\0';
- gname[0] = '\0';
- perm = 0;
- set = NULL;
- while (subpair < val->data.mapping.pairs.top) {
- subkey = yaml_document_get_node(document, subpair->key);
- subval = yaml_document_get_node(document, subpair->value);
- if (!strcasecmp(subkey->data.scalar.value, "sum") && subval->data.scalar.length == 64)
- strlcpy(sum, subval->data.scalar.value, sizeof(sum));
- else if (!strcasecmp(subkey->data.scalar.value, "uname") && subval->data.scalar.length <= MAXLOGNAME)
- strlcpy(uname, subval->data.scalar.value, sizeof(uname));
- else if (!strcasecmp(subkey->data.scalar.value, "gname") && subval->data.scalar.length <= MAXLOGNAME)
- strlcpy(gname, subval->data.scalar.value, sizeof(gname));
- else if (!strcasecmp(subkey->data.scalar.value, "perm") && subval->data.scalar.length > 0) {
- if ((set = setmode(subval->data.scalar.value)) == NULL)
- EMIT_PKG_ERROR("Not a valide mode: %s", subval->data.scalar.value);
- else
- perm = getmode(set, 0);
- }
- ++subpair;
- }
- pkg_addfile_attr(pkg, key->data.scalar.value, sum[0] != '\0' ? sum : NULL,
- uname[0] != '\0' ? uname : NULL, gname[0] != '\0' ? gname : NULL,
- perm);
- }
- break;
- case PKG_OPTIONS:
- pkg_addoption(pkg, key->data.scalar.value, val->data.scalar.value);
- break;
- case PKG_DEPS:
- subpair = val->data.mapping.pairs.start;
- while (subpair < val->data.mapping.pairs.top) {
- subkey = yaml_document_get_node(document, subpair->key);
- subval = yaml_document_get_node(document, subpair->value);
- if (!strcasecmp(subkey->data.scalar.value, "origin"))
- strlcpy(origin, subval->data.scalar.value, BUFSIZ);
- else if (!strcasecmp(subkey->data.scalar.value, "version"))
- strlcpy(version, subval->data.scalar.value, BUFSIZ);
+ pair = item->data.mapping.pairs.start;
+ while (pair < item->data.mapping.pairs.top) {
+ key = yaml_document_get_node(doc, pair->key);
+ val = yaml_document_get_node(doc, pair->value);
+
+ if (key->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping empty dependency name");
+ ++pair;
+ continue;
+ }
+
+ switch (attr) {
+ case PKG_DEPS:
+ if (val->type != YAML_MAPPING_NODE)
+ pkg_emit_error("Skipping malformed depencency %s",
+ key->data.scalar.value);
else
- EMIT_PKG_ERROR("Ignoring key: (%s: %s) for dependency %s",
- subkey->data.scalar.value,
- subval->data.scalar.value,
+ pkg_set_deps_from_node(pkg, val, doc, key->data.scalar.value);
+ break;
+ case PKG_DIRS:
+ if (val->type != YAML_MAPPING_NODE)
+ pkg_emit_error("Skipping malformed dirs %s",
key->data.scalar.value);
- ++subpair;
- }
- pkg_adddep(pkg, key->data.scalar.value, origin, version);
- break;
- case PKG_SCRIPTS:
- if (strcmp(key->data.scalar.value, "pre-install") == 0) {
- script_type = PKG_SCRIPT_PRE_INSTALL;
- } else if (strcmp(key->data.scalar.value, "install") == 0) {
- script_type = PKG_SCRIPT_INSTALL;
- } else if (strcmp(key->data.scalar.value, "post-install") == 0) {
- script_type = PKG_SCRIPT_POST_INSTALL;
- } else if (strcmp(key->data.scalar.value, "pre-upgrade") == 0) {
- script_type = PKG_SCRIPT_PRE_UPGRADE;
- } else if (strcmp(key->data.scalar.value, "upgrade") == 0) {
- script_type = PKG_SCRIPT_UPGRADE;
- } else if (strcmp(key->data.scalar.value, "post-upgrade") == 0) {
- script_type = PKG_SCRIPT_POST_UPGRADE;
- } else if (strcmp(key->data.scalar.value, "pre-deinstall") == 0) {
- script_type = PKG_SCRIPT_PRE_DEINSTALL;
- } else if (strcmp(key->data.scalar.value, "deinstall") == 0) {
- script_type = PKG_SCRIPT_DEINSTALL;
- } else if (strcmp(key->data.scalar.value, "post-deinstall") == 0) {
- script_type = PKG_SCRIPT_POST_DEINSTALL;
- } else
+ else
+ pkg_set_dirs_from_node(pkg, val, doc, key->data.scalar.value);
break;
-
- pkg_addscript(pkg, val->data.scalar.value, script_type);
- break;
- default:
- type = manifest_type(key->data.scalar.value);
- if (type == -1) {
- if (val->type == YAML_SCALAR_NODE)
- EMIT_PKG_ERROR("Unknown line: (%s: %s)\n",
- key->data.scalar.value,
- val->data.scalar.value);
+ case PKG_FILES:
+ if (val->type == YAML_SCALAR_NODE && val->data.scalar.length > 0)
+ pkg_addfile(pkg, key->data.scalar.value, val->data.scalar.length == 64 ? val->data.scalar.value : NULL);
+ else if (val->type == YAML_MAPPING_NODE)
+ pkg_set_files_from_node(pkg, val, doc, key->data.scalar.value);
else
- EMIT_PKG_ERROR("Unknown key: (%s)\n",
+ pkg_emit_error("Skipping malformed files %s",
key->data.scalar.value);
- ++pair;
break;
- }
- if (val->type == YAML_SCALAR_NODE) {
- /* just ignore empty lines */
- if (val->data.scalar.length <= 0)
+ case PKG_OPTIONS:
+ if (val->type != YAML_SCALAR_NODE)
+ pkg_emit_error("Skipping malformed option %s",
+ key->data.scalar.value);
+ else
+ pkg_addoption(pkg, key->data.scalar.value, val->data.scalar.value);
+ break;
+ case PKG_SCRIPTS:
+ if (val->type != YAML_SCALAR_NODE)
+ pkg_emit_error("Skipping malformed scripts %s",
+ key->data.scalar.value);
+ if (strcmp(key->data.scalar.value, "pre-install") == 0) {
+ script_type = PKG_SCRIPT_PRE_INSTALL;
+ } else if (strcmp(key->data.scalar.value, "install") == 0) {
+ script_type = PKG_SCRIPT_INSTALL;
+ } else if (strcmp(key->data.scalar.value, "post-install") == 0) {
+ script_type = PKG_SCRIPT_POST_INSTALL;
+ } else if (strcmp(key->data.scalar.value, "pre-upgrade") == 0) {
+ script_type = PKG_SCRIPT_PRE_UPGRADE;
+ } else if (strcmp(key->data.scalar.value, "upgrade") == 0) {
+ script_type = PKG_SCRIPT_UPGRADE;
+ } else if (strcmp(key->data.scalar.value, "post-upgrade") == 0) {
+ script_type = PKG_SCRIPT_POST_UPGRADE;
+ } else if (strcmp(key->data.scalar.value, "pre-deinstall") == 0) {
+ script_type = PKG_SCRIPT_PRE_DEINSTALL;
+ } else if (strcmp(key->data.scalar.value, "deinstall") == 0) {
+ script_type = PKG_SCRIPT_DEINSTALL;
+ } else if (strcmp(key->data.scalar.value, "post-deinstall") == 0) {
+ script_type = PKG_SCRIPT_POST_DEINSTALL;
+ } else {
+ pkg_emit_error("Skipping unknown script type: %s",
+ key->data.scalar.value);
break;
- type = manifest_type(key->data.scalar.value);
- switch (type) {
- case -1:
- EMIT_PKG_ERROR("Unknown line: (%s: %s)\n",
- key->data.scalar.value,
- val->data.scalar.value);
- break;
- case PKG_FLATSIZE:
- pkg_setflatsize(pkg, strtoimax(val->data.scalar.value, NULL, 10));
- break;
- case PKG_LICENSELOGIC:
- if (!strcmp(val->data.scalar.value, "single"))
- pkg_set_licenselogic(pkg, LICENSE_SINGLE);
- else if ( !strcmp(val->data.scalar.value, "and") || !strcmp(val->data.scalar.value, "dual"))
- pkg_set_licenselogic(pkg, LICENSE_AND);
- else if ( !strcmp(val->data.scalar.value, "or") || !strcmp(val->data.scalar.value, "multi"))
- pkg_set_licenselogic(pkg, LICENSE_OR);
- else
- EMIT_PKG_ERROR("Unknown license logic: %s", val->data.scalar.value);
- break;
- default:
- while (val->data.scalar.length > 0 &&
- val->data.scalar.value[val->data.scalar.length - 1] == '\n') {
- val->data.scalar.value[val->data.scalar.length - 1] = '\0';
- val->data.scalar.length--;
- }
- pkg_set(pkg, type, val->data.scalar.value);
- break;
}
- } else {
- parse_node(pkg, val, document, type);
- }
- break;
+
+ pkg_addscript(pkg, val->data.scalar.value, script_type);
+ break;
+ }
+
+ ++pair;
}
+ return (EPKG_OK);
}
-static void
-parse_node(struct pkg *pkg, yaml_node_t *node, yaml_document_t *document, int pkgtype)
-{
- yaml_node_pair_t *pair, *p;
- yaml_node_item_t *item;
- yaml_node_t *nd, *pk, *pv, *key, *val;
- char uname[MAXLOGNAME + 1];
- char gname[MAXLOGNAME + 1];
+static int
+pkg_set_files_from_node(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, const char *filename) {
+ yaml_node_pair_t *pair;
+ yaml_node_t *key;
+ yaml_node_t *val;
+ const char *sum = NULL;
+ const char *uname = NULL;
+ const char *gname = NULL;
void *set;
- mode_t perm;
+ mode_t perm = 0;
+
+ pair = item->data.mapping.pairs.start;
+ while (pair < item->data.mapping.pairs.top) {
+ key = yaml_document_get_node(doc, pair->key);
+ val = yaml_document_get_node(doc, pair->value);
+ if (key->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping malformed file entry for %s", filename);
+ ++pair;
+ continue;
+ }
- switch (node->type) {
- case YAML_SCALAR_NODE:
- /* NOT REACHED THERE SHOULD NOT BE ALONE SCALARS */
- printf("%s\n", (char *)node->data.scalar.value);
- break;
- case YAML_SEQUENCE_NODE:
- switch (pkgtype) {
- case PKG_DIRS:
- item = node->data.sequence.items.start;
- while (item < node->data.sequence.items.top) {
- nd = yaml_document_get_node(document, *item);
- if (nd->type == YAML_SCALAR_NODE)
- pkg_adddir(pkg, nd->data.scalar.value);
- else if (nd->type == YAML_MAPPING_NODE) {
- uname[0] = '\0';
- gname[0] = '\0';
- perm = 0;
- set = NULL;
- p = nd->data.mapping.pairs.start;
- pk = yaml_document_get_node(document, p->key);
- pv = yaml_document_get_node(document, p->value);
- pair = pv->data.mapping.pairs.start;
- while (pair < pv->data.mapping.pairs.top) {
- key = yaml_document_get_node(document, pair->key);
- val = yaml_document_get_node(document, pair->value);
- if (!strcasecmp(key->data.scalar.value, "uname") && val->data.scalar.length <= MAXLOGNAME)
- strlcpy(uname, val->data.scalar.value,
- sizeof(uname));
- else if (!strcasecmp(key->data.scalar.value, "gname") && val->data.scalar.length <= MAXLOGNAME)
- strlcpy(gname, val->data.scalar.value,
- sizeof(gname));
- else if (!strcasecmp(key->data.scalar.value, "perm") && val->data.scalar.length > 0) {
- if ((set = setmode(val->data.scalar.value)) == NULL)
- EMIT_PKG_ERROR("Not a valide mode: %s", val->data.scalar.value);
- else
- perm = getmode(set, 0);
- }
- ++pair;
- }
- pkg_adddir_attr(pkg, pk->data.scalar.value, uname[0] != '\0' ? uname : NULL,
- gname[0] != '\0' ? gname : NULL, perm);
- }
- ++item;
- }
- break;
- case PKG_CATEGORIES:
- item = node->data.sequence.items.start;
- while (item < node->data.sequence.items.top) {
- nd = yaml_document_get_node(document, *item);
- pkg_addcategory(pkg, nd->data.scalar.value);
- ++item;
- }
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping malformed file entry for %s", filename);
+ ++pair;
+ continue;
+ }
- break;
- case PKG_CONFLICTS:
- item = node->data.sequence.items.start;
- while (item < node->data.sequence.items.top) {
- nd = yaml_document_get_node(document, *item);
- pkg_addconflict(pkg, nd->data.scalar.value);
- ++item;
- }
- break;
- case PKG_LICENSES:
- item = node->data.sequence.items.start;
- while (item < node->data.sequence.items.top) {
- nd = yaml_document_get_node(document, *item);
- pkg_addlicense(pkg, nd->data.scalar.value);
- ++item;
- }
- break;
- case PKG_USERS:
- item = node->data.sequence.items.start;
- while (item < node->data.sequence.items.top) {
- nd = yaml_document_get_node(document, *item);
- pkg_adduser(pkg, nd->data.scalar.value);
- ++item;
- }
- break;
- case PKG_GROUPS:
- item = node->data.sequence.items.start;
- while (item < node->data.sequence.items.top) {
- nd = yaml_document_get_node(document, *item);
- pkg_adduser(pkg, nd->data.scalar.value);
- ++item;
- }
- break;
- }
+ if (!strcasecmp(key->data.scalar.value, "uname"))
+ uname = val->data.scalar.value;
+ else if (!strcasecmp(key->data.scalar.value, "gname"))
+ gname = val->data.scalar.value;
+ else if (!strcasecmp(key->data.scalar.value, "sum") && val->data.scalar.length == 64)
+ sum = val->data.scalar.value;
+ else if (!strcasecmp(key->data.scalar.value, "perm")) {
+ if ((set = setmode(val->data.scalar.value)) == NULL)
+ pkg_emit_error("Not a valide mode: %s", val->data.scalar.value);
+ else
+ perm = getmode(set, 0);
+ } else {
+ pkg_emit_error("Skipping unknown key for file(%s): %s", filename,
+ key->data.scalar.value);
+ }
+
+ ++pair;
+ }
+ pkg_addfile_attr(pkg, key->data.scalar.value, sum, uname, gname, perm);
+
+ return (EPKG_OK);
+}
+
+static int
+pkg_set_dirs_from_node(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, const char *dirname) {
+ yaml_node_pair_t *pair;
+ yaml_node_t *key;
+ yaml_node_t *val;
+ const char *uname = NULL;
+ const char *gname = NULL;
+ void *set;
+ mode_t perm = 0;
+
+ pair = item->data.mapping.pairs.start;
+ while (pair < item->data.mapping.pairs.top) {
+ key = yaml_document_get_node(doc, pair->key);
+ val = yaml_document_get_node(doc, pair->value);
+ if (key->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping malformed file entry for %s", dirname);
+ ++pair;
+ continue;
+ }
+
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping malformed file entry for %s", dirname);
+ ++pair;
+ continue;
+ }
+
+ if (!strcasecmp(key->data.scalar.value, "uname"))
+ uname = val->data.scalar.value;
+ else if (!strcasecmp(key->data.scalar.value, "gname"))
+ gname = val->data.scalar.value;
+ else if (!strcasecmp(key->data.scalar.value, "perm")) {
+ if ((set = setmode(val->data.scalar.value)) == NULL)
+ pkg_emit_error("Not a valide mode: %s", val->data.scalar.value);
+ else
+ perm = getmode(set, 0);
+ } else {
+ pkg_emit_error("Skipping unknown key for dir(%s): %s", dirname,
+ key->data.scalar.value);
+ }
+
+ ++pair;
+ }
+
+ pkg_adddir_attr(pkg, dirname, uname, gname, perm);
+
+ return (EPKG_OK);
+}
+
+static int
+pkg_set_deps_from_node(struct pkg *pkg, yaml_node_t *item, yaml_document_t *doc, const char *depname) {
+ yaml_node_pair_t *pair;
+ yaml_node_t *key;
+ yaml_node_t *val;
+ const char *origin = NULL;
+ const char *version = NULL;
+
+ pair = item->data.mapping.pairs.start;
+ while (pair < item->data.mapping.pairs.top) {
+ key = yaml_document_get_node(doc, pair->key);
+ val = yaml_document_get_node(doc, pair->value);
+ if (key->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping malformed dependency entry for %s",
+ depname);
+ ++pair;
+ continue;
+ }
+
+ if (val->type != YAML_SCALAR_NODE || val->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping malformed dependency entry for %s",
+ depname);
+ ++pair;
+ continue;
+ }
+
+ if (!strcasecmp(key->data.scalar.value, "origin"))
+ origin = val->data.scalar.value;
+
+ if (!strcasecmp(key->data.scalar.value, "version"))
+ version = val->data.scalar.value;
+
+ ++pair;
+ }
+
+ if (origin != NULL && version != NULL)
+ pkg_adddep(pkg, depname, origin, version);
+ else
+ pkg_emit_error("Skipping malformed dependency %s", depname);
+
+ return (EPKG_OK);
+}
+
+static int
+parse_root_node(struct pkg *pkg, yaml_node_t *node, yaml_document_t *doc) {
+ yaml_node_pair_t *pair;
+ yaml_node_t *key;
+ yaml_node_t *val;
+ int i = 0;
+ int retcode = EPKG_OK;
+
+ pair = node->data.mapping.pairs.start;
+ while (pair < node->data.mapping.pairs.top) {
+ if (retcode == EPKG_FATAL)
break;
- case YAML_MAPPING_NODE:
- pair = node->data.mapping.pairs.start;
- while (pair < node->data.mapping.pairs.top) {
- parse_mapping(pkg, pair, document, pkgtype);
- ++pair;
+
+ key = yaml_document_get_node(doc, pair->key);
+ val = yaml_document_get_node(doc, pair->value);
+ if (key->data.scalar.length <= 0) {
+ pkg_emit_error("Skipping empty key");
+ ++pair;
+ continue;
+ }
+
+ if (val->type == YAML_NO_NODE || ( val->type == YAML_SCALAR_NODE && val->data.scalar.length <= 0)) {
+ /* silently skip on purpose */
+ ++pair;
+ continue;
+ }
+
+ for (i = 0; manifest_key[i].key != NULL; i++) {
+ if (!strcasecmp(key->data.scalar.value, manifest_key[i].key)) {
+ if (val->type == manifest_key[i].valid_type) {
+ retcode = manifest_key[i].parse_data(pkg, val, doc, manifest_key[i].type);
+ } else {
+ pkg_emit_error("Unsupported format for key: %s",
+ key->data.scalar.value);
+ retcode = EPKG_FATAL;
+ }
+ break;
}
- break;
- case YAML_NO_NODE:
- break;
+
+ if (manifest_key[i].key == NULL)
+ pkg_emit_error("Skipping unknown manifest key: %s",
+ key->data.scalar.value);
+ }
+ ++pair;
}
+
+ return (retcode);
}
int
@@ -357,7 +464,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
yaml_parser_t parser;
yaml_document_t doc;
yaml_node_t *node;
- int retcode = EPKG_OK;
+ int retcode = EPKG_FATAL;
assert(pkg != NULL);
assert(buf != NULL);
@@ -367,10 +474,16 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
yaml_parser_load(&parser, &doc);
node = yaml_document_get_root_node(&doc);
- if (node != NULL)
- parse_node(pkg, node, &doc, -1);
- else
- retcode = EPKG_FATAL;
+ if (node != NULL) {
+ if (node->type != YAML_MAPPING_NODE) {
+ pkg_emit_error("Invalid manifest format");
+ } else {
+ parse_root_node(pkg, node, &doc);
+ retcode = EPKG_OK;
+ }
+ } else {
+ pkg_emit_error("Invalid manifest format");
+ }
yaml_document_delete(&doc);
yaml_parser_delete(&parser);
@@ -508,7 +621,7 @@ pkg_emit_manifest(struct pkg *pkg, char **dest)
yaml_document_add_scalar(&doc, NULL, __DECONST(yaml_char_t*, "options"), 7, YAML_PLAIN_SCALAR_STYLE),
options);
}
- manifest_append_kv(files, pkg_option_opt(option), pkg_option_value(option));
+ manifest_append_kv(options, pkg_option_opt(option), pkg_option_value(option));
}
while (pkg_files(pkg, &file) == EPKG_OK) {
View
4 libpkg/pkg_ports.c
@@ -155,7 +155,7 @@ ports_parse_plist(struct pkg *pkg, char *plist)
ret += pkg_adddir(pkg, path);
} else {
- EMIT_PKG_ERROR("%s is deprecated, ignoring", plist_p);
+ pkg_emit_error("%s is deprecated, ignoring", plist_p);
}
} else if ((len = strlen(plist_p)) > 0){
filestarted = true;
@@ -184,7 +184,7 @@ ports_parse_plist(struct pkg *pkg, char *plist)
}
ret += pkg_addfile(pkg, path, p);
} else {
- EMIT_ERRNO("lstat", path);
+ pkg_emit_errno("lstat", path);
}
}
View
29 libpkg/pkg_repo.c
@@ -41,7 +41,7 @@ pkg_repo_fetch(struct pkg *pkg)
/* Create the dirs in cachedir */
if ((path = dirname(dest)) == NULL) {
- EMIT_ERRNO("dirname", dest);
+ pkg_emit_errno("dirname", dest);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -60,7 +60,8 @@ pkg_repo_fetch(struct pkg *pkg)
retcode = sha256_file(dest, cksum);
if (retcode == EPKG_OK)
if (strcmp(cksum, pkg_get(pkg, PKG_CKSUM))) {
- EMIT_FAILED_CKSUM(pkg);
+ pkg_emit_error("%s failed checksum from repo",
+ pkg_get(pkg, PKG_NAME));
retcode = EPKG_FATAL;
}
@@ -102,12 +103,13 @@ load_rsa_public_key(const char *rsa_key_path)
char errbuf[1024];
if ((fp = fopen(rsa_key_path, "rb")) == 0) {
- EMIT_ERRNO("Error reading public key(%s)", rsa_key_path);
+ pkg_emit_errno("fopen", rsa_key_path);
return (NULL);
}
if (!PEM_read_RSA_PUBKEY( fp, &rsa, NULL, NULL )) {
- EMIT_PKG_ERROR("Error reading public key(%s): %s", rsa_key_path, ERR_error_string(ERR_get_error(), errbuf));
+ pkg_emit_error("error reading public key(%s): %s", rsa_key_path,
+ ERR_error_string(ERR_get_error(), errbuf));
fclose(fp);
return (NULL);
}
@@ -134,7 +136,8 @@ pkg_repo_verify(const char *path, unsigned char *sig, unsigned int sig_len)
return(EPKG_FATAL);
if (RSA_verify(NID_sha1, sha256, sizeof(sha256), sig, sig_len, rsa) == 0) {
- EMIT_PKG_ERROR("%s: %s", pkg_config("PUBKEY"), ERR_error_string(ERR_get_error(), errbuf));
+ pkg_emit_error("%s: %s", pkg_config("PUBKEY"),
+ ERR_error_string(ERR_get_error(), errbuf));
return (EPKG_FATAL);
}
@@ -238,7 +241,7 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
"VALUES (?1, (SELECT id FROM categories WHERE name = ?2));";
if (!is_dir(path)) {
- EMIT_PKG_ERROR("%s is not a directory", path);
+ pkg_emit_error("%s is not a directory", path);
return EPKG_FATAL;
}
@@ -249,7 +252,7 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
if (stat(repodb, &st) != -1)
if (unlink(repodb) != 0) {
- EMIT_ERRNO("unlink", path);
+ pkg_emit_errno("unlink", path);
return EPKG_FATAL;
}
@@ -260,14 +263,14 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
}
if (sqlite3_exec(sqlite, initsql, NULL, NULL, &errmsg) != SQLITE_OK) {
- EMIT_PKG_ERROR("sqlite: %s", errmsg);
+ pkg_emit_error("sqlite: %s", errmsg);
retcode = EPKG_FATAL;
goto cleanup;
}
if (sqlite3_exec(sqlite, "BEGIN TRANSACTION;", NULL, NULL, &errmsg) !=
SQLITE_OK) {
- EMIT_PKG_ERROR("sqlite: %s", errmsg);
+ pkg_emit_error("sqlite: %s", errmsg);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -297,7 +300,7 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
}
if ((fts = fts_open(repopath, FTS_PHYSICAL, NULL)) == NULL) {
- EMIT_ERRNO("fts_open", path);
+ pkg_emit_errno("fts_open", path);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -429,7 +432,7 @@ pkg_create_repo(char *path, void (progress)(struct pkg *pkg, void *data), void *
}
if (sqlite3_exec(sqlite, "COMMIT;", NULL, NULL, &errmsg) != SQLITE_OK) {
- EMIT_PKG_ERROR("sqlite: %s", errmsg);
+ pkg_emit_error("sqlite: %s", errmsg);
retcode = EPKG_FATAL;
}
@@ -487,7 +490,7 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path)
packing_init(&pack, repo_archive, TXZ);
if (rsa_key_path != NULL) {
if (access(rsa_key_path, R_OK) == -1) {
- EMIT_ERRNO("access", rsa_key_path);
+ pkg_emit_errno("access", rsa_key_path);
return EPKG_FATAL;
}
@@ -505,7 +508,7 @@ pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path)
if (RSA_sign(NID_sha1, sha256, sizeof(sha256), sigret, &siglen, rsa) == 0) {
/* XXX pass back RSA errors correctly */
- EMIT_PKG_ERROR("%s: %lu", rsa_key_path, ERR_get_error());
+ pkg_emit_error("%s: %lu", rsa_key_path, ERR_get_error());
return EPKG_FATAL;
}
View
14 libpkg/pkg_util.c
@@ -70,7 +70,7 @@ mkdirs(const char *_path)
if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0)
if (errno != EEXIST && errno != EISDIR) {
- EMIT_ERRNO("mkdir", path);
+ pkg_emit_errno("mkdir", path);
return (EPKG_FATAL);
}
@@ -97,28 +97,28 @@ file_to_buffer(const char *path, char **buffer, off_t *sz)
assert(sz != NULL);
if ((fd = open(path, O_RDONLY)) == -1) {
- EMIT_ERRNO("open", path);
+ pkg_emit_errno("open", path);
retcode = EPKG_FATAL;
goto cleanup;
}
if (fstat(fd, &st) == -1) {
close(fd);
- EMIT_ERRNO("fstat", path);
+ pkg_emit_errno("fstat", path);
retcode = EPKG_FATAL;
goto cleanup;
}
if ((*buffer = malloc(st.st_size + 1)) == NULL) {
close(fd);
- EMIT_ERRNO("malloc", "");
+ pkg_emit_errno("malloc", "");
retcode = EPKG_FATAL;
goto cleanup;
}
if (read(fd, *buffer, st.st_size) == -1) {
close(fd);
- EMIT_ERRNO("read", path);
+ pkg_emit_errno("read", path);
retcode = EPKG_FATAL;
goto cleanup;
}
@@ -249,7 +249,7 @@ sha256_file(const char *path, char out[SHA256_DIGEST_LENGTH * 2 + 1])
SHA256_CTX sha256;
if ((fp = fopen(path, "rb")) == NULL) {
- EMIT_ERRNO("fopen", path);
+ pkg_emit_errno("fopen", path);
return EPKG_FATAL;
}
@@ -261,7 +261,7 @@ sha256_file(const char *path, char out[SHA256_DIGEST_LENGTH * 2 + 1])
if (ferror(fp) != 0) {
fclose(fp);
out[0] = '\0';
- EMIT_ERRNO("fread", path);
+ pkg_emit_errno("fread", path);
return EPKG_FATAL;
}
View
2  libpkg/pkg_util.h
@@ -10,7 +10,7 @@
#define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)
#define ERROR_SQLITE(db) \
- EMIT_PKG_ERROR("sqlite: %s", sqlite3_errmsg(db))
+ pkg_emit_error("sqlite: %s", sqlite3_errmsg(db))
int sbuf_set(struct sbuf **, const char *);
const char * sbuf_get(struct sbuf *);
View
52 libpkg/pkgdb.c
@@ -114,7 +114,7 @@ populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg) {
}
}
if (columns_text[i].name == NULL)
- EMIT_PKG_ERROR("Unknown column %s", colname);
+ pkg_emit_error("Unknown column %s", colname);
break;
case SQLITE_INTEGER:
for (i = 0; columns_int[i].name != NULL; i++ ) {
@@ -124,11 +124,11 @@ populate_pkg(sqlite3_stmt *stmt, struct pkg *pkg) {
}
}
if (columns_int[i].name == NULL)
- EMIT_PKG_ERROR("Unknown column %s", colname);
+ pkg_emit_error("Unknown column %s", colname);
break;
case SQLITE_BLOB:
case SQLITE_FLOAT:
- EMIT_PKG_ERROR("Wrong type for column: %s", colname);
+ pkg_emit_error("Wrong type for column: %s", colname);
/* just ignore currently */
break;
case SQLITE_NULL:
@@ -229,7 +229,7 @@ pkgdb_upgrade(sqlite3 *sdb)
if (db_version == DBVERSION)
return (EPKG_OK);
else if (db_version > DBVERSION) {
- EMIT_PKG_ERROR("%s", "database version is newer than libpkg(3)");
+ pkg_emit_error("database version is newer than libpkg(3)");
return (EPKG_FATAL);
}
@@ -252,7 +252,7 @@ pkgdb_upgrade(sqlite3 *sdb)
* been removed.
*/
if (sql_upgrade == NULL) {
- EMIT_PKG_ERROR("can not upgrade to db version %" PRId64,
+ pkg_emit_error("can not upgrade to db version %" PRId64,
db_version);
return (EPKG_FATAL);
}