opkg: fix md5 related #ifdef (thx, swalker)
[openwrt/staging/chunkeey.git] / package / system / opkg / patches / 230-drop_md5_support.patch
1 --- a/libopkg/conffile.c
2 +++ b/libopkg/conffile.c
3 @@ -36,7 +36,7 @@
4
5 int conffile_has_been_modified(conffile_t *conffile)
6 {
7 - char *md5sum;
8 + char *chksum;
9 char *filename = conffile->name;
10 char *root_filename;
11 int ret = 1;
12 @@ -48,16 +48,19 @@
13
14 root_filename = root_filename_alloc(filename);
15
16 - md5sum = file_md5sum_alloc(root_filename);
17 -
18 - if (md5sum && (ret = strcmp(md5sum, conffile->value))) {
19 - opkg_msg(INFO, "Conffile %s:\n\told md5=%s\n\tnew md5=%s\n",
20 - conffile->name, md5sum, conffile->value);
21 +#ifdef HAVE_MD5
22 + chksum = file_md5sum_alloc(root_filename);
23 +#else
24 + chksum = file_sha256sum_alloc(root_filename);
25 +#endif
26 + if (chksum && (ret = strcmp(chksum, conffile->value))) {
27 + opkg_msg(INFO, "Conffile %s:\n\told chk=%s\n\tnew chk=%s\n",
28 + conffile->name, chksum, conffile->value);
29 }
30
31 free(root_filename);
32 - if (md5sum)
33 - free(md5sum);
34 + if (chksum)
35 + free(chksum);
36
37 return ret;
38 }
39 --- a/libopkg/file_util.c
40 +++ b/libopkg/file_util.c
41 @@ -26,7 +26,9 @@
42
43 #include "sprintf_alloc.h"
44 #include "file_util.h"
45 +#ifdef HAVE_MD5
46 #include "md5.h"
47 +#endif
48 #include "libbb/libbb.h"
49
50 #if defined HAVE_SHA256
51 @@ -135,6 +137,7 @@
52 return make_directory(path, mode, FILEUTILS_RECUR);
53 }
54
55 +#ifdef HAVE_MD5
56 char *file_md5sum_alloc(const char *file_name)
57 {
58 static const int md5sum_bin_len = 16;
59 @@ -180,6 +183,7 @@
60
61 return md5sum_hex;
62 }
63 +#endif
64
65 #ifdef HAVE_SHA256
66 char *file_sha256sum_alloc(const char *file_name)
67 --- a/libopkg/opkg_install.c
68 +++ b/libopkg/opkg_install.c
69 @@ -1082,7 +1082,7 @@
70 conffile_list_elt_t *iter;
71 conffile_t *cf;
72 char *cf_backup;
73 - char *md5sum;
74 + char *chksum;
75
76 if (conf->noaction) return 0;
77
78 @@ -1093,7 +1093,11 @@
79
80 /* Might need to initialize the md5sum for each conffile */
81 if (cf->value == NULL) {
82 +#ifdef HAVE_MD5
83 cf->value = file_md5sum_alloc(root_filename);
84 +#else
85 + cf->value = file_sha256sum_alloc(root_filename);
86 +#endif
87 }
88
89 if (!file_exists(root_filename)) {
90 @@ -1105,8 +1109,12 @@
91
92 if (file_exists(cf_backup)) {
93 /* Let's compute md5 to test if files are changed */
94 - md5sum = file_md5sum_alloc(cf_backup);
95 - if (md5sum && cf->value && strcmp(cf->value,md5sum) != 0 ) {
96 +#ifdef HAVE_MD5
97 + chksum = file_md5sum_alloc(cf_backup);
98 +#else
99 + chksum = file_sha256sum_alloc(cf_backup);
100 +#endif
101 + if (chksum && cf->value && strcmp(cf->value,chksum) != 0 ) {
102 if (conf->force_maintainer) {
103 opkg_msg(NOTICE, "Conffile %s using maintainer's setting.\n",
104 cf_backup);
105 @@ -1123,8 +1131,8 @@
106 }
107 }
108 unlink(cf_backup);
109 - if (md5sum)
110 - free(md5sum);
111 + if (chksum)
112 + free(chksum);
113 }
114
115 free(cf_backup);
116 @@ -1323,6 +1331,7 @@
117 }
118 #endif
119
120 +#ifdef HAVE_MD5
121 /* Check for md5 values */
122 if (pkg->md5sum)
123 {
124 @@ -1346,6 +1355,7 @@
125 if (file_md5)
126 free(file_md5);
127 }
128 +#endif
129
130 #ifdef HAVE_SHA256
131 /* Check for sha256 value */
132 --- a/libopkg/Makefile.am
133 +++ b/libopkg/Makefile.am
134 @@ -25,13 +25,16 @@
135 pkg_src.c pkg_src.h pkg_src_list.c pkg_src_list.h \
136 str_list.c str_list.h void_list.c void_list.h \
137 active_list.c active_list.h list.h
138 -opkg_util_sources = file_util.c file_util.h opkg_message.h opkg_message.c md5.c md5.h \
139 +opkg_util_sources = file_util.c file_util.h opkg_message.h opkg_message.c \
140 parse_util.c parse_util.h \
141 sprintf_alloc.c sprintf_alloc.h \
142 xregex.c xregex.h xsystem.c xsystem.h
143 if HAVE_PATHFINDER
144 opkg_util_sources += opkg_pathfinder.c opkg_pathfinder.h
145 endif
146 +if HAVE_MD5
147 +opkg_util_sources += md5.c md5.h
148 +endif
149 if HAVE_SHA256
150 opkg_util_sources += sha256.c sha256.h
151 endif
152 --- a/configure.ac
153 +++ b/configure.ac
154 @@ -72,6 +72,7 @@
155 AC_DEFINE(HAVE_SHA256, 1, [Define if you want sha256 support])
156 fi
157 AM_CONDITIONAL(HAVE_SHA256, test "x$want_sha256" = "xyes")
158 +AM_CONDITIONAL(HAVE_MD5, test "x$want_sha256" = "xno")
159
160 # check for openssl
161 AC_ARG_ENABLE(openssl,