Skip to content

Commit 7404aeb

Browse files
authored
Merge pull request #1 from camilajenny/master
adhere to Debian version comparison guidelines
2 parents 87e86e9 + ab4a8ef commit 7404aeb

22 files changed

+3365
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*~
22
build/
33
.flatpak-builder
4+
.idea/

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
Install, update, uninstall and view information about debian packages.
2121

22-
Eddy can also support other packaging formats such as .rpm thanks to it's PackageKit backend, although it's primary focus is managing debian packages and being designed for elementary OS.
22+
Eddy can also support other packaging formats such as .rpm thanks to its PackageKit backend, although its primary focus
23+
is managing debian packages and being designed for elementary OS.
2324

2425
## Installation
2526

@@ -31,9 +32,12 @@ These dependencies must be present before building
3132
- `packagekit-glib2`
3233
- `unity`
3334

34-
You can install these on a Ubuntu-based system by executing this command:
35+
You can install these on an Ubuntu-based system by executing this command:
3536

36-
`sudo apt install valac libgranite-dev libpackagekit-glib2-dev libunity-dev meson ninja-build libzeitgeist-2.0-dev gettext`
37+
```
38+
sudo apt install valac libgranite-dev libpackagekit-glib2-dev libunity-dev meson ninja-build \
39+
libzeitgeist-2.0-dev gettext
40+
```
3741

3842
### Building
3943
```
@@ -48,9 +52,21 @@ sudo ninja install
4852
com.github.donadigo.eddy
4953
```
5054

51-
### Reporting bugs & debugging
52-
When reporting a bug you should include as much information as possible, that is the system that you're running, what you did in order to have the bug appear and probably a simple list of steps on how to reproduce the issue, however it is not required as some issues are not easily reproducible.
55+
## Running tests
56+
After `meson build` is complete, run
57+
```
58+
ninja -C build
59+
```
60+
once, and after that each time there's a change in a unit test, run
61+
```
62+
meson test -C build
63+
```
64+
65+
It should print OK on all the tests at the end of the output.
66+
67+
## Reporting bugs & debugging
68+
When reporting a bug, you should include as much information as possible, that is the system that you're running, what you did in order to have the bug appear and probably a simple list of steps on how to reproduce the issue, however, it is not required as some issues are not easily reproducible.
5369

54-
Additionally you can include a debug log in the description of the issue. To get a full log of backend and application messages, you can execute Eddy in a terminal with the following command:
70+
Additionally, you can include a debug log in the description of the issue. To get a full log of backend and application messages, you can execute Eddy in a terminal with the following command:
5571
`G_MESSAGES_DEBUG=all com.github.donadigo.eddy --debug`, reproduce the bug in the application window and copy the terminal output to the issue's description.
5672
This information could really help localizing and fixing the issue.

