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