xbps-repo: misc fixes/improvements to index{,-files}.c code.
This commit is contained in:
parent
652e9afcef
commit
b20dffd2c0
@ -37,7 +37,6 @@ struct index_files_data {
|
||||
prop_array_t idxfiles;
|
||||
prop_array_t obsoletes;
|
||||
const char *pkgdir;
|
||||
const char *targetarch;
|
||||
bool flush;
|
||||
bool new;
|
||||
};
|
||||
@ -74,10 +73,10 @@ static int
|
||||
genindex_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
{
|
||||
prop_object_t obj2, fileobj;
|
||||
prop_dictionary_t pkg_filesd, pkgd, regpkgd;
|
||||
prop_array_t array, files;
|
||||
prop_dictionary_t pkg_filesd, pkgd;
|
||||
prop_array_t files, pkg_cffiles, pkg_files, pkg_links;
|
||||
struct index_files_data *ifd = arg;
|
||||
const char *binpkg, *pkgver, *rpkgver, *arch;
|
||||
const char *binpkg, *pkgver, *arch;
|
||||
char *file;
|
||||
bool found = false;
|
||||
size_t i;
|
||||
@ -88,31 +87,12 @@ genindex_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
||||
|
||||
if (ifd->new)
|
||||
goto start;
|
||||
|
||||
regpkgd = xbps_find_pkg_in_array_by_pkgver(ifd->idxfiles, pkgver, arch);
|
||||
if (regpkgd) {
|
||||
/*
|
||||
* pkg already registered, check if same version
|
||||
* is registered.
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(regpkgd, "pkgver", &rpkgver);
|
||||
if (strcmp(pkgver, rpkgver) == 0) {
|
||||
/* same pkg */
|
||||
xbps_warn_printf("skipping `%s', already registered.\n",
|
||||
rpkgver);
|
||||
return 0;
|
||||
}
|
||||
/* pkgver does not match, remove it from index-files */
|
||||
if (!xbps_remove_pkg_from_array_by_pkgver(ifd->idxfiles,
|
||||
rpkgver, arch))
|
||||
return EINVAL;
|
||||
printf("Removed obsolete entry for `%s' from "
|
||||
"files index.\n", rpkgver);
|
||||
if (xbps_find_pkg_in_array_by_pkgver(ifd->idxfiles, pkgver, arch)) {
|
||||
fprintf(stderr, "index-files: skipping `%s' (%s), "
|
||||
"already registered.\n", pkgver, arch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
start:
|
||||
file = xbps_xasprintf("%s/%s/%s", ifd->pkgdir, arch, binpkg);
|
||||
if (file == NULL)
|
||||
return ENOMEM;
|
||||
@ -125,6 +105,31 @@ start:
|
||||
}
|
||||
free(file);
|
||||
|
||||
/* Find out if binary pkg stored in index contain any file */
|
||||
pkg_cffiles = prop_dictionary_get(pkg_filesd, "conf_files");
|
||||
if (pkg_cffiles != NULL && prop_array_count(pkg_cffiles))
|
||||
found = true;
|
||||
else
|
||||
pkg_cffiles = NULL;
|
||||
|
||||
pkg_files = prop_dictionary_get(pkg_filesd, "files");
|
||||
if (pkg_files != NULL && prop_array_count(pkg_files))
|
||||
found = true;
|
||||
else
|
||||
pkg_files = NULL;
|
||||
|
||||
pkg_links = prop_dictionary_get(pkg_filesd, "links");
|
||||
if (pkg_links != NULL && prop_array_count(pkg_links))
|
||||
found = true;
|
||||
else
|
||||
pkg_links = NULL;
|
||||
|
||||
/* If pkg does not contain any file, ignore it */
|
||||
if (!found) {
|
||||
prop_object_release(pkg_filesd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* create pkg dictionary */
|
||||
if ((pkgd = prop_dictionary_create()) == NULL) {
|
||||
prop_object_release(pkg_filesd);
|
||||
@ -154,11 +159,9 @@ start:
|
||||
}
|
||||
|
||||
/* add conf_files in pkgd */
|
||||
array = prop_dictionary_get(pkg_filesd, "conf_files");
|
||||
if (array != NULL && prop_array_count(array)) {
|
||||
found = true;
|
||||
for (i = 0; i < prop_array_count(array); i++) {
|
||||
obj2 = prop_array_get(array, i);
|
||||
if (pkg_cffiles != NULL) {
|
||||
for (i = 0; i < prop_array_count(pkg_cffiles); i++) {
|
||||
obj2 = prop_array_get(pkg_cffiles, i);
|
||||
fileobj = prop_dictionary_get(obj2, "file");
|
||||
if (!prop_array_add(files, fileobj)) {
|
||||
prop_object_release(pkgd);
|
||||
@ -168,11 +171,9 @@ start:
|
||||
}
|
||||
}
|
||||
/* add files array in pkgd */
|
||||
array = prop_dictionary_get(pkg_filesd, "files");
|
||||
if (array != NULL && prop_array_count(array)) {
|
||||
found = true;
|
||||
for (i = 0; i < prop_array_count(array); i++) {
|
||||
obj2 = prop_array_get(array, i);
|
||||
if (pkg_files != NULL) {
|
||||
for (i = 0; i < prop_array_count(pkg_files); i++) {
|
||||
obj2 = prop_array_get(pkg_files, i);
|
||||
fileobj = prop_dictionary_get(obj2, "file");
|
||||
if (!prop_array_add(files, fileobj)) {
|
||||
prop_object_release(pkgd);
|
||||
@ -182,11 +183,9 @@ start:
|
||||
}
|
||||
}
|
||||
/* add links array in pkgd */
|
||||
array = prop_dictionary_get(pkg_filesd, "links");
|
||||
if (array != NULL && prop_array_count(array)) {
|
||||
found = true;
|
||||
for (i = 0; i < prop_array_count(array); i++) {
|
||||
obj2 = prop_array_get(array, i);
|
||||
if (pkg_links != NULL) {
|
||||
for (i = 0; i < prop_array_count(pkg_links); i++) {
|
||||
obj2 = prop_array_get(pkg_links, i);
|
||||
fileobj = prop_dictionary_get(obj2, "file");
|
||||
if (!prop_array_add(files, fileobj)) {
|
||||
prop_object_release(pkgd);
|
||||
@ -196,18 +195,14 @@ start:
|
||||
}
|
||||
}
|
||||
prop_object_release(pkg_filesd);
|
||||
if (!found) {
|
||||
prop_object_release(pkgd);
|
||||
return 0;
|
||||
}
|
||||
/* add pkgd into provided array */
|
||||
if (!prop_array_add(ifd->idxfiles, pkgd)) {
|
||||
prop_object_release(pkgd);
|
||||
return EINVAL;
|
||||
}
|
||||
printf("index-files: added `%s' (%s)\n", pkgver, arch);
|
||||
prop_object_release(pkgd);
|
||||
ifd->flush = true;
|
||||
printf("Registered `%s' in repository files index.\n", pkgver);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -250,7 +245,7 @@ repo_genindex_files(const char *pkgdir)
|
||||
}
|
||||
ifd->pkgdir = pkgdir;
|
||||
ifd->idxfiles = prop_array_internalize_from_zfile(plist);
|
||||
ifd->idx = prop_array_copy(idx);
|
||||
ifd->idx = idx;
|
||||
ifd->obsoletes = prop_array_create();
|
||||
if (ifd->idxfiles == NULL) {
|
||||
/* missing file, create new one */
|
||||
@ -258,11 +253,6 @@ repo_genindex_files(const char *pkgdir)
|
||||
ifd->new = true;
|
||||
}
|
||||
|
||||
/* iterate over index.plist array */
|
||||
rv = xbps_callback_array_iter(idx, genindex_files_cb, ifd);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
|
||||
/* remove obsolete pkg entries */
|
||||
if (!ifd->new) {
|
||||
rv = xbps_callback_array_iter(ifd->idxfiles,
|
||||
@ -285,11 +275,15 @@ repo_genindex_files(const char *pkgdir)
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
printf("Removed obsolete entry for `%s' "
|
||||
"from files index.\n", pkgver);
|
||||
printf("index-files: removed obsolete entry `%s' "
|
||||
"(%s)\n", pkgver, arch);
|
||||
free(pkgver);
|
||||
}
|
||||
}
|
||||
/* iterate over index.plist array */
|
||||
if ((rv = xbps_callback_array_iter(idx, genindex_files_cb, ifd)) != 0)
|
||||
goto out;
|
||||
|
||||
if (!ifd->flush)
|
||||
goto out;
|
||||
|
||||
@ -300,14 +294,10 @@ repo_genindex_files(const char *pkgdir)
|
||||
}
|
||||
out:
|
||||
if (rv == 0)
|
||||
printf("%u packages registered in repository files index.\n",
|
||||
printf("index-files: %u packages registered.\n",
|
||||
prop_array_count(ifd->idxfiles));
|
||||
if (ifd->obsoletes != NULL)
|
||||
prop_object_release(ifd->obsoletes);
|
||||
if (ifd->idxfiles != NULL)
|
||||
prop_object_release(ifd->idxfiles);
|
||||
if (ifd->idx != NULL)
|
||||
prop_object_release(ifd->idx);
|
||||
if (plist != NULL)
|
||||
free(plist);
|
||||
if (ifd != NULL)
|
||||
|
@ -86,8 +86,8 @@ again:
|
||||
break;
|
||||
}
|
||||
if (access(binpkg, R_OK) == -1) {
|
||||
printf("Removed obsolete entry for `%s' "
|
||||
"from index.\n", pkgver);
|
||||
printf("index: removed obsolete entry `%s' (%s)\n",
|
||||
pkgver, arch);
|
||||
prop_array_remove(array, i);
|
||||
free(binpkg);
|
||||
found = true;
|
||||
@ -136,7 +136,8 @@ add_binpkg_to_index(prop_array_t idx,
|
||||
{
|
||||
prop_dictionary_t newpkgd, curpkgd;
|
||||
struct stat st;
|
||||
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver, *arch;
|
||||
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver;
|
||||
const char *arch, *oldarch;
|
||||
char *sha256, *filen, *tmpfilen, *oldfilepath, *buf;
|
||||
int rv = 0;
|
||||
|
||||
@ -175,8 +176,9 @@ add_binpkg_to_index(prop_array_t idx,
|
||||
} else {
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd, "version", ®ver);
|
||||
if (xbps_cmpver(version, regver) <= 0) {
|
||||
xbps_warn_printf("skipping `%s', `%s-%s' already "
|
||||
"registered.\n", filen, pkgname, regver);
|
||||
fprintf(stderr, "index: skipping `%s-%s' (%s), `%s-%s' already "
|
||||
"registered.\n", pkgname, version,
|
||||
arch, pkgname, regver);
|
||||
prop_object_release(newpkgd);
|
||||
rv = EEXIST;
|
||||
goto out;
|
||||
@ -190,6 +192,8 @@ add_binpkg_to_index(prop_array_t idx,
|
||||
"filename", &oldfilen);
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||
"pkgver", &oldpkgver);
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||
"architecture", &oldarch);
|
||||
buf = strdup(oldpkgver);
|
||||
if (buf == NULL) {
|
||||
prop_object_release(newpkgd);
|
||||
@ -214,15 +218,15 @@ add_binpkg_to_index(prop_array_t idx,
|
||||
goto out;
|
||||
}
|
||||
free(oldfilepath);
|
||||
if (!xbps_remove_pkg_from_array_by_name(idx, pkgname, arch)) {
|
||||
if (!xbps_remove_pkg_from_array_by_pkgver(idx, buf, oldarch)) {
|
||||
xbps_error_printf("failed to remove `%s' "
|
||||
"from plist index: %s\n", pkgname, strerror(errno));
|
||||
"from plist index: %s\n", buf, strerror(errno));
|
||||
prop_object_release(newpkgd);
|
||||
free(buf);
|
||||
goto out;
|
||||
}
|
||||
printf("Removed obsolete package entry/binpkg for `%s'.\n",
|
||||
buf);
|
||||
printf("index: removed obsolete entry/binpkg `%s' "
|
||||
"(%s).\n", buf, arch);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
@ -266,8 +270,7 @@ add_binpkg_to_index(prop_array_t idx,
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
printf("Registered `%s-%s' (%s) in repository index.\n",
|
||||
pkgname, version, filen);
|
||||
printf("index: added `%s-%s' (%s).\n", pkgname, version, arch);
|
||||
|
||||
out:
|
||||
if (tmpfilen)
|
||||
@ -353,7 +356,7 @@ repo_genindex(const char *pkgdir)
|
||||
/*
|
||||
* Show total count registered packages.
|
||||
*/
|
||||
printf("%zu packages registered in repository index.\n",
|
||||
printf("index: %zu packages registered.\n",
|
||||
(size_t)prop_array_count(idx));
|
||||
/*
|
||||
* Don't write plist file if no packages were registered.
|
||||
|
Loading…
Reference in New Issue
Block a user