meson.build

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ executable(
3838
'src/AppSettings.vala',
3939
'src/Constants.vala',
4040
'src/DetailedView.vala',
41+
'src/EddyUtils.vala',
4142
'src/FolderLoader.vala',
4243
'src/MainWindow.vala',
4344
'src/MimeTypeHelper.vala',
@@ -51,7 +52,23 @@ executable(
5152
install: true
5253
)
5354

55+
#
56+
# Build glue
57+
#
58+
59+
valadoc = find_program('valadoc', required: false)
60+
61+
vala_unit_proj = subproject(
62+
'vala-unit',
63+
default_options: [
64+
'install=false',
65+
'valadoc=@0@'.format(valadoc.found())
66+
]
67+
)
68+
vala_unit_dep = vala_unit_proj.get_variable('vala_unit_dep')
69+
5470
subdir('data')
5571
subdir('po')
72+
subdir('test')
5673

5774
meson.add_install_script('meson/post_install.py')

src/EddyUtils.vala

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
public class EddyUtils {
2+
public static int compare_versions (string v1, string v2) {
3+
// https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
4+
5+
string a = v1;
6+
string b = v2;
7+
8+
// check for empty strings - later we split the strings and it would break on an empty array
9+
if (a == "")
10+
return -1;
11+
if (b == "")
12+
return 1;
13+
14+
// check epochs
15+
string[] atok = a.split(":");
16+
string[] btok = b.split(":");
17+
18+
int a_epoch, b_epoch;
19+
if (atok.length >= 2 ) {
20+
bool a_is_epoch = int.try_parse(atok[0], out a_epoch);
21+
22+
if(!a_is_epoch)
23+
a_epoch = 0;
24+
} else {
25+
a_epoch = 0;
26+
}
27+
28+
if (btok.length >= 2) {
29+
bool b_is_epoch = int.try_parse(btok[0], out b_epoch);
30+
31+
if(!b_is_epoch)
32+
b_epoch = 0;
33+
} else {
34+
b_epoch = 0;
35+
}
36+
37+
if (a_epoch != b_epoch)
38+
return a_epoch - b_epoch;
39+
40+
// trim epochs when the same (including assumed 0 when none)
41+
a = join_sliced_from_1(atok);
42+
b = join_sliced_from_1(btok);
43+
44+
//check upstream version
45+
Regex regex = new Regex("[+~-]");
46+
atok = regex.split(a);
47+
btok = regex.split(b);
48+
49+
string[] aparts = atok[0].split (".");
50+
string[] bparts = btok[0].split (".");
51+
52+
int length = int.min (aparts.length, bparts.length);
53+
for (int i = 0; i < length; i++) {
54+
int a_num, b_num;
55+
bool a_is_num = int.try_parse(aparts[i], out a_num);
56+
bool b_is_num = int.try_parse(bparts[i], out b_num);
57+
58+
if (a_is_num && b_is_num) {
59+
int diff = a_num - b_num;
60+
if (diff != 0) {
61+
return diff;
62+
}
63+
} else {
64+
int rc = strcmp (aparts[i], bparts[i]);
65+
if (rc != 0) {
66+
return rc;
67+
}
68+
}
69+
if (i == length - 1) {
70+
if(aparts.length != bparts.length) {
71+
return aparts.length - bparts.length;
72+
}
73+
}
74+
}
75+
76+
// a tilde sorts before anything, even the end of a part
77+
atok = a.split ("~");
78+
btok = b.split ("~");
79+
80+
if (atok.length < 2 && btok.length >= 2) {
81+
return 1;
82+
} else if (atok.length >= 2 && btok.length < 2) {
83+
return -1;
84+
}
85+
86+
// check debian revision if present
87+
atok = a.split("-");
88+
btok = b.split("-");
89+
90+
int a_dr, b_dr;
91+
bool a_dr_is_num = int.try_parse(atok[atok.length - 1], out a_dr);
92+
bool b_dr_is_num = int.try_parse(btok[btok.length - 1], out b_dr);
93+
94+
if (a_dr_is_num && b_dr_is_num) {
95+
if (a_dr != b_dr)
96+
return a_dr - b_dr;
97+
}
98+
99+
return strcmp(a, b);
100+
}
101+
102+
private static string join_sliced_from_1(string[] arr) {
103+
if (arr.length == 0)
104+
return "";
105+
106+
if (arr.length == 1)
107+
return arr[0];
108+
109+
string result = "";
110+
for (int i = 1; i < arr.length; i++) {
111+
result += arr[i];
112+
}
113+
114+
return result;
115+
}
116+
}

src/Package.vala

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -260,47 +260,6 @@ public class Eddy.Package : Object {
260260
}
261261
}
262262

263-
private static int compare_versions (string a, string b) {
264-
if (a == b) {
265-
return 0;
266-
}
267-
268-
string[] atok = a.split ("~");
269-
string[] btok = b.split ("~");
270-
271-
if (atok.length < 2 && btok.length >= 2) {
272-
return -1;
273-
} else if (atok.length >= 2 && btok.length < 2) {
274-
return 1;
275-
}
276-
277-
string aver = atok[0];
278-
string bver = btok[0];
279-
280-
string[] aparts = aver.split (".");
281-
string[] bparts = bver.split (".");
282-
283-
int length = int.max (aparts.length, bparts.length);
284-
for (int i = 0; i < length; i++) {
285-
int a_num, b_num;
286-
bool a_is_num = int.try_parse(aparts[i], out a_num);
287-
bool b_is_num = int.try_parse(bparts[i], out b_num);
288-
289-
if (a_is_num && b_is_num) {
290-
if (a_num < b_num) {
291-
return -1;
292-
} else if (a_num > b_num) {
293-
return 1;
294-
}
295-
return 0;
296-
} else {
297-
return strcmp (aparts[i], bparts[i]);
298-
}
299-
}
300-
301-
return 0;
302-
}
303-
304263
public Package (string filename) {
305264
Object (filename: filename);
306265
}
@@ -426,10 +385,10 @@ public class Eddy.Package : Object {
426385
found = true;
427386
state_flags = StateFlags.INSTALLED;
428387

429-
int rc = compare_versions (package.get_version (), version);
430-
if (rc == 1) {
388+
int rc = EddyUtils.compare_versions (version, package.get_version ());
389+
if (rc < 0) {
431390
state_flags |= StateFlags.CAN_DOWNGRADE;
432-
} else if (rc == -1) {
391+
} else if (rc > 0) {
433392
state_flags |= StateFlags.CAN_UPDATE;
434393
}
435394
}

0 commit comments

Comments
 (0)