Commit 8836c8f87b00573910c894201ea72bdc58f29a5e

Authored by Silvan Calarco
1 parent 61352c7c3e
Exists in master

Fix checkVersionWithFlags for rpm 4 and remove semaphore handlings

Showing 3 changed files with 42 additions and 33 deletions Side-by-side Diff

... ... @@ -971,11 +971,7 @@
971 971 /* process package */
972 972 logmsg(LOG_DEBUG, "getting header for %s", filepath);
973 973  
974   - sem_t rpm_mutex = getRPMMutex();
975   -
976   - sem_wait(&rpm_mutex);
977 974 if (getHeader(&ts, filepath, &h)) {
978   - sem_post(&rpm_mutex);
979 975 errstr = strerror(errno);
980 976 logmsg(LOG_WARNING,
981 977 "%s: unable to read header (%s); skipping.",filename, errstr);
... ... @@ -998,7 +994,6 @@
998 994 }
999 995 memset(newheaderlist, 0, sizeof(struct headerList));
1000 996 getPackageInfoIntoHeaderList(h, newheaderlist);
1001   - sem_post(&rpm_mutex);
1002 997  
1003 998 if (!newheaderlist->sourcename) {
1004 999 logmsg(LOG_WARNING,
src/include/rpmfunctions.h
... ... @@ -33,7 +33,6 @@
33 33 #endif
34 34 #endif
35 35  
36   -#include <semaphore.h>
37 36 #include <dirent.h>
38 37  
39 38 #define HEADERS_BUFFER_SIZE 2000000
... ... @@ -76,8 +75,6 @@
76 75 int scanrpmnamecmp(const struct dirent **f1, const struct dirent **f2);
77 76  
78 77 char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *release);
79   -
80   -sem_t getRPMMutex();
81 78  
82 79 #endif // RPMFUNCTIONS_H
... ... @@ -28,6 +28,7 @@
28 28 # include <strings.h>
29 29 #endif
30 30  
  31 +#include <stdlib.h>
31 32 #include <fcntl.h>
32 33 #include <zlib.h>
33 34 #include <libiberty/libiberty.h>
34 35  
35 36  
36 37  
37 38  
38 39  
39 40  
40 41  
... ... @@ -35,38 +36,59 @@
35 36 #include "functions.h"
36 37 #include "rpmfunctions.h"
37 38  
38   -sem_t rpm_mutex;
39   -
40 39 /*
41 40 * static int getPackageInfo(
42 41 * Header h, char **name, char **version, char **release,
43 42 * char **summary); */
44 43  
  44 +struct EVR_s {
  45 + char *data;
  46 + uint32_t e;
  47 + char *v;
  48 + char *r;
  49 +} EVR;
  50 +
  51 +void rpmEVRsplit(const char* ver, struct EVR_s *evr) {
  52 + evr->e = 0;
  53 + evr->v = NULL;
  54 + evr->r = NULL;
  55 + evr->data = strdup(ver);
  56 + for (int i = 0; i < strlen(ver); i++) {
  57 + if (evr->data[i] == ':') {
  58 + evr->e = strtoul(ver, NULL, 10);
  59 + evr->data[i] = '\0';
  60 + evr->v = &evr->data[i+1];
  61 + } else if (evr->data[i] == '-') {
  62 + evr->data[i] = '\0';
  63 + evr->r = &evr->data[i+1];
  64 + if (evr->v == NULL) evr->v = evr->data;
  65 + }
  66 + }
  67 + if (evr->v == NULL) evr->v = evr->data;
  68 +}
  69 +
45 70 unsigned int checkVersionWithFlags(const char* cmp1, uint_32 flags, const char* cmp2) {
46 71 int vercmp = 0;
47   -#if RPM_VERSION_MAJOR >= 5
48   - struct EVR_s evr1, evr2;
  72 + struct EVR_s evr1, evr2;
49 73  
50   - sem_wait(&rpm_mutex);
51   - rpmEVRparse(cmp1, &evr1);
52   - rpmEVRparse(cmp2, &evr2);
53   - sem_post(&rpm_mutex);
  74 + rpmEVRsplit(cmp1, &evr1);
  75 + rpmEVRsplit(cmp2, &evr2);
54 76  
55   - if (strlen(evr1.F[RPMEVR_E]) && strlen(evr2.F[RPMEVR_E])) vercmp=rpmvercmp(evr1.F[RPMEVR_E], evr2.F[RPMEVR_E]);
56   - else if (strlen(evr2.F[RPMEVR_E])) vercmp = -1;
57   - else if (strlen(evr1.F[RPMEVR_E])) vercmp = 1;
  77 + if (evr1.e == evr2.e) vercmp = 0;
  78 + else if (evr1.e > evr2.e) vercmp = 1;
  79 + else vercmp = -1;
58 80  
59   - if (!vercmp) vercmp=rpmvercmp(evr1.F[RPMEVR_V], evr2.F[RPMEVR_V]);
60   - if (!vercmp && strlen(evr1.F[RPMEVR_R]) && strlen(evr2.F[RPMEVR_R])) vercmp=rpmvercmp(evr1.F[RPMEVR_R], evr2.F[RPMEVR_R]);
61   -#else
62   - vercmp=rpmvercmp(cmp1, cmp2);
63   -#endif
  81 + if (vercmp == 0) vercmp = rpmvercmp(evr1.v, evr2.v);
  82 + if (vercmp == 0 && evr1.r && evr2.r) vercmp = rpmvercmp(evr1.r, evr2.r);
64 83  
65   - if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1;
66   - else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1;
67   - else if ((vercmp == -1) && (flags & RPMSENSE_GREATER)) return 1;
  84 + free(evr1.data);
  85 + free(evr2.data);
68 86  
69   - return 0;
  87 + if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1;
  88 + else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1;
  89 + else if ((vercmp == -1) && (flags & RPMSENSE_GREATER)) return 1;
  90 +
  91 + return 0;
70 92 }
71 93  
72 94 /*
73 95  
... ... @@ -394,16 +416,11 @@
394 416 return s;
395 417 }
396 418  
397   -sem_t getRPMMutex() {
398   - return rpm_mutex;
399   -}
400   -
401 419 void rpminit() {
402 420 #if RPM_VERSION >= 0x040100
403 421 rpmReadConfigFiles(NULL, NULL);
404 422 // ts = rpmtsCreate();
405 423 // rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
406 424 #endif
407   - sem_init(&rpm_mutex, 0, 1);
408 425 }