2009-11-28 10:13:21 +05:30
|
|
|
/*-
|
2015-02-27 00:07:46 +05:30
|
|
|
* Copyright (c) 2009-2015 Juan Romero Pardines.
|
2009-11-28 10:13:21 +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>
|
2010-05-18 11:16:27 +05:30
|
|
|
#include <unistd.h>
|
2009-11-28 10:13:21 +05:30
|
|
|
|
2010-11-13 07:48:58 +05:30
|
|
|
#include "xbps_api_impl.h"
|
2009-11-28 10:13:21 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
static xbps_array_t
|
|
|
|
merge_filelist(xbps_dictionary_t d)
|
2013-03-09 18:00:56 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t a, result;
|
|
|
|
xbps_dictionary_t filed;
|
2013-06-12 13:34:10 +05:30
|
|
|
unsigned int i;
|
2013-03-09 18:00:56 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
result = xbps_array_create();
|
2013-03-09 18:00:56 +05:30
|
|
|
assert(result);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
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);
|
2013-03-09 18:00:56 +05:30
|
|
|
}
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
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);
|
2013-03-09 18:00:56 +05:30
|
|
|
}
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
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);
|
2013-03-09 18:00:56 +05:30
|
|
|
}
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
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);
|
2013-03-09 18:00:56 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t
|
2012-10-24 11:15:00 +05:30
|
|
|
xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_t instd,
|
|
|
|
xbps_dictionary_t newd)
|
2009-11-28 10:13:21 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t instfiles, newfiles, obsoletes;
|
2014-03-31 13:46:18 +05:30
|
|
|
/* These are symlinks in Void and must not be removed */
|
|
|
|
const char *basesymlinks[] = {
|
|
|
|
"./bin",
|
|
|
|
"./sbin",
|
2015-06-05 11:59:05 +05:30
|
|
|
"./usr/sbin",
|
2014-03-31 13:46:18 +05:30
|
|
|
"./lib",
|
|
|
|
"./lib32",
|
|
|
|
"./lib64",
|
|
|
|
"./usr/lib32",
|
|
|
|
"./usr/lib64",
|
|
|
|
"./var/run",
|
|
|
|
};
|
2011-02-21 22:12:47 +05:30
|
|
|
int rv = 0;
|
2012-10-24 11:15:00 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
assert(xbps_object_type(instd) == XBPS_TYPE_DICTIONARY);
|
|
|
|
assert(xbps_object_type(newd) == XBPS_TYPE_DICTIONARY);
|
2011-01-25 08:44:33 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
obsoletes = xbps_array_create();
|
2012-10-24 11:15:00 +05:30
|
|
|
assert(obsoletes);
|
|
|
|
|
2013-03-09 18:00:56 +05:30
|
|
|
instfiles = merge_filelist(instd);
|
2013-06-20 13:56:12 +05:30
|
|
|
if (xbps_array_count(instfiles) == 0) {
|
2013-03-09 18:00:56 +05:30
|
|
|
/* nothing to check if current pkg does not own any file */
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(instfiles);
|
2013-03-09 18:00:56 +05:30
|
|
|
return obsoletes;
|
|
|
|
}
|
|
|
|
newfiles = merge_filelist(newd);
|
2012-09-30 12:27:57 +05:30
|
|
|
|
2009-11-28 10:13:21 +05:30
|
|
|
/*
|
2012-10-24 11:15:00 +05:30
|
|
|
* Iterate over files list from installed package.
|
2009-11-28 10:13:21 +05:30
|
|
|
*/
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(instfiles); i++) {
|
2015-02-27 00:07:46 +05:30
|
|
|
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;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
obj = xbps_array_get(instfiles, i);
|
|
|
|
if (xbps_object_type(obj) != XBPS_TYPE_DICTIONARY) {
|
2013-03-14 02:38:13 +05:30
|
|
|
/* ignore unexistent files */
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
oldstr = xbps_dictionary_get(obj, "file");
|
2012-11-30 11:41:51 +05:30
|
|
|
if (oldstr == NULL)
|
|
|
|
continue;
|
2012-10-24 11:15:00 +05:30
|
|
|
|
2014-05-22 14:11:31 +05:30
|
|
|
snprintf(file, sizeof(file), ".%s", xbps_string_cstring_nocopy(oldstr));
|
2012-10-24 11:15:00 +05:30
|
|
|
|
2015-02-27 00:07:46 +05:30
|
|
|
if (xbps_dictionary_get_cstring_nocopy(obj, "sha256", &oldhash)) {
|
2011-06-01 13:07:32 +05:30
|
|
|
rv = xbps_file_hash_check(file, oldhash);
|
2010-05-18 11:16:27 +05:30
|
|
|
if (rv == ENOENT || rv == ERANGE) {
|
|
|
|
/*
|
2019-03-15 18:04:30 +05:30
|
|
|
* Skip unexistent and files that do not
|
2010-05-18 11:16:27 +05:30
|
|
|
* match the hash.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 18:00:56 +05:30
|
|
|
/*
|
|
|
|
* Check if current file is available in new pkg filelist.
|
|
|
|
*/
|
2013-09-15 13:36:49 +05:30
|
|
|
for (unsigned int x = 0; x < xbps_array_count(newfiles); x++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
obj2 = xbps_array_get(newfiles, x);
|
|
|
|
newstr = xbps_dictionary_get(obj2, "file");
|
2013-03-09 18:00:56 +05:30
|
|
|
assert(newstr);
|
|
|
|
/*
|
|
|
|
* Skip files with same path.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
if (xbps_string_equals(oldstr, newstr)) {
|
2013-03-09 18:00:56 +05:30
|
|
|
found = true;
|
|
|
|
break;
|
2009-11-28 10:13:21 +05:30
|
|
|
}
|
|
|
|
}
|
2010-05-18 11:16:27 +05:30
|
|
|
if (found) {
|
2009-11-28 10:13:21 +05:30
|
|
|
continue;
|
2010-05-18 11:16:27 +05:30
|
|
|
}
|
2012-07-11 02:52:25 +05:30
|
|
|
/*
|
2014-03-31 13:46:18 +05:30
|
|
|
* Make sure to not remove any symlink of root directory.
|
2012-07-11 02:52:25 +05:30
|
|
|
*/
|
2014-03-31 13:46:18 +05:30
|
|
|
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) {
|
2012-07-11 02:52:25 +05:30
|
|
|
continue;
|
|
|
|
}
|
2015-02-27 00:07:46 +05:30
|
|
|
/*
|
|
|
|
* 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);
|
|
|
|
}
|
2009-11-28 10:13:21 +05:30
|
|
|
/*
|
2012-10-24 11:15:00 +05:30
|
|
|
* Obsolete found, add onto the array.
|
2009-11-28 10:13:21 +05:30
|
|
|
*/
|
2013-03-09 18:00:56 +05:30
|
|
|
xbps_dbg_printf(xhp, "found obsolete: %s\n", file);
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_add_cstring(obsoletes, file);
|
2009-11-28 10:13:21 +05:30
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(instfiles);
|
|
|
|
xbps_object_release(newfiles);
|
2009-11-28 10:13:21 +05:30
|
|
|
|
2012-10-24 11:15:00 +05:30
|
|
|
return obsoletes;
|
2010-05-18 11:16:27 +05:30
|
|
|
}
|