Files
MSYS2-packages/pacman/0010-filelist-strcasecmp.patch
Christoph Reiter b958515c15 pacman: make file list comparisons between packages case insensitive (#1430)
In case a package gets upgrade and a filename has changed case this allows
the upgrade to go through without any conflicts.

Similarly in case two different packages contain the same file with
a different case this makes it correctly detect a conflict.

This only handles ASCII parts of paths, so Unicode filenames still can
lead to invalid conflict detection.

Fixes #1426
2018-09-30 08:56:23 +03:00

96 lines
2.4 KiB
Diff

This makes _alpm_filelist_difference() and _alpm_filelist_intersection() take
into account that filenames are case insensitive (only for ASCII, unicode is
still broken). This fixes conflict detection in case two packages share the
same filename with a different case.
--- pacman-5.1.1-orig/lib/libalpm/filelist.c 2018-05-14 02:02:18.000000000 +0200
+++ pacman-5.1.1/lib/libalpm/filelist.c 2018-09-28 13:05:47.398469000 +0200
@@ -25,6 +25,43 @@
#include "filelist.h"
#include "util.h"
+#ifdef __MSYS__
+
+#define TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
+
+static int _cmppath(const char *s1, const char *s2)
+{
+ int c1, c2;
+
+ while(*s1 && *s2)
+ {
+ c1 = TOLOWER(*s1);
+ c2 = TOLOWER(*s2);
+ if(c1 != c2)
+ return c1 - c2;
+ s1++;
+ s2++;
+ }
+
+ return *s1 - *s2;
+}
+
+static int _cmpchar(char c1, char c2)
+{
+ return TOLOWER(c1) - TOLOWER(c2);
+}
+#else
+static int _cmppath(const char *s1, const char *s2)
+{
+ return strcmp(s1, s2);
+}
+
+static int _cmpchar(char c1, char c2)
+{
+ return c1 - c2;
+}
+#endif
+
/* Returns the difference of the provided two lists of files.
* Pre-condition: both lists are sorted!
* When done, free the list but NOT the contained data.
@@ -39,7 +76,7 @@
char *strA = filesA->files[ctrA].name;
char *strB = filesB->files[ctrB].name;
- int cmp = strcmp(strA, strB);
+ int cmp = _cmppath(strA, strB);
if(cmp < 0) {
/* item only in filesA, qualifies as a difference */
ret = alpm_list_add(ret, strA);
@@ -63,7 +100,7 @@
static int _alpm_filelist_pathcmp(const char *p1, const char *p2)
{
- while(*p1 && *p1 == *p2) {
+ while(*p1 && _cmpchar(*p1, *p2) == 0) {
p1++;
p2++;
}
@@ -75,7 +112,7 @@
p1++;
}
- return *p1 - *p2;
+ return _cmpchar(*p1, *p2);
}
/* Returns the intersection of the provided two lists of files.
@@ -115,7 +152,7 @@
{
const alpm_file_t *file1 = f1;
const alpm_file_t *file2 = f2;
- return strcmp(file1->name, file2->name);
+ return _cmppath(file1->name, file2->name);
}
alpm_file_t SYMEXPORT *alpm_filelist_contains(alpm_filelist_t *filelist,
@@ -137,7 +174,7 @@
{
size_t i;
for(i = 1; i < filelist->count; i++) {
- if(strcmp(filelist->files[i - 1].name, filelist->files[i].name) > 0) {
+ if(_cmppath(filelist->files[i - 1].name, filelist->files[i].name) > 0) {
/* filelist is not pre-sorted */
qsort(filelist->files, filelist->count,
sizeof(alpm_file_t), _alpm_files_cmp);