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);
92 xbps_dbg_printf(
"%s: processing conf_file %s\n",
95 if (pkg_filesd == NULL || mysymlink) {
103 xbps_dbg_printf(
"%s: conf_file %s not currently "
104 "installed, renaming to %s.new-%s\n", pkgver,
105 entry_pname, entry_pname, version);
106 snprintf(buf,
sizeof(buf),
"%s.new-%s", entry_pname, version);
107 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
108 0, pkgver,
"File `%s' exists, installing configuration file to `%s'.", entry_pname, buf);
109 archive_entry_copy_pathname(entry, buf);
116 while ((obj2 = xbps_object_iterator_next(iter2))) {
117 xbps_dictionary_get_cstring_nocopy(obj2,
119 snprintf(buf,
sizeof(buf),
".%s", cffile);
120 if (strcmp(entry_pname, buf) == 0) {
121 xbps_dictionary_get_cstring_nocopy(obj2,
"sha256", &sha256_orig);
125 xbps_object_iterator_release(iter2);
130 if (sha256_orig == NULL) {
131 xbps_dbg_printf(
"%s: conf_file %s not installed\n",
132 pkgver, entry_pname);
140 while ((obj = xbps_object_iterator_next(iter))) {
141 xbps_dictionary_get_cstring_nocopy(obj,
"file", &cffile);
142 snprintf(buf,
sizeof(buf),
".%s", cffile);
143 if (strcmp(entry_pname, buf)) {
147 if (errno == ENOENT) {
151 xbps_dbg_printf(
"%s: conf_file %s not "
152 "installed\n", pkgver, entry_pname);
160 xbps_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256_new);
166 if ((strcmp(sha256_orig, sha256_cur) == 0) &&
167 (strcmp(sha256_orig, sha256_new) == 0) &&
168 (strcmp(sha256_cur, sha256_new) == 0)) {
169 xbps_dbg_printf(
"%s: conf_file %s orig = X, "
170 "cur = X, new = X\n", pkgver, entry_pname);
179 }
else if ((strcmp(sha256_orig, sha256_cur) == 0) &&
180 (strcmp(sha256_orig, sha256_new)) &&
181 (strcmp(sha256_cur, sha256_new)) &&
182 (!(xhp->
flags & XBPS_FLAG_KEEP_CONFIG))) {
183 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
185 "Updating configuration file `%s' provided "
186 "by `%s'.", cffile, pkgver);
196 }
else if ((strcmp(sha256_orig, sha256_new) == 0) &&
197 (strcmp(sha256_cur, sha256_new)) &&
198 (strcmp(sha256_orig, sha256_cur))) {
199 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
201 "Keeping modified configuration file `%s'.",
211 }
else if ((strcmp(sha256_cur, sha256_new) == 0) &&
212 (strcmp(sha256_orig, sha256_new)) &&
213 (strcmp(sha256_orig, sha256_cur))) {
214 xbps_dbg_printf(
"%s: conf_file %s orig = X, "
215 "cur = Y, new = Y\n", pkgver, entry_pname);
225 }
else if (((strcmp(sha256_orig, sha256_cur)) &&
226 (strcmp(sha256_cur, sha256_new)) &&
227 (strcmp(sha256_orig, sha256_new))) ||
228 (xhp->
flags & XBPS_FLAG_KEEP_CONFIG)) {
231 snprintf(buf,
sizeof(buf),
".%s.new-%s", cffile, version);
232 xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
233 0, pkgver,
"File `%s' exists, installing configuration file to `%s'.", cffile, buf);
234 archive_entry_copy_pathname(entry, buf);
242 xbps_object_iterator_release(iter);
244 xbps_dbg_printf(
"%s: conf_file %s returned %d\n",
245 pkgver, entry_pname, rv);
Generic XBPS structure handler for initialization.
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)