From ac2c517bd7ebd875e24547938ed7e332e30757c3 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 14 Sep 2014 18:04:10 +0200 Subject: [PATCH] Fixed install/update tests on pkgs with no files. --- lib/package_register.c | 10 +++++----- lib/package_unpack.c | 34 +++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/package_register.c b/lib/package_register.c index db07aef2..60bbaf9e 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -86,13 +86,13 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd) goto out; } /* - * Create a hash for the pkg's metafile. + * Create a hash for the pkg's metafile if it exists. */ buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); - sha256 = xbps_file_hash(buf); - assert(sha256); - xbps_dictionary_set_cstring(pkgd, "metafile-sha256", sha256); - free(sha256); + if ((sha256 = xbps_file_hash(buf))) { + xbps_dictionary_set_cstring(pkgd, "metafile-sha256", sha256); + free(sha256); + } free(buf); /* * Remove unneeded objs from pkg dictionary. diff --git a/lib/package_unpack.c b/lib/package_unpack.c index c425aa6b..9ee9f0c8 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -238,16 +238,6 @@ unpack_archive(struct xbps_handle *xhp, xbps_dictionary_set(pkg_repod, "remove-script", data); xbps_object_release(data); } - buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); - if (!xbps_dictionary_externalize_to_file(binpkg_filesd, buf)) { - free(buf); - rv = errno; - xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, rv, pkgver, - "%s: [unpack] failed to externalize pkg metadata files: %s", - pkgver, strerror(rv)); - goto out; - } - free(buf); /* * Execute INSTALL "pre" ACTION before unpacking files. */ @@ -503,6 +493,21 @@ unpack_archive(struct xbps_handle *xhp, pkgver, archive_error_string(ar)); goto out; } + /* + * Externalize binpkg files.plist to disk, if not empty. + */ + if (xbps_dictionary_count(binpkg_filesd)) { + buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); + if (!xbps_dictionary_externalize_to_file(binpkg_filesd, buf)) { + rv = errno; + free(buf); + xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, + rv, pkgver, "%s: [unpack] failed to externalize pkg " + "pkg metadata files: %s", pkgver, strerror(rv)); + goto out; + } + free(buf); + } /* * Skip checking for obsolete files on: * - Package with "preserve" keyword. @@ -538,7 +543,14 @@ unpack_archive(struct xbps_handle *xhp, xbps_object_release(obj); } xbps_object_release(pkg_filesd); - + /* + * If unpacked pkg has no files, remove its files metadata plist. + */ + if (!xbps_dictionary_count(binpkg_filesd)) { + buf = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); + unlink(buf); + free(buf); + } out: if (xbps_object_type(binpkg_filesd) == XBPS_TYPE_DICTIONARY) xbps_object_release(binpkg_filesd);