32#include <archive_entry.h>
34#include "xbps_api_impl.h"
40xbps_entry_is_a_conf_file(xbps_dictionary_t filesd,
41 const char *entry_pname)
47 array = xbps_dictionary_get(filesd,
"conf_files");
48 if (xbps_array_count(array) == 0)
51 for (
unsigned int i = 0; i < xbps_array_count(array); i++) {
52 d = xbps_array_get(array, i);
53 xbps_dictionary_get_cstring_nocopy(d,
"file", &cffile);
54 if (strcmp(cffile, entry_pname) == 0)
64xbps_entry_install_conf_file(
struct xbps_handle *xhp,
65 xbps_dictionary_t binpkg_filesd,
66 xbps_dictionary_t pkg_filesd,
67 struct archive_entry *entry,
68 const char *entry_pname,
72 xbps_object_t obj, obj2;
73 xbps_object_iterator_t iter, iter2;
74 const char *version = NULL, *cffile, *sha256_new = NULL;
75 char buf[PATH_MAX], sha256_cur[XBPS_SHA256_SIZE];
76 const char *sha256_orig = NULL;
79 assert(xbps_object_type(binpkg_filesd) == XBPS_TYPE_DICTIONARY);
95 if (pkg_filesd == NULL || mysymlink) {
105 "installed, renaming to %s.new-%s\n", pkgver,
106 entry_pname, entry_pname, version);
107 snprintf(buf,
sizeof(buf),
"%s.new-%s", entry_pname, version);
108 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
109 0, pkgver,
"File `%s' exists, installing configuration file to `%s'.", entry_pname, buf);
110 archive_entry_copy_pathname(entry, buf);
117 while ((obj2 = xbps_object_iterator_next(iter2))) {
118 xbps_dictionary_get_cstring_nocopy(obj2,
120 snprintf(buf,
sizeof(buf),
".%s", cffile);
121 if (strcmp(entry_pname, buf) == 0) {
122 xbps_dictionary_get_cstring_nocopy(obj2,
"sha256", &sha256_orig);
126 xbps_object_iterator_release(iter2);
131 if (sha256_orig == NULL) {
133 pkgver, entry_pname);
141 while ((obj = xbps_object_iterator_next(iter))) {
142 xbps_dictionary_get_cstring_nocopy(obj,
"file", &cffile);
143 snprintf(buf,
sizeof(buf),
".%s", cffile);
144 if (strcmp(entry_pname, buf)) {
148 if (errno == ENOENT) {
153 "installed\n", pkgver, entry_pname);
161 xbps_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256_new);
167 if ((strcmp(sha256_orig, sha256_cur) == 0) &&
168 (strcmp(sha256_orig, sha256_new) == 0) &&
169 (strcmp(sha256_cur, sha256_new) == 0)) {
171 "cur = X, new = X\n", pkgver, entry_pname);
180 }
else if ((strcmp(sha256_orig, sha256_cur) == 0) &&
181 (strcmp(sha256_orig, sha256_new)) &&
182 (strcmp(sha256_cur, sha256_new)) &&
183 (!(xhp->
flags & XBPS_FLAG_KEEP_CONFIG))) {
184 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
186 "Updating configuration file `%s' provided "
187 "by `%s'.", cffile, pkgver);
197 }
else if ((strcmp(sha256_orig, sha256_new) == 0) &&
198 (strcmp(sha256_cur, sha256_new)) &&
199 (strcmp(sha256_orig, sha256_cur))) {
200 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
202 "Keeping modified configuration file `%s'.",
212 }
else if ((strcmp(sha256_cur, sha256_new) == 0) &&
213 (strcmp(sha256_orig, sha256_new)) &&
214 (strcmp(sha256_orig, sha256_cur))) {
216 "cur = Y, new = Y\n", pkgver, entry_pname);
226 }
else if (((strcmp(sha256_orig, sha256_cur)) &&
227 (strcmp(sha256_cur, sha256_new)) &&
228 (strcmp(sha256_orig, sha256_new))) ||
229 (xhp->
flags & XBPS_FLAG_KEEP_CONFIG)) {
233 snprintf(buf,
sizeof(buf),
".%s.new-%s", cffile, version);
234 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
235 0, pkgver,
"File `%s' exists, installing configuration file to `%s'.", cffile, buf);
236 archive_entry_copy_pathname(entry, buf);
244 xbps_object_iterator_release(iter);
247 pkgver, entry_pname, rv);
Generic XBPS structure handler for initialization.
#define xbps_unreachable()
Log and abort for code that should be unreachable.
void xbps_dbg_printf(const char *fmt,...)
Prints debug messages to stderr.
xbps_object_iterator_t xbps_array_iter_from_dict(xbps_dictionary_t dict, const char *key)
bool xbps_file_sha256(char *dst, size_t len, const char *file)
const char * xbps_pkg_version(const char *pkg)