2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
2011-05-27 21:02:42 +05:30
|
|
|
* Copyright (c) 2009-2011 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>
|
2009-08-17 22:37:20 +05:30
|
|
|
#include <sys/utsname.h>
|
|
|
|
#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
|
|
|
|
|
|
|
/* Array of valid architectures */
|
|
|
|
static const char *archdirs[] = { "i686", "x86_64", "noarch", NULL };
|
|
|
|
|
2011-07-09 16:48:11 +05:30
|
|
|
/*
|
|
|
|
* Removes stalled pkg entries in repository's pkg-index.plist file, if any
|
|
|
|
* binary package cannot be read (unavailable, not enough perms, etc).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
remove_missing_binpkg_entries(const char *repodir)
|
|
|
|
{
|
|
|
|
prop_array_t pkgarray;
|
|
|
|
prop_dictionary_t idxd, pkgd;
|
2011-07-09 17:03:48 +05:30
|
|
|
const char *arch, *filen;
|
2011-07-09 16:48:11 +05:30
|
|
|
char *binpkg, *plist;
|
|
|
|
size_t i;
|
|
|
|
int rv = 0;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
plist = xbps_pkg_index_plist(repodir);
|
|
|
|
if (plist == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
idxd = prop_dictionary_internalize_from_zfile(plist);
|
|
|
|
if (idxd == NULL) {
|
|
|
|
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:
|
|
|
|
pkgarray = prop_dictionary_get(idxd, "packages");
|
|
|
|
if (prop_object_type(pkgarray) != PROP_TYPE_ARRAY)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < prop_array_count(pkgarray); i++) {
|
|
|
|
pkgd = prop_array_get(pkgarray, i);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
|
|
|
|
prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen);
|
|
|
|
binpkg = xbps_xasprintf("%s/%s/%s", repodir, arch, filen);
|
|
|
|
if (binpkg == NULL) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (access(binpkg, R_OK) == -1) {
|
|
|
|
xbps_warn_printf("xbps-repo: `%s' unavailable, "
|
|
|
|
"removing entry from index... (%s)\n",
|
|
|
|
filen, strerror(errno));
|
|
|
|
prop_array_remove(pkgarray, i);
|
|
|
|
free(binpkg);
|
|
|
|
found = true;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
free(binpkg);
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
prop_dictionary_set_uint64(idxd, "total-pkgs",
|
|
|
|
prop_array_count(pkgarray));
|
|
|
|
prop_dictionary_set(idxd, "packages", pkgarray);
|
|
|
|
if (!prop_dictionary_externalize_to_zfile(idxd, plist))
|
|
|
|
rv = errno;
|
|
|
|
}
|
|
|
|
free(plist);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
static prop_dictionary_t
|
|
|
|
repoidx_getdict(const char *pkgdir)
|
|
|
|
{
|
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_array_t array;
|
|
|
|
char *plist;
|
2011-07-09 16:48:11 +05:30
|
|
|
int rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove entries in repositories pkg-index for unexistent
|
|
|
|
* packages, i.e dangling entries.
|
|
|
|
*/
|
|
|
|
if ((rv = remove_missing_binpkg_entries(pkgdir)) != 0)
|
|
|
|
return NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
plist = xbps_pkg_index_plist(pkgdir);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (plist == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-04-20 17:52:38 +05:30
|
|
|
dict = prop_dictionary_internalize_from_zfile(plist);
|
2009-08-17 22:37:20 +05:30
|
|
|
if (dict == NULL) {
|
|
|
|
dict = prop_dictionary_create();
|
|
|
|
if (dict == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
array = prop_array_create();
|
|
|
|
if (array == NULL) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_set(dict, "packages", array)) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
prop_object_release(array);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_release(array);
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_set_cstring_nocopy(dict,
|
|
|
|
"pkgindex-version", XBPS_PKGINDEX_VERSION)) {
|
|
|
|
prop_object_release(dict);
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
out:
|
|
|
|
free(plist);
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2009-11-24 16:41:23 +05:30
|
|
|
static int
|
2011-07-09 16:48:11 +05:30
|
|
|
add_binpkg_to_index(prop_dictionary_t idxdict,
|
|
|
|
const char *filedir,
|
|
|
|
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
|
|
|
prop_array_t pkgar;
|
|
|
|
struct stat st;
|
2009-11-24 08:36:06 +05:30
|
|
|
const char *pkgname, *version, *regver, *oldfilen;
|
|
|
|
char *sha256, *filen, *tmpfilen, *tmpstr, *oldfilepath;
|
2009-11-25 10:02:04 +05:30
|
|
|
int rv = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-11-24 08:36:06 +05:30
|
|
|
if (idxdict == NULL || file == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
newpkgd = xbps_dictionary_metadata_plist_by_url(file, XBPS_PKGPROPS);
|
2009-11-25 10:02:04 +05:30
|
|
|
if (newpkgd == NULL) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-repo: can't read %s %s metadata "
|
2010-01-15 19:49:16 +05:30
|
|
|
"file, skipping!\n", file, XBPS_PKGPROPS);
|
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);
|
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
|
|
|
*/
|
2010-01-14 06:44:31 +05:30
|
|
|
curpkgd = xbps_find_pkg_in_dict_by_name(idxdict, "packages", pkgname);
|
2009-11-26 07:52:50 +05:30
|
|
|
if (curpkgd == NULL) {
|
|
|
|
if (errno && errno != ENOENT) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else if (curpkgd) {
|
2011-07-11 13:42:42 +05:30
|
|
|
/*
|
|
|
|
* Ignore packages providing virtual packages greater than or
|
|
|
|
* equal than current package.
|
|
|
|
*/
|
|
|
|
if (xbps_find_virtual_pkg_in_dict(curpkgd, pkgname, false)) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = EEXIST;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd, "version", ®ver);
|
2009-11-25 10:02:04 +05:30
|
|
|
if (xbps_cmpver(version, regver) <= 0) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_warn_printf("skipping %s. %s-%s already "
|
2009-11-25 10:02:04 +05:30
|
|
|
"registered.\n", filen, 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;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
/*
|
2009-11-25 10:02:04 +05:30
|
|
|
* Current binpkg is newer than the one registered
|
|
|
|
* in package index, remove outdated binpkg file
|
|
|
|
* and its dictionary from the pkg index.
|
2009-08-17 22:37:20 +05:30
|
|
|
*/
|
2010-11-06 11:14:00 +05:30
|
|
|
prop_dictionary_get_cstring_nocopy(curpkgd,
|
|
|
|
"filename", &oldfilen);
|
2009-11-25 10:02:04 +05:30
|
|
|
oldfilepath = xbps_xasprintf("%s/%s", filedir, oldfilen);
|
|
|
|
if (oldfilepath == NULL) {
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
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) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-repo: couldn't remove old "
|
|
|
|
"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);
|
|
|
|
rv = errno;
|
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);
|
|
|
|
tmpstr = strdup(oldfilen);
|
|
|
|
if (tmpstr == NULL) {
|
2009-11-18 11:47:45 +05:30
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
2009-11-25 10:02:04 +05:30
|
|
|
goto out;
|
2009-11-18 11:47:45 +05:30
|
|
|
}
|
2011-01-27 22:52:57 +05:30
|
|
|
if (!xbps_remove_pkg_from_dict_by_name(idxdict,
|
|
|
|
"packages", pkgname)) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-repo: couldn't remove `%s' "
|
|
|
|
"from plist index: %s\n", pkgname, strerror(errno));
|
2009-08-17 22:37:20 +05:30
|
|
|
prop_object_release(newpkgd);
|
2009-11-25 10:02:04 +05:30
|
|
|
free(tmpstr);
|
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_warn_printf("xbps-repo: removed outdated binpkg file for "
|
2010-01-15 19:49:16 +05:30
|
|
|
"'%s'.\n", tmpstr);
|
2009-11-25 10:02:04 +05:30
|
|
|
free(tmpstr);
|
|
|
|
}
|
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;
|
|
|
|
}
|
2011-06-01 13:07:32 +05:30
|
|
|
sha256 = xbps_file_hash(file);
|
2009-11-25 10:02:04 +05:30
|
|
|
if (sha256 == NULL) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
/* Get package array in repo index file */
|
|
|
|
pkgar = prop_dictionary_get(idxdict, "packages");
|
|
|
|
if (pkgar == NULL) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Add dictionary into the index and update package count.
|
|
|
|
*/
|
|
|
|
if (!xbps_add_obj_to_array(pkgar, newpkgd)) {
|
|
|
|
prop_object_release(newpkgd);
|
|
|
|
rv = EINVAL;
|
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-25 10:02:04 +05:30
|
|
|
printf("Registered %s-%s (%s) in package index.\n",
|
|
|
|
pkgname, version, filen);
|
|
|
|
|
|
|
|
if (!prop_dictionary_set_uint64(idxdict, "total-pkgs",
|
|
|
|
prop_array_count(pkgar)))
|
|
|
|
rv = errno;
|
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
|
|
|
|
xbps_repo_genindex(const char *pkgdir)
|
|
|
|
{
|
2009-11-18 11:04:39 +05:30
|
|
|
prop_dictionary_t idxdict = NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
struct dirent *dp;
|
|
|
|
DIR *dirp;
|
|
|
|
struct utsname un;
|
2009-11-18 11:04:39 +05:30
|
|
|
uint64_t npkgcnt = 0;
|
|
|
|
char *binfile, *path, *plist;
|
2009-08-17 22:37:20 +05:30
|
|
|
size_t i;
|
|
|
|
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
|
|
|
|
|
|
|
if (uname(&un) == -1)
|
|
|
|
return errno;
|
2009-11-18 11:04:39 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Create or read existing package index plist file.
|
|
|
|
*/
|
|
|
|
idxdict = repoidx_getdict(pkgdir);
|
|
|
|
if (idxdict == NULL)
|
|
|
|
return errno;
|
|
|
|
|
2011-06-01 13:07:32 +05:30
|
|
|
plist = xbps_pkg_index_plist(pkgdir);
|
2009-11-18 11:04:39 +05:30
|
|
|
if (plist == NULL) {
|
|
|
|
prop_object_release(idxdict);
|
|
|
|
return errno;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Iterate over the known architecture directories to find
|
|
|
|
* binary packages.
|
|
|
|
*/
|
|
|
|
for (i = 0; archdirs[i] != NULL; i++) {
|
|
|
|
if ((strcmp(archdirs[i], un.machine)) &&
|
|
|
|
(strcmp(archdirs[i], "noarch")))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
path = xbps_xasprintf("%s/%s", pkgdir, archdirs[i]);
|
2009-11-18 11:04:39 +05:30
|
|
|
if (path == NULL) {
|
2009-11-19 04:41:06 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2009-11-18 11:04:39 +05:30
|
|
|
}
|
2011-07-09 14:51:17 +05:30
|
|
|
/*
|
|
|
|
* If repo/<noarch|un.machine> does not exist,
|
|
|
|
* create it.
|
|
|
|
*/
|
|
|
|
if ((access(path, X_OK) == -1) && errno == ENOENT) {
|
|
|
|
if (xbps_mkpath(path, 0755) == -1) {
|
|
|
|
xbps_error_printf("xbps-repo: cannot "
|
|
|
|
"create %s directory: %s\n",
|
|
|
|
path, strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
dirp = opendir(path);
|
|
|
|
if (dirp == NULL) {
|
2011-01-30 22:53:33 +05:30
|
|
|
xbps_error_printf("xbps-repo: unexistent '%s' "
|
|
|
|
"directory!\n", path);
|
2009-08-17 22:37:20 +05:30
|
|
|
free(path);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
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", path, dp->d_name);
|
|
|
|
if (binfile == NULL) {
|
|
|
|
(void)closedir(dirp);
|
|
|
|
free(path);
|
2009-11-19 04:41:06 +05:30
|
|
|
rv = errno;
|
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2011-07-09 16:48:11 +05:30
|
|
|
rv = add_binpkg_to_index(idxdict, path, binfile);
|
2009-08-17 22:37:20 +05:30
|
|
|
free(binfile);
|
2010-05-18 06:12:21 +05:30
|
|
|
if (rv == EEXIST) {
|
|
|
|
rv = 0;
|
2009-11-18 11:04:39 +05:30
|
|
|
continue;
|
2010-05-18 06:12:21 +05:30
|
|
|
}
|
2009-11-18 11:04:39 +05:30
|
|
|
else if (rv != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
(void)closedir(dirp);
|
|
|
|
free(path);
|
2009-11-19 04:41:06 +05:30
|
|
|
goto out;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-11-18 11:04:39 +05:30
|
|
|
registered_newpkgs = true;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
(void)closedir(dirp);
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
prop_dictionary_get_uint64(idxdict, "total-pkgs", &npkgcnt);
|
|
|
|
printf("%ju packages registered in package index.\n", npkgcnt);
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-04-20 17:52:38 +05:30
|
|
|
if (!prop_dictionary_externalize_to_zfile(idxdict, 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);
|
|
|
|
prop_object_release(idxdict);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|