lib/package_find_obsoletes.c: avoid many heap allocs and simplify.
This commit is contained in:
parent
ea234f095f
commit
0f95cf4e46
@ -1,5 +1,5 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
* Copyright (c) 2009-2014 Juan Romero Pardines.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -90,7 +90,7 @@ xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|||||||
"./var/run",
|
"./var/run",
|
||||||
};
|
};
|
||||||
const char *oldhash;
|
const char *oldhash;
|
||||||
char *file;
|
char file[PATH_MAX];
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
@ -122,12 +122,10 @@ xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|||||||
if (oldstr == NULL)
|
if (oldstr == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
file = xbps_xasprintf(".%s",
|
snprintf(file, sizeof(file), ".%s", xbps_string_cstring_nocopy(oldstr));
|
||||||
xbps_string_cstring_nocopy(oldstr));
|
|
||||||
|
|
||||||
oldhash = NULL;
|
oldhash = NULL;
|
||||||
xbps_dictionary_get_cstring_nocopy(obj,
|
xbps_dictionary_get_cstring_nocopy(obj, "sha256", &oldhash);
|
||||||
"sha256", &oldhash);
|
|
||||||
if (oldhash) {
|
if (oldhash) {
|
||||||
rv = xbps_file_hash_check(file, oldhash);
|
rv = xbps_file_hash_check(file, oldhash);
|
||||||
if (rv == ENOENT || rv == ERANGE) {
|
if (rv == ENOENT || rv == ERANGE) {
|
||||||
@ -135,7 +133,6 @@ xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|||||||
* Skip unexistent and files that do not
|
* Skip unexistent and files that do not
|
||||||
* match the hash.
|
* match the hash.
|
||||||
*/
|
*/
|
||||||
free(file);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +152,6 @@ xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
free(file);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -171,7 +167,6 @@ xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
free(file);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -179,7 +174,6 @@ xbps_find_pkg_obsoletes(struct xbps_handle *xhp,
|
|||||||
*/
|
*/
|
||||||
xbps_dbg_printf(xhp, "found obsolete: %s\n", file);
|
xbps_dbg_printf(xhp, "found obsolete: %s\n", file);
|
||||||
xbps_array_add_cstring(obsoletes, file);
|
xbps_array_add_cstring(obsoletes, file);
|
||||||
free(file);
|
|
||||||
}
|
}
|
||||||
xbps_object_release(instfiles);
|
xbps_object_release(instfiles);
|
||||||
xbps_object_release(newfiles);
|
xbps_object_release(newfiles);
|
||||||
|
Loading…
Reference in New Issue
Block a user