lib/package_find_obsoletes.c: remove in favor of transaction file checks
This commit is contained in:
parent
888289786b
commit
6877d28139
@ -50,7 +50,7 @@
|
|||||||
*
|
*
|
||||||
* This header documents the full API for the XBPS Library.
|
* This header documents the full API for the XBPS Library.
|
||||||
*/
|
*/
|
||||||
#define XBPS_API_VERSION "20190615"
|
#define XBPS_API_VERSION "20190618"
|
||||||
|
|
||||||
#ifndef XBPS_VERSION
|
#ifndef XBPS_VERSION
|
||||||
#define XBPS_VERSION "UNSET"
|
#define XBPS_VERSION "UNSET"
|
||||||
@ -758,22 +758,6 @@ const char *xbps_fetch_error_string(void);
|
|||||||
*/
|
*/
|
||||||
xbps_array_t xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans);
|
xbps_array_t xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans);
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup pkg_obsoletes
|
|
||||||
*
|
|
||||||
* Finds obsolete files by comparing installed files dictionary with
|
|
||||||
* a new files dictionary.
|
|
||||||
*
|
|
||||||
* @param[in] xhp The pointer to the xbps_handle struct.
|
|
||||||
* @param[in] instd Installed package metadata dictionary.
|
|
||||||
* @param[in] newd New package metadata dictionary.
|
|
||||||
*
|
|
||||||
* @return A proplib array of strings with a sorted list of obsolete files.
|
|
||||||
*/
|
|
||||||
xbps_array_t xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|
||||||
xbps_dictionary_t instd,
|
|
||||||
xbps_dictionary_t newd);
|
|
||||||
|
|
||||||
/** @addtogroup pkgdb */
|
/** @addtogroup pkgdb */
|
||||||
/*@{*/
|
/*@{*/
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ EXTOBJS = external/dewey.o external/fexec.o external/mkpath.o
|
|||||||
|
|
||||||
# libxbps
|
# libxbps
|
||||||
OBJS = package_configure.o package_config_files.o package_orphans.o
|
OBJS = package_configure.o package_config_files.o package_orphans.o
|
||||||
OBJS += package_remove.o package_find_obsoletes.o package_state.o
|
OBJS += package_remove.o package_state.o
|
||||||
OBJS += package_unpack.o package_register.o package_script.o verifysig.o
|
OBJS += package_unpack.o package_register.o package_script.o verifysig.o
|
||||||
OBJS += package_msg.o transaction_shlibs.o
|
OBJS += package_msg.o transaction_shlibs.o
|
||||||
OBJS += transaction_commit.o transaction_package_replace.o
|
OBJS += transaction_commit.o transaction_package_replace.o
|
||||||
|
@ -1,198 +0,0 @@
|
|||||||
/*-
|
|
||||||
* Copyright (c) 2009-2015 Juan Romero Pardines.
|
|
||||||
* 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 <unistd.h>
|
|
||||||
|
|
||||||
#include "xbps_api_impl.h"
|
|
||||||
|
|
||||||
static xbps_array_t
|
|
||||||
merge_filelist(xbps_dictionary_t d)
|
|
||||||
{
|
|
||||||
xbps_array_t a, result;
|
|
||||||
xbps_dictionary_t filed;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
result = xbps_array_create();
|
|
||||||
assert(result);
|
|
||||||
|
|
||||||
if ((a = xbps_dictionary_get(d, "files"))) {
|
|
||||||
for (i = 0; i < xbps_array_count(a); i++) {
|
|
||||||
filed = xbps_array_get(a, i);
|
|
||||||
xbps_array_add(result, filed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((a = xbps_dictionary_get(d, "links"))) {
|
|
||||||
for (i = 0; i < xbps_array_count(a); i++) {
|
|
||||||
filed = xbps_array_get(a, i);
|
|
||||||
xbps_array_add(result, filed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((a = xbps_dictionary_get(d, "conf_files"))) {
|
|
||||||
for (i = 0; i < xbps_array_count(a); i++) {
|
|
||||||
filed = xbps_array_get(a, i);
|
|
||||||
xbps_array_add(result, filed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((a = xbps_dictionary_get(d, "dirs"))) {
|
|
||||||
for (i = 0; i < xbps_array_count(a); i++) {
|
|
||||||
filed = xbps_array_get(a, i);
|
|
||||||
xbps_array_add(result, filed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
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",
|
|
||||||
"./usr/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;
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ include('cmpver/Kyuafile')
|
|||||||
include('pkgpattern_match/Kyuafile')
|
include('pkgpattern_match/Kyuafile')
|
||||||
include('plist_match/Kyuafile')
|
include('plist_match/Kyuafile')
|
||||||
include('plist_match_virtual/Kyuafile')
|
include('plist_match_virtual/Kyuafile')
|
||||||
include('find_pkg_obsoletes/Kyuafile')
|
|
||||||
include('config/Kyuafile')
|
include('config/Kyuafile')
|
||||||
include('find_pkg_orphans/Kyuafile')
|
include('find_pkg_orphans/Kyuafile')
|
||||||
include('pkgdb/Kyuafile')
|
include('pkgdb/Kyuafile')
|
||||||
|
@ -7,7 +7,6 @@ SUBDIRS += pkgpattern_match
|
|||||||
SUBDIRS += plist_match
|
SUBDIRS += plist_match
|
||||||
SUBDIRS += plist_match_virtual
|
SUBDIRS += plist_match_virtual
|
||||||
SUBDIRS += util
|
SUBDIRS += util
|
||||||
SUBDIRS += find_pkg_obsoletes
|
|
||||||
SUBDIRS += find_pkg_orphans
|
SUBDIRS += find_pkg_orphans
|
||||||
SUBDIRS += pkgdb
|
SUBDIRS += pkgdb
|
||||||
SUBDIRS += config
|
SUBDIRS += config
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
syntax("kyuafile", 1)
|
|
||||||
|
|
||||||
test_suite("libxbps")
|
|
||||||
|
|
||||||
atf_test_program{name="find_pkg_obsoletes_test"}
|
|
@ -1,8 +0,0 @@
|
|||||||
TOPDIR = ../../../..
|
|
||||||
-include $(TOPDIR)/config.mk
|
|
||||||
|
|
||||||
TESTSSUBDIR = xbps/libxbps/find_pkg_obsoletes
|
|
||||||
TEST = find_pkg_obsoletes_test
|
|
||||||
EXTRA_FILES = Kyuafile
|
|
||||||
|
|
||||||
include $(TOPDIR)/mk/test.mk
|
|
@ -1,131 +0,0 @@
|
|||||||
/*-
|
|
||||||
* Copyright (c) 2013 Juan Romero Pardines.
|
|
||||||
* 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 <atf-c.h>
|
|
||||||
#include <xbps.h>
|
|
||||||
|
|
||||||
static void
|
|
||||||
append_file(xbps_dictionary_t d, const char *key, const char *fpath)
|
|
||||||
{
|
|
||||||
xbps_array_t a;
|
|
||||||
xbps_dictionary_t filed;
|
|
||||||
|
|
||||||
filed = xbps_dictionary_create();
|
|
||||||
a = xbps_dictionary_get(d, key);
|
|
||||||
if (a == NULL) {
|
|
||||||
a = xbps_array_create();
|
|
||||||
xbps_dictionary_set(d, key, a);
|
|
||||||
}
|
|
||||||
|
|
||||||
xbps_dictionary_set_cstring_nocopy(filed, "file", fpath);
|
|
||||||
xbps_array_add(a, filed);
|
|
||||||
}
|
|
||||||
|
|
||||||
static xbps_dictionary_t
|
|
||||||
create_dict(const char *key, const char *fpath)
|
|
||||||
{
|
|
||||||
xbps_array_t a;
|
|
||||||
xbps_dictionary_t d, filed;
|
|
||||||
|
|
||||||
d = xbps_dictionary_create();
|
|
||||||
filed = xbps_dictionary_create();
|
|
||||||
a = xbps_array_create();
|
|
||||||
|
|
||||||
xbps_dictionary_set_cstring_nocopy(filed, "file", fpath);
|
|
||||||
xbps_dictionary_set_cstring_nocopy(filed, "sha256", "kjaskajsk");
|
|
||||||
xbps_array_add(a, filed);
|
|
||||||
xbps_dictionary_set(d, key, a);
|
|
||||||
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
ATF_TC(find_pkg_obsoletes_test);
|
|
||||||
ATF_TC_HEAD(find_pkg_obsoletes_test, tc)
|
|
||||||
{
|
|
||||||
atf_tc_set_md_var(tc, "descr", "Test xbps_find_pkg_obsoletes");
|
|
||||||
}
|
|
||||||
|
|
||||||
ATF_TC_BODY(find_pkg_obsoletes_test, tc)
|
|
||||||
{
|
|
||||||
struct xbps_handle xh;
|
|
||||||
xbps_array_t res;
|
|
||||||
xbps_dictionary_t d1, d2;
|
|
||||||
const char *tcsdir;
|
|
||||||
|
|
||||||
/* get test source dir */
|
|
||||||
tcsdir = atf_tc_get_config_var(tc, "srcdir");
|
|
||||||
|
|
||||||
memset(&xh, 0, sizeof(xh));
|
|
||||||
xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
|
|
||||||
ATF_REQUIRE_EQ(xbps_init(&xh), 0);
|
|
||||||
|
|
||||||
d1 = create_dict("files", "/etc/foo.conf");
|
|
||||||
d2 = create_dict("conf_files", "/etc/foo.conf");
|
|
||||||
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 0);
|
|
||||||
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d2, d1);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 0);
|
|
||||||
|
|
||||||
append_file(d1, "files", "file");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 1);
|
|
||||||
|
|
||||||
append_file(d1, "conf_files", "conf_file");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 2);
|
|
||||||
|
|
||||||
append_file(d1, "links", "link");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 3);
|
|
||||||
|
|
||||||
append_file(d1, "dirs", "dir");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 4);
|
|
||||||
|
|
||||||
append_file(d2, "files", "file");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 3);
|
|
||||||
|
|
||||||
append_file(d2, "conf_files", "conf_file");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 2);
|
|
||||||
|
|
||||||
append_file(d2, "links", "link");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 1);
|
|
||||||
|
|
||||||
append_file(d2, "dirs", "dir");
|
|
||||||
res = xbps_find_pkg_obsoletes(&xh, d1, d2);
|
|
||||||
ATF_REQUIRE_EQ(xbps_array_count(res), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ATF_TP_ADD_TCS(tp)
|
|
||||||
{
|
|
||||||
ATF_TP_ADD_TC(tp, find_pkg_obsoletes_test);
|
|
||||||
|
|
||||||
return atf_no_error();
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user