2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2012-01-19 16:56:40 +05:30
|
|
|
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
2009-08-17 22:37:20 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dirent.h>
|
2010-04-29 02:43:33 +05:30
|
|
|
#include <libgen.h>
|
2012-05-31 19:59:56 +05:30
|
|
|
#include <assert.h>
|
2009-08-17 22:37:20 +05:30
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
2009-11-24 16:35:39 +05:30
|
|
|
#include "defs.h"
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-05-31 19:59:56 +05:30
|
|
|
#ifndef __arraycount
|
|
|
|
#define __arraycount(a) (sizeof(a) / sizeof(*a))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const char *archs[] = { "noarch", "i686", "x86_64" };
|
|
|
|
|
2011-07-09 16:48:11 +05:30
|
|
|
/*
|
2011-11-10 13:51:17 +05:30
|
|
|
* Removes stalled pkg entries in repository's index.plist file, if any
|
2011-07-09 16:48:11 +05:30
|
|
|
* binary package cannot be read (unavailable, not enough perms, etc).
|
|
|
|
*/
|
|
|
|
static int
|
2012-06-14 11:52:11 +05:30
|
|
|
remove_missing_binpkg_entries(struct xbps_handle *xhp, const char *repodir)
|
2011-07-09 16:48:11 +05:30
|
|
|
{
|
2012-01-19 16:56:40 +05:30
|
|
|
prop_array_t array;
|
|
|
|
prop_dictionary_t pkgd;
|
2012-05-31 19:59:56 +05:30
|
|
|
const char *filen, *pkgver, *arch;
|
2011-07-09 16:48:11 +05:30
|
|
|
char *binpkg, *plist;
|
|
|
|
size_t i;
|
|
|
|
int rv = 0;
|
|
|
|
bool found = false;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
plist = xbps_pkg_index_plist(xhp, repodir);
|
2011-07-09 16:48:11 +05:30
|
|
|
if (plist == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2012-01-19 16:56:40 +05:30
|
|
|
array = prop_array_internalize_from_zfile(plist);
|
|
|
|
if (array == NULL) {
|
2011-07-09 16:48:11 +05:30
|
|
|
if (errno != ENOENT) {
|
|
|
|
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
|
|
|
|
plist, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
} else {
|
|
|
|
free(plist);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
again:
|
2012-01-19 16:56:40 +05:30
|
|
|
for (i = 0; i < prop_array_count(array); i++) {
|
|
|
|
pkgd = prop_array_get(array, i);
|
2012-01-24 14:17:40 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
2011-07-09 16:48:11 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen);
|
2012-05-31 19:59:56 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
|
|
|
|
binpkg = xbps_xasprintf("%s/%s/%s", repodir, arch, filen);
|
2011-07-09 16:48:11 +05:30
|
|
|
if (binpkg == NULL) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (access(binpkg, R_OK) == -1) {
|
2012-06-01 14:27:58 +05:30
|
|
|
printf("index: removed obsolete entry `%s' (%s)\n",
|
|
|
|
pkgver, arch);
|
2012-01-19 16:56:40 +05:30
|
|
|
prop_array_remove(array, i);
|
2011-07-09 16:48:11 +05:30
|
|
|
free(binpkg);
|
|
|
|
found = true;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
free(binpkg);
|
|
|
|
}
|
2012-06-02 20:21:22 +05:30
|
|
|
if (found && !prop_array_externalize_to_zfile(array, plist))
|
|
|
|
rv = errno;
|
|
|
|
|
2011-07-09 16:48:11 +05:30
|
|
|
free(plist);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-01-19 16:56:40 +05:30
|
|
|
static prop_array_t
|
2012-06-14 11:52:11 +05:30
|
|
|
repoidx_get(struct xbps_handle *xhp, const char *pkgdir)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_array_t array;
|
|
|
|
char *plist;
|
2011-07-09 16:48:11 +05:30
|
|
|
int rv;
|
|
|
|
/*
|
2011-11-10 13:51:17 +05:30
|
|
|
* Remove entries in repositories index for unexistent
|
2011-07-09 16:48:11 +05:30
|
|
|
* packages, i.e dangling entries.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((rv = remove_missing_binpkg_entries(xhp, pkgdir)) != 0)
|
2011-07-09 16:48:11 +05:30
|
|
|
return NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
plist = xbps_pkg_index_plist(xhp, pkgdir);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (plist == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2012-01-19 16:56:40 +05:30
|
|
|
array = prop_array_internalize_from_zfile(plist);
|
|
|
|
free(plist);
|
|
|
|
if (array == NULL)
|
2009-08-17 22:37:20 +05:30
|
|
|
array = prop_array_create();
|
|
|
|
|
2012-01-19 16:56:40 +05:30
|
|
|
return array;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-11-24 16:41:23 +05:30
|
|
|
static int
|
2012-06-15 19:03:11 +05:30
|
|
|
add_binpkg_to_index(struct xbps_handle *xhp,
|
|
|
|
prop_array_t idx,
|
2012-06-30 14:40:00 +05:30
|
|
|
const char *repodir,
|
2011-07-09 16:48:11 +05:30
|
|
|
const char *file)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2009-11-18 11:04:39 +05:30
|
|
|
prop_dictionary_t newpkgd, curpkgd;
|
2009-08-17 22:37:20 +05:30
|
|
|
struct stat st;
|
2012-06-01 14:27:58 +05:30
|
|
|
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver;
|
|
|
|
const char *arch, *oldarch;
|
2012-01-17 15:55:45 +05:30
|
|
|
char *sha256, *filen, *tmpfilen, *oldfilepath, *buf;
|
2012-06-01 20:07:44 +05:30
|
|
|
int ret = 0, rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-08-18 17:42:44 +05:30
|
|
|
tmpfilen = strdup(file);
|
|
|
|
if (tmpfilen == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
filen = basename(tmpfilen);
|
|
|
|
if (strcmp(tmpfilen, filen) == 0) {
|
2009-11-24 08:36:06 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
2009-08-18 17:42:44 +05:30
|
|
|
}
|
|
|
|
|
2012-06-06 00:23:15 +05:30
|
|
|
newpkgd = xbps_dictionary_metadata_plist_by_url(file, "./props.plist");
|
2009-11-25 10:02:04 +05:30
|
|
|
if (newpkgd == NULL) {
|
2012-01-17 15:20:35 +05:30
|
|
|
xbps_error_printf("failed to read %s metadata for `%s',"
|
|
|
|
" skipping!\n", XBPS_PKGPROPS, file);
|
2009-11-25 10:02:04 +05:30
|
|
|
goto out;
|
|
|
|
}
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname", &pkgname);
|
|
|
|
prop_dictionary_get_cstring_nocopy(newpkgd, "version", &version);
|
2012-05-31 19:59:56 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(newpkgd, "architecture", &arch);
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
2009-11-25 10:02:04 +05:30
|
|
|
* Check if this package exists already in the index, but first
|
|
|
|
* checking the version. If current package version is greater
|
|
|
|
* than current registered package, update the index; otherwise
|
|
|
|
* pass to the next one.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2012-06-15 19:03:11 +05:30
|
|
|
curpkgd = xbps_find_pkg_in_array_by_name(xhp, idx, pkgname, arch);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (curpkgd == NULL) {
|
|
|
|
if (errno && errno != ENOENT) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-31 19:59:56 +05:30
|
|
|
} else {
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd, "version", ®ver);
|
2012-06-01 20:07:44 +05:30
|
|
|
ret = xbps_cmpver(version, regver);
|
|
|
|
if (ret == 0) {
|
|
|
|
/* same version */
|
2012-06-01 14:27:58 +05:30
|
|
|
fprintf(stderr, "index: skipping `%s-%s' (%s), `%s-%s' already "
|
|
|
|
"registered.\n", pkgname, version,
|
|
|
|
arch, pkgname, regver);
|
2009-11-23 15:16:51 +05:30
|
|
|
prop_object_release(newpkgd);
|
2009-11-25 10:02:04 +05:30
|
|
|
rv = EEXIST;
|
|
|
|
goto out;
|
2012-06-01 20:07:44 +05:30
|
|
|
} else if (ret == -1) {
|
|
|
|
/* idx version is greater, remove current binpkg */
|
2012-06-30 14:40:00 +05:30
|
|
|
oldfilepath = xbps_xasprintf("%s/%s/%s",
|
|
|
|
repodir, arch, filen);
|
2012-06-01 20:07:44 +05:30
|
|
|
assert(oldfilepath != NULL);
|
|
|
|
if (remove(oldfilepath) == -1) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_error_printf("failed to remove old binpkg "
|
|
|
|
"`%s': %s\n", oldfilepath, strerror(rv));
|
|
|
|
free(oldfilepath);
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
free(oldfilepath);
|
|
|
|
buf = xbps_xasprintf("`%s-%s' (%s)", pkgname, version, arch);
|
|
|
|
assert(buf != NULL);
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
printf("index: removed obsolete binpkg %s.\n", buf);
|
|
|
|
free(buf);
|
2012-06-01 20:33:05 +05:30
|
|
|
rv = EEXIST;
|
2012-06-01 20:07:44 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-06-01 20:07:44 +05:30
|
|
|
/* current binpkg is greater than idx version */
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd,
|
|
|
|
"filename", &oldfilen);
|
2012-01-17 15:20:35 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd,
|
|
|
|
"pkgver", &oldpkgver);
|
2012-06-01 14:27:58 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd,
|
|
|
|
"architecture", &oldarch);
|
2012-06-01 20:07:44 +05:30
|
|
|
|
2012-01-17 15:55:45 +05:30
|
|
|
buf = strdup(oldpkgver);
|
|
|
|
if (buf == NULL) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-30 14:40:00 +05:30
|
|
|
oldfilepath = xbps_xasprintf("%s/%s/%s",
|
|
|
|
repodir, oldarch, oldfilen);
|
2009-11-25 10:02:04 +05:30
|
|
|
if (oldfilepath == NULL) {
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = errno;
|
2012-01-17 15:55:45 +05:30
|
|
|
prop_object_release(newpkgd);
|
|
|
|
free(buf);
|
2009-11-25 10:02:04 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-25 10:02:04 +05:30
|
|
|
if (remove(oldfilepath) == -1) {
|
2012-01-17 15:55:45 +05:30
|
|
|
rv = errno;
|
2012-01-17 15:20:35 +05:30
|
|
|
xbps_error_printf("failed to remove old "
|
2011-01-30 22:53:33 +05:30
|
|
|
"package file `%s': %s\n", oldfilepath,
|
|
|
|
strerror(errno));
|
2009-11-25 10:02:04 +05:30
|
|
|
free(oldfilepath);
|
2009-11-23 15:16:51 +05:30
|
|
|
prop_object_release(newpkgd);
|
2012-01-17 15:55:45 +05:30
|
|
|
free(buf);
|
2009-11-25 10:02:04 +05:30
|
|
|
goto out;
|
2009-11-23 15:16:51 +05:30
|
|
|
}
|
2009-11-25 10:02:04 +05:30
|
|
|
free(oldfilepath);
|
2012-06-15 19:03:11 +05:30
|
|
|
if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx,
|
|
|
|
buf, oldarch)) {
|
2012-01-17 15:20:35 +05:30
|
|
|
xbps_error_printf("failed to remove `%s' "
|
2012-06-01 14:27:58 +05:30
|
|
|
"from plist index: %s\n", buf, strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_release(newpkgd);
|
2012-01-17 15:55:45 +05:30
|
|
|
free(buf);
|
2009-11-25 10:02:04 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-06-01 14:27:58 +05:30
|
|
|
printf("index: removed obsolete entry/binpkg `%s' "
|
|
|
|
"(%s).\n", buf, arch);
|
2012-01-17 15:55:45 +05:30
|
|
|
free(buf);
|
2009-11-25 10:02:04 +05:30
|
|
|
}
|
2009-11-24 08:36:06 +05:30
|
|
|
|
2009-11-25 10:02:04 +05:30
|
|
|
/*
|
|
|
|
* We have the dictionary now, add the required
|
|
|
|
* objects for the index.
|
|
|
|
*/
|
|
|
|
if (!prop_dictionary_set_cstring(newpkgd, "filename", filen)) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-01 20:33:05 +05:30
|
|
|
if ((sha256 = xbps_file_hash(file)) == NULL) {
|
2009-11-25 10:02:04 +05:30
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!prop_dictionary_set_cstring(newpkgd, "filename-sha256", sha256)) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
free(sha256);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
free(sha256);
|
|
|
|
if (stat(file, &st) == -1) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!prop_dictionary_set_uint64(newpkgd, "filename-size",
|
|
|
|
(uint64_t)st.st_size)) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Add dictionary into the index and update package count.
|
|
|
|
*/
|
2012-01-19 16:56:40 +05:30
|
|
|
if (!xbps_add_obj_to_array(idx, newpkgd)) {
|
2009-11-25 10:02:04 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-06-01 14:27:58 +05:30
|
|
|
printf("index: added `%s-%s' (%s).\n", pkgname, version, arch);
|
2009-11-25 10:02:04 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
out:
|
2009-11-24 08:36:06 +05:30
|
|
|
if (tmpfilen)
|
|
|
|
free(tmpfilen);
|
2009-08-18 17:42:44 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
repo_genindex(struct xbps_handle *xhp, const char *pkgdir)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2012-01-19 16:56:40 +05:30
|
|
|
prop_array_t idx = NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
struct dirent *dp;
|
|
|
|
DIR *dirp;
|
2012-05-31 19:59:56 +05:30
|
|
|
size_t i;
|
|
|
|
char *curdir;
|
2011-11-08 00:58:35 +05:30
|
|
|
char *binfile, *plist;
|
2009-08-17 22:37:20 +05:30
|
|
|
int rv = 0;
|
2009-11-18 11:04:39 +05:30
|
|
|
bool registered_newpkgs = false, foundpkg = false;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-18 11:04:39 +05:30
|
|
|
/*
|
|
|
|
* Create or read existing package index plist file.
|
|
|
|
*/
|
2012-06-14 11:52:11 +05:30
|
|
|
idx = repoidx_get(xhp, pkgdir);
|
2012-01-19 16:56:40 +05:30
|
|
|
if (idx == NULL)
|
2009-11-18 11:04:39 +05:30
|
|
|
return errno;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
plist = xbps_pkg_index_plist(xhp, pkgdir);
|
2009-11-18 11:04:39 +05:30
|
|
|
if (plist == NULL) {
|
2012-01-19 16:56:40 +05:30
|
|
|
prop_object_release(idx);
|
2009-11-18 11:04:39 +05:30
|
|
|
return errno;
|
|
|
|
}
|
2011-11-08 00:58:35 +05:30
|
|
|
|
2012-05-31 19:59:56 +05:30
|
|
|
for (i = 0; i < __arraycount(archs); i++) {
|
|
|
|
curdir = xbps_xasprintf("%s/%s", pkgdir, archs[i]);
|
|
|
|
assert(curdir != NULL);
|
2011-11-08 00:58:35 +05:30
|
|
|
|
2012-05-31 19:59:56 +05:30
|
|
|
dirp = opendir(curdir);
|
|
|
|
if (dirp == NULL) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
free(curdir);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
xbps_error_printf("xbps-repo: cannot open `%s': %s\n",
|
|
|
|
curdir, strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-05-31 19:59:56 +05:30
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if ((strcmp(dp->d_name, ".") == 0) ||
|
|
|
|
(strcmp(dp->d_name, "..") == 0))
|
|
|
|
continue;
|
|
|
|
/* Ignore unknown files */
|
|
|
|
if (strstr(dp->d_name, ".xbps") == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
foundpkg = true;
|
|
|
|
binfile = xbps_xasprintf("%s/%s", curdir, dp->d_name);
|
|
|
|
if (binfile == NULL) {
|
|
|
|
(void)closedir(dirp);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-30 14:40:00 +05:30
|
|
|
rv = add_binpkg_to_index(xhp, idx, pkgdir, binfile);
|
2012-05-31 19:59:56 +05:30
|
|
|
free(binfile);
|
|
|
|
if (rv == EEXIST) {
|
|
|
|
rv = 0;
|
|
|
|
continue;
|
|
|
|
} else if (rv != 0) {
|
|
|
|
(void)closedir(dirp);
|
|
|
|
free(curdir);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
registered_newpkgs = true;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2012-05-31 19:59:56 +05:30
|
|
|
(void)closedir(dirp);
|
|
|
|
free(curdir);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
2009-11-18 11:04:39 +05:30
|
|
|
if (foundpkg == false) {
|
|
|
|
/* No packages were found in directory */
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = ENOENT;
|
2009-11-18 11:04:39 +05:30
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Show total count registered packages.
|
|
|
|
*/
|
2012-06-01 14:27:58 +05:30
|
|
|
printf("index: %zu packages registered.\n",
|
2012-01-19 16:56:40 +05:30
|
|
|
(size_t)prop_array_count(idx));
|
2009-11-18 11:04:39 +05:30
|
|
|
/*
|
|
|
|
* Don't write plist file if no packages were registered.
|
|
|
|
*/
|
|
|
|
if (registered_newpkgs == false)
|
2009-11-19 04:41:06 +05:30
|
|
|
goto out;
|
2009-11-18 11:04:39 +05:30
|
|
|
/*
|
|
|
|
* If any package was registered in package index, write
|
|
|
|
* plist file to storage.
|
|
|
|
*/
|
2012-01-19 16:56:40 +05:30
|
|
|
if (!prop_array_externalize_to_zfile(idx, plist))
|
2009-11-18 11:04:39 +05:30
|
|
|
rv = errno;
|
|
|
|
}
|
2009-11-19 04:41:06 +05:30
|
|
|
out:
|
2009-11-18 11:47:45 +05:30
|
|
|
free(plist);
|
2012-01-19 16:56:40 +05:30
|
|
|
prop_object_release(idx);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|