31 #include "xbps_api_impl.h"
37 xbps_entry_is_a_conf_file(prop_dictionary_t propsd,
38 const char *entry_pname)
44 assert(prop_object_type(propsd) == PROP_TYPE_DICTIONARY);
45 assert(entry_pname != NULL);
47 array = prop_dictionary_get(propsd,
"conf_files");
48 if (array == NULL || prop_array_count(array) == 0)
51 for (i = 0; i < prop_array_count(array); i++) {
52 prop_array_get_cstring_nocopy(array, i, &cffile);
53 if (strcmp(cffile, entry_pname) == 0)
63 xbps_entry_install_conf_file(
struct xbps_handle *xhp,
64 prop_dictionary_t filesd,
65 struct archive_entry *entry,
66 const char *entry_pname,
70 prop_dictionary_t forigd;
71 prop_object_t obj, obj2;
72 prop_object_iterator_t iter, iter2;
73 const char *cffile, *sha256_new = NULL;
74 char *buf, *sha256_cur = NULL, *sha256_orig = NULL;
77 assert(prop_object_type(filesd) == PROP_TYPE_DICTIONARY);
78 assert(entry != NULL);
79 assert(entry_pname != NULL);
80 assert(pkgname != NULL);
81 assert(version != NULL);
91 xbps_dbg_printf(xhp,
"%s-%s: processing conf_file %s\n",
92 pkgname, version, entry_pname);
96 xbps_dbg_printf(xhp,
"%s-%s: conf_file %s not currently "
97 "installed\n", pkgname, version, entry_pname);
104 while ((obj2 = prop_object_iterator_next(iter2))) {
105 prop_dictionary_get_cstring_nocopy(obj2,
108 if (strcmp(entry_pname, buf) == 0) {
109 prop_dictionary_get_cstring(obj2,
"sha256",
117 prop_object_iterator_release(iter2);
122 if (sha256_orig == NULL) {
123 xbps_dbg_printf(xhp,
"%s-%s: conf_file %s not installed\n",
124 pkgname, version, entry_pname);
132 while ((obj = prop_object_iterator_next(iter))) {
133 prop_dictionary_get_cstring_nocopy(obj,
"file", &cffile);
135 if (strcmp(entry_pname, buf)) {
142 prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256_new);
143 if (sha256_cur == NULL) {
144 if (errno == ENOENT) {
148 xbps_dbg_printf(xhp,
"%s-%s: conf_file %s not "
149 "installed\n", pkgname, version,
163 if ((strcmp(sha256_orig, sha256_cur) == 0) &&
164 (strcmp(sha256_orig, sha256_new) == 0) &&
165 (strcmp(sha256_cur, sha256_new) == 0)) {
166 xbps_dbg_printf(xhp,
"%s-%s: conf_file %s orig = X, "
167 "cur = X, new = X\n", pkgname, version,
176 }
else if ((strcmp(sha256_orig, sha256_cur) == 0) &&
177 (strcmp(sha256_orig, sha256_new)) &&
178 (strcmp(sha256_cur, sha256_new))) {
179 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
181 "Updating configuration file `%s' provided "
182 "by version `%s'.", cffile, version);
192 }
else if ((strcmp(sha256_orig, sha256_new) == 0) &&
193 (strcmp(sha256_cur, sha256_new)) &&
194 (strcmp(sha256_orig, sha256_cur))) {
195 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
197 "Keeping modified configuration file `%s'.",
207 }
else if ((strcmp(sha256_cur, sha256_new) == 0) &&
208 (strcmp(sha256_orig, sha256_new)) &&
209 (strcmp(sha256_orig, sha256_cur))) {
210 xbps_dbg_printf(xhp,
"%s-%s: conf_file %s orig = X, "
211 "cur = Y, new = Y\n", pkgname, version,
220 }
else if ((strcmp(sha256_orig, sha256_cur)) &&
221 (strcmp(sha256_cur, sha256_new)) &&
222 (strcmp(sha256_orig, sha256_new))) {
225 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
227 "Installing new configuration file to "
228 "`%s.new-%s'.", cffile, version);
229 archive_entry_set_pathname(entry, buf);
242 prop_object_iterator_release(iter);
244 xbps_dbg_printf(xhp,
"%s-%s: conf_file %s returned %d\n",
245 pkgname, version, entry_pname, rv);