2009-11-28 10:13:21 +05:30
|
|
|
/*-
|
2012-07-11 02:52:25 +05:30
|
|
|
* Copyright (c) 2009-2012 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
|
|
|
|
2012-10-24 11:15:00 +05:30
|
|
|
prop_array_t
|
|
|
|
xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|
|
|
prop_dictionary_t instd,
|
|
|
|
prop_dictionary_t newd)
|
2009-11-28 10:13:21 +05:30
|
|
|
{
|
2012-10-24 11:15:00 +05:30
|
|
|
prop_array_t array, array2, obsoletes;
|
2010-11-19 18:10:13 +05:30
|
|
|
prop_object_t obj, obj2;
|
|
|
|
prop_string_t oldstr, newstr;
|
2012-10-24 11:15:00 +05:30
|
|
|
size_t i, x;
|
2009-11-28 10:13:21 +05:30
|
|
|
const char *array_str = "files";
|
2012-07-14 15:41:55 +05:30
|
|
|
const char *oldhash;
|
2010-11-19 18:10:13 +05:30
|
|
|
char *file;
|
2011-02-21 22:12:47 +05:30
|
|
|
int rv = 0;
|
2012-10-24 11:15:00 +05:30
|
|
|
bool found, dodirs, dolinks, docffiles;
|
2009-11-28 10:13:21 +05:30
|
|
|
|
2012-10-24 11:15:00 +05:30
|
|
|
dodirs = dolinks = docffiles = false;
|
|
|
|
|
|
|
|
assert(prop_object_type(instd) == PROP_TYPE_DICTIONARY);
|
2011-10-19 20:23:38 +05:30
|
|
|
assert(prop_object_type(newd) == PROP_TYPE_DICTIONARY);
|
2011-01-25 08:44:33 +05:30
|
|
|
|
2012-10-24 11:15:00 +05:30
|
|
|
obsoletes = prop_array_create();
|
|
|
|
assert(obsoletes);
|
|
|
|
|
2009-11-28 10:13:21 +05:30
|
|
|
again:
|
2012-10-24 11:15:00 +05:30
|
|
|
array = prop_dictionary_get(instd, array_str);
|
|
|
|
if (array == NULL || prop_array_count(array) == 0)
|
2012-09-30 12:27:57 +05:30
|
|
|
goto out1;
|
|
|
|
|
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
|
|
|
*/
|
2012-10-24 11:15:00 +05:30
|
|
|
for (i = 0; i < prop_array_count(array); i++) {
|
2009-11-28 10:13:21 +05:30
|
|
|
found = false;
|
2012-10-24 11:15:00 +05:30
|
|
|
obj = prop_array_get(array, i);
|
2009-11-28 10:13:21 +05:30
|
|
|
oldstr = prop_dictionary_get(obj, "file");
|
2012-10-24 11:15:00 +05:30
|
|
|
assert(oldstr);
|
|
|
|
|
2010-05-18 11:16:27 +05:30
|
|
|
file = xbps_xasprintf(".%s",
|
|
|
|
prop_string_cstring_nocopy(oldstr));
|
2012-10-24 11:15:00 +05:30
|
|
|
|
|
|
|
if ((strcmp(array_str, "files") == 0) ||
|
|
|
|
(strcmp(array_str, "conf_files") == 0)) {
|
2010-05-18 11:16:27 +05:30
|
|
|
prop_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) {
|
|
|
|
/*
|
|
|
|
* Skip unexistent and files that do not
|
|
|
|
* match the hash.
|
|
|
|
*/
|
|
|
|
free(file);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-10-24 11:15:00 +05:30
|
|
|
array2 = prop_dictionary_get(newd, array_str);
|
|
|
|
if (array2 && prop_array_count(array2)) {
|
|
|
|
for (x = 0; x < prop_array_count(array2); x++) {
|
|
|
|
obj2 = prop_array_get(array2, x);
|
|
|
|
newstr = prop_dictionary_get(obj2, "file");
|
|
|
|
assert(newstr);
|
|
|
|
/*
|
|
|
|
* Skip files with same path.
|
|
|
|
*/
|
|
|
|
if (prop_string_equals(oldstr, newstr)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-11-28 10:13:21 +05:30
|
|
|
}
|
|
|
|
}
|
2010-05-18 11:16:27 +05:30
|
|
|
if (found) {
|
|
|
|
free(file);
|
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
|
|
|
/*
|
2012-10-24 11:15:00 +05:30
|
|
|
* Do not add required symlinks for the
|
2012-07-11 02:52:25 +05:30
|
|
|
* system transition to /usr.
|
|
|
|
*/
|
|
|
|
if ((strcmp(file, "./bin") == 0) ||
|
2012-07-14 15:41:55 +05:30
|
|
|
(strcmp(file, "./bin/") == 0) ||
|
2012-07-11 02:52:25 +05:30
|
|
|
(strcmp(file, "./sbin") == 0) ||
|
2012-07-14 15:41:55 +05:30
|
|
|
(strcmp(file, "./sbin/") == 0) ||
|
2012-07-11 02:52:25 +05:30
|
|
|
(strcmp(file, "./lib") == 0) ||
|
2012-07-14 15:41:55 +05:30
|
|
|
(strcmp(file, "./lib/") == 0) ||
|
|
|
|
(strcmp(file, "./lib64/") == 0) ||
|
2012-07-11 02:52:25 +05:30
|
|
|
(strcmp(file, "./lib64") == 0)) {
|
|
|
|
free(file);
|
|
|
|
continue;
|
|
|
|
}
|
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
|
|
|
*/
|
2012-10-24 11:15:00 +05:30
|
|
|
xbps_dbg_printf(xhp, "found obsolete: %s (%s)\n",
|
|
|
|
file, array_str);
|
|
|
|
|
|
|
|
prop_array_add_cstring(obsoletes, file);
|
2010-12-25 07:07:25 +05:30
|
|
|
free(file);
|
2009-11-28 10:13:21 +05:30
|
|
|
}
|
2012-09-30 12:27:57 +05:30
|
|
|
out1:
|
2009-11-28 10:13:21 +05:30
|
|
|
if (!dolinks) {
|
|
|
|
dolinks = true;
|
|
|
|
array_str = "links";
|
|
|
|
goto again;
|
2012-10-24 11:15:00 +05:30
|
|
|
} else if (!docffiles) {
|
|
|
|
docffiles = true;
|
|
|
|
array_str = "conf_files";
|
|
|
|
goto again;
|
|
|
|
} else if (!dodirs) {
|
2010-11-19 18:10:13 +05:30
|
|
|
dodirs = true;
|
|
|
|
array_str = "dirs";
|
|
|
|
goto again;
|
|
|
|
}
|
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
|
|
|
}
|