xbps_array_t xbps_find_pkg_obsoletes(struct xbps_handle *xhp, xbps_dictionary_t instd, xbps_dictionary_t newd) { xbps_array_t instfiles, newfiles, obsoletes; xbps_object_t obj, obj2; xbps_string_t oldstr, newstr; unsigned int i, x; const char *oldhash; char *file; int rv = 0; bool found; assert(xbps_object_type(instd) == XBPS_TYPE_DICTIONARY); assert(xbps_object_type(newd) == XBPS_TYPE_DICTIONARY); obsoletes = xbps_array_create(); assert(obsoletes); instfiles = merge_filelist(instd); if (xbps_array_count(instfiles) == 0) { /* nothing to check if current pkg does not own any file */ xbps_object_release(instfiles); return obsoletes; } newfiles = merge_filelist(newd); /* * Iterate over files list from installed package. */ for (i = 0; i < xbps_array_count(instfiles); i++) { found = false; obj = xbps_array_get(instfiles, i); if (xbps_object_type(obj) != XBPS_TYPE_DICTIONARY) { /* ignore unexistent files */ continue; } oldstr = xbps_dictionary_get(obj, "file"); if (oldstr == NULL) continue; file = xbps_xasprintf(".%s", xbps_string_cstring_nocopy(oldstr)); oldhash = NULL; xbps_dictionary_get_cstring_nocopy(obj, "sha256", &oldhash); if (oldhash) { rv = xbps_file_hash_check(file, oldhash); if (rv == ENOENT || rv == ERANGE) { /* * Skip unexistent and files that do not * match the hash. */ free(file); continue; } } /* * Check if current file is available in new pkg filelist. */ for (x = 0; x < xbps_array_count(newfiles); x++) { obj2 = xbps_array_get(newfiles, x); newstr = xbps_dictionary_get(obj2, "file"); assert(newstr); /* * Skip files with same path. */ if (xbps_string_equals(oldstr, newstr)) { found = true; break; } } if (found) { free(file); continue; } /* * Do not add required symlinks for the * system transition to /usr. */ if ((strcmp(file, "./bin") == 0) || (strcmp(file, "./bin/") == 0) || (strcmp(file, "./sbin") == 0) || (strcmp(file, "./sbin/") == 0) || (strcmp(file, "./lib") == 0) || (strcmp(file, "./lib/") == 0) || (strcmp(file, "./lib64/") == 0) || (strcmp(file, "./lib64") == 0)) { free(file); continue; } /* * Obsolete found, add onto the array. */ xbps_dbg_printf(xhp, "found obsolete: %s\n", file); xbps_array_add_cstring(obsoletes, file); free(file); } xbps_object_release(instfiles); xbps_object_release(newfiles); return obsoletes; }
static int add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg) { xbps_array_t mdeps; xbps_object_iterator_t iter = NULL; xbps_object_t obj; unsigned int idx = 0; bool add_pkgdep, pkgfound, update_pkgdep; int rv = 0; assert(reqpkg != NULL); add_pkgdep = update_pkgdep = pkgfound = false; mdeps = xbps_dictionary_get(xhp->transd, "missing_deps"); iter = xbps_array_iterator(mdeps); if (iter == NULL) goto out; while ((obj = xbps_object_iterator_next(iter)) != NULL) { const char *curdep, *curver, *pkgver; char *curpkgnamedep = NULL, *pkgnamedep = NULL; assert(xbps_object_type(obj) == XBPS_TYPE_STRING); curdep = xbps_string_cstring_nocopy(obj); curver = xbps_pkgpattern_version(curdep); pkgver = xbps_pkgpattern_version(reqpkg); if (curver == NULL || pkgver == NULL) goto out; curpkgnamedep = xbps_pkgpattern_name(curdep); if (curpkgnamedep == NULL) goto out; pkgnamedep = xbps_pkgpattern_name(reqpkg); if (pkgnamedep == NULL) { free(curpkgnamedep); goto out; } if (strcmp(pkgnamedep, curpkgnamedep) == 0) { pkgfound = true; if (strcmp(curver, pkgver) == 0) { free(curpkgnamedep); free(pkgnamedep); rv = EEXIST; goto out; } /* * if new dependency version is greater than current * one, store it. */ xbps_dbg_printf(xhp, "Missing pkgdep name matched, curver: %s newver: %s\n", curver, pkgver); if (xbps_cmpver(curver, pkgver) <= 0) { add_pkgdep = false; free(curpkgnamedep); free(pkgnamedep); rv = EEXIST; goto out; } update_pkgdep = true; } free(curpkgnamedep); free(pkgnamedep); if (pkgfound) break; idx++; } add_pkgdep = true; out: if (iter) xbps_object_iterator_release(iter); if (update_pkgdep) xbps_array_remove(mdeps, idx); if (add_pkgdep) { char *str; str = xbps_xasprintf("MISSING: %s", reqpkg); xbps_array_add_cstring(mdeps, str); free(str); } return rv; }
static bool repodata_commit(struct xbps_handle *xhp, const char *repodir, xbps_dictionary_t idx, xbps_dictionary_t meta, xbps_dictionary_t stage) { const char *pkgname; xbps_object_iterator_t iter; xbps_object_t keysym; int rv; if(xbps_dictionary_count(stage) == 0) { // Nothing to do. return true; } /* * Find old shlibs-provides */ xbps_dictionary_t oldshlibs = xbps_dictionary_create(); xbps_dictionary_t usedshlibs = xbps_dictionary_create(); iter = xbps_dictionary_iterator(stage); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t oldpkg = xbps_dictionary_get(idx, pkgname); xbps_array_t pkgshlibs = xbps_dictionary_get(oldpkg, "shlib-provides"); for(unsigned int i = 0; i < xbps_array_count(pkgshlibs); i++) { const char *shlib = NULL; xbps_array_get_cstring_nocopy(pkgshlibs, i, &shlib); xbps_dictionary_set_cstring(oldshlibs, shlib, pkgname); } } xbps_object_iterator_release(iter); /* * throw away all unused shlibs */ iter = xbps_dictionary_iterator(idx); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t pkg = xbps_dictionary_get(stage, pkgname); if(!pkg) pkg = xbps_dictionary_get_keysym(idx, keysym); xbps_array_t pkgshlibs = xbps_dictionary_get(pkg, "shlib-requires"); for(unsigned int i = 0; i < xbps_array_count(pkgshlibs); i++) { const char *shlib = NULL, *user = NULL; xbps_array_get_cstring_nocopy(pkgshlibs, i, &shlib); xbps_dictionary_get_cstring_nocopy(pkg, shlib, &user); if(!user) continue; xbps_array_t users = xbps_dictionary_get(usedshlibs, shlib); if(!users) { users = xbps_array_create(); xbps_dictionary_set(usedshlibs, shlib, users); } xbps_array_add_cstring(users, user); } } xbps_object_iterator_release(iter); /* * purge all packages that are fullfilled by the stage */ iter = xbps_dictionary_iterator(stage); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t newpkg = xbps_dictionary_get(idx, pkgname); xbps_array_t pkgshlibs = xbps_dictionary_get(newpkg, "shlib-provides"); for(unsigned int i = 0; i < xbps_array_count(pkgshlibs); i++) { const char *shlib; xbps_array_get_cstring_nocopy(pkgshlibs, i, &shlib); xbps_dictionary_remove(usedshlibs, shlib); } } xbps_object_iterator_release(iter); if(xbps_dictionary_count(usedshlibs) != 0) { puts("Unfullfilled shlibs:"); iter = xbps_dictionary_iterator(usedshlibs); while ((keysym = xbps_object_iterator_next(iter))) { const char *shlib = xbps_dictionary_keysym_cstring_nocopy(keysym), *provider = NULL; xbps_array_t users = xbps_dictionary_get(usedshlibs, shlib); xbps_dictionary_get_cstring_nocopy(usedshlibs, shlib, &provider); printf(" %s (provided by: %s; used by: ", shlib, provider); const char *pre = ""; for(unsigned int i = 0; i < xbps_array_count(users); i++) { const char *user; xbps_array_get_cstring_nocopy(users, i, &user); xbps_dictionary_remove(usedshlibs, shlib); printf("%s%s",pre, user); pre = ", "; } puts(")"); } puts("Changes are commit to stage."); xbps_object_iterator_release(iter); // TODO FLUSH STAGE rv = true; } else { iter = xbps_dictionary_iterator(stage); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t newpkg = xbps_dictionary_get_keysym(stage, keysym); xbps_dictionary_set(idx, pkgname, newpkg); } xbps_object_iterator_release(iter); rv = repodata_flush(xhp, repodir, idx, meta); } xbps_object_release(usedshlibs); xbps_object_release(oldshlibs); return rv; }
xbps_array_t xbps_find_pkg_obsoletes(struct xbps_handle *xhp, xbps_dictionary_t instd, xbps_dictionary_t newd) { xbps_array_t instfiles, newfiles, obsoletes; /* These are symlinks in Void and must not be removed */ const char *basesymlinks[] = { "./bin", "./sbin", "./lib", "./lib32", "./lib64", "./usr/lib32", "./usr/lib64", "./var/run", }; int rv = 0; assert(xbps_object_type(instd) == XBPS_TYPE_DICTIONARY); assert(xbps_object_type(newd) == XBPS_TYPE_DICTIONARY); obsoletes = xbps_array_create(); assert(obsoletes); instfiles = merge_filelist(instd); if (xbps_array_count(instfiles) == 0) { /* nothing to check if current pkg does not own any file */ xbps_object_release(instfiles); return obsoletes; } newfiles = merge_filelist(newd); /* * Iterate over files list from installed package. */ for (unsigned int i = 0; i < xbps_array_count(instfiles); i++) { xbps_object_t obj, obj2; xbps_string_t oldstr, newstr; struct stat st; uint64_t mtime = 0; const char *oldhash; char file[PATH_MAX]; bool found = false; obj = xbps_array_get(instfiles, i); if (xbps_object_type(obj) != XBPS_TYPE_DICTIONARY) { /* ignore unexistent files */ continue; } oldstr = xbps_dictionary_get(obj, "file"); if (oldstr == NULL) continue; snprintf(file, sizeof(file), ".%s", xbps_string_cstring_nocopy(oldstr)); if (xbps_dictionary_get_cstring_nocopy(obj, "sha256", &oldhash)) { rv = xbps_file_hash_check(file, oldhash); if (rv == ENOENT || rv == ERANGE) { /* Skip unexistent and files that do not * match the hash. */ continue; } } /* * Check if current file is available in new pkg filelist. */ for (unsigned int x = 0; x < xbps_array_count(newfiles); x++) { obj2 = xbps_array_get(newfiles, x); newstr = xbps_dictionary_get(obj2, "file"); assert(newstr); /* * Skip files with same path. */ if (xbps_string_equals(oldstr, newstr)) { found = true; break; } } if (found) { continue; } /* * Make sure to not remove any symlink of root directory. */ for (uint8_t x = 0; x < __arraycount(basesymlinks); x++) { if (strcmp(file, basesymlinks[x]) == 0) { found = true; xbps_dbg_printf(xhp, "[obsoletes] ignoring " "%s removal\n", file); break; } } if (found) { continue; } /* * Finally check if file mtime on disk matched what * the installed pkg has stored. */ if (xbps_dictionary_get_uint64(obj, "mtime", &mtime)) { if (lstat(file, &st) == -1) { xbps_dbg_printf(xhp, "[obsoletes] lstat failed " "for %s: %s\n", file, strerror(errno)); continue; } if (mtime != (uint64_t)st.st_mtime) continue; xbps_dbg_printf(xhp, "[obsoletes] %s: matched mtime, adding obsolete.\n", file); } /* * Obsolete found, add onto the array. */ xbps_dbg_printf(xhp, "found obsolete: %s\n", file); xbps_array_add_cstring(obsoletes, file); } xbps_object_release(instfiles); xbps_object_release(newfiles); return obsoletes; }