Package: listaller / 0.5.5-2

02_lidatabase-update-1.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
From 97c617b2114c373b355e1855f95b02a9d5a84c7c Mon Sep 17 00:00:00 2001
From: Matthias Klumpp <matthias@tenstral.net>
Date: Wed, 30 May 2012 02:33:17 +0200
Subject: [PATCH] database: Get rid of dbid and improve other parts of the db

/!\ Breaks ABI!
---
 contrib/libuild/CMakeLists.txt |    2 +-
 src/application.vala           |   19 ++---
 src/database-internal.vala     |  152 ++++++++++++++++++++++------------------
 src/database.vala              |   40 ++++-------
 src/manager.vala               |    9 ++-
 src/settings.vala              |    4 +-
 src/utils.vala                 |    2 +-
 tests/tests-database.vala      |    3 +-
 8 files changed, 112 insertions(+), 119 deletions(-)

diff --git a/contrib/libuild/CMakeLists.txt b/contrib/libuild/CMakeLists.txt
index e2c307b..7a265e3 100644
--- a/contrib/libuild/CMakeLists.txt
+++ b/contrib/libuild/CMakeLists.txt
@@ -7,7 +7,7 @@ find_package(GLIB2 REQUIRED)
 pkg_check_modules(GEE REQUIRED gee-1.0)
 pkg_check_modules(GIO2 REQUIRED gio-2.0)
 
-ensure_vala_version("0.12" MINIMUM)
+ensure_vala_version("0.14" MINIMUM)
 
 set(BUILDLIST_SOURCES buildlist.vala
 )
diff --git a/src/application.vala b/src/application.vala
index de8c282..cb86549 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -88,10 +88,12 @@ public class AppItem : Object {
 	private string _dependencies;
 	private bool _shared;
 	private AppOrigin _origin;
-	private int _dbid;
 	private string _app_id;
 	private Listaller.Settings liconf;
 
+	/**
+	 * Application identifier
+	 * */
 	public string idname {
 		get {
 			if (_idname.strip () == "")
@@ -216,14 +218,6 @@ public class AppItem : Object {
 		get { _app_id = generate_appid (); return _app_id; }
 	}
 
-	/**
-	 * Id number of this application in software database
-	 */
-	public int dbid {
-		get { return _dbid; }
-		set { _dbid = value; }
-	}
-
 	public AppItem.blank () {
 		_shared = false;
 		_idname = "";
@@ -233,7 +227,6 @@ public class AppItem : Object {
 		_description = "";
 		install_time = 0;
 		categories = "all;";
-		dbid = -1;
 		origin = AppOrigin.UNKNOWN;
 		_app_id = "";
 		_desktop_file = "";
@@ -268,7 +261,7 @@ public class AppItem : Object {
 	public string to_string () {
 		return "[ (" + idname + ") "
 			+ "(" + version +") "
-			+ "! " + appid + " ::" + dbid.to_string () + " "
+			+ "! " + appid + " :: (" + full_name + ") "
 			+ "]";
 	}
 
@@ -334,7 +327,9 @@ public class AppItem : Object {
 		assert (appid != "");
 	}
 
-	public void set_origin_from_string (string s) {
+	public void set_origin_from_string (string? s) {
+		if (s == null)
+			s = "";
 		switch (s) {
 			case ("package_ipk"):
 				origin = AppOrigin.IPK;
diff --git a/src/database-internal.vala b/src/database-internal.vala
index b1cc0d6..036e6d3 100644
--- a/src/database-internal.vala
+++ b/src/database-internal.vala
@@ -28,8 +28,7 @@ namespace Listaller {
 
 private const string DATABASE = ""
 		+ "CREATE TABLE IF NOT EXISTS applications ("
-		+ "id INTEGER PRIMARY KEY, "
-		+ "name TEXT UNIQUE NOT NULL, "
+		+ "name TEXT PRIMARY KEY, "
 		+ "full_name TEXT NOT NULL, "
 		+ "version TEXT NOT NULL, "
 		+ "desktop_file TEXT,"
@@ -45,8 +44,7 @@ private const string DATABASE = ""
 		+ "origin TEXT NOT NULL"
 		+ "); "
 		+ "CREATE TABLE IF NOT EXISTS dependencies ("
-		+ "id INTEGER PRIMARY KEY, "
-		+ "name TEXT UNIQUE NOT NULL, "
+		+ "name TEXT PRIMARY KEY, "
 		+ "full_name TEXT NOT NULL, "
 		+ "version TEXT NOT NULL, "
 		+ "description TEXT, "
@@ -67,37 +65,35 @@ private const string depcols = "name, full_name, version, description, author, h
 			"install_time, provided_by, components, environment, dependencies";
 
 private enum AppRow {
-	DBID = 0,
-	IDNAME = 1,
-	FULLNAME = 2,
-	VERSION = 3,
-	DESKTOPFILE = 4,
-	AUTHOR = 5,
-	PUBLISHER = 6,
-	CATEGORIES = 7,
-	DESCRIPTION = 8,
-	HOMEPAGE = 9,
-	ARCHITECTURE = 10,
-	INST_TIME = 11,
-	DEPS = 12,
-	REPLACES = 13,
-	ORIGIN = 14;
+	IDNAME = 0,
+	FULLNAME = 1,
+	VERSION = 2,
+	DESKTOPFILE = 3,
+	AUTHOR = 4,
+	PUBLISHER = 5,
+	CATEGORIES = 6,
+	DESCRIPTION = 7,
+	HOMEPAGE = 8,
+	ARCHITECTURE = 9,
+	INST_TIME = 10,
+	DEPS = 11,
+	REPLACES = 12,
+	ORIGIN = 13;
 }
 
 private enum DepRow {
-	DBID = 0,
-	IDNAME = 1,
-	FULLNAME = 2,
-	VERSION = 3,
-	DESCRIPTION = 4,
-	AUTHOR = 5,
-	HOMEPAGE = 6,
-	ARCHITECTURE = 7,
-	INST_TIME = 8,
-	PROVIDED_BY = 9,
-	COMPONENTS = 10,
-	ENVIRONMENT = 11,
-	DEPENDENCIES = 12;
+	IDNAME = 0,
+	FULLNAME = 1,
+	VERSION = 2,
+	DESCRIPTION = 3,
+	AUTHOR = 4,
+	HOMEPAGE = 5,
+	ARCHITECTURE = 6,
+	INST_TIME = 7,
+	PROVIDED_BY = 8,
+	COMPONENTS = 9,
+	ENVIRONMENT = 10,
+	DEPENDENCIES = 11;
 }
 
 public errordomain DatabaseError {
@@ -239,7 +235,7 @@ private class InternalDB : Object {
 
 		// Prepare statements
 
-		// InsterApp statement
+		// InsertApp statement
 		try {
 			db_assert (db.prepare_v2 ("INSERT INTO applications (" + appcols + ") "
 				+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
@@ -423,34 +419,34 @@ private class InternalDB : Object {
 
 		// Assign values
 		try {
-			db_assert (insert_app.bind_text (AppRow.IDNAME, item.idname), "assign value");
+			db_assert (insert_app.bind_text (AppRow.IDNAME +1, item.idname), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.VERSION, item.version), "assign value");
+			db_assert (insert_app.bind_text (AppRow.VERSION +1, item.version), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.FULLNAME, item.full_name), "assign value");
+			db_assert (insert_app.bind_text (AppRow.FULLNAME +1, item.full_name), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.DESKTOPFILE, item.desktop_file), "assign value");
+			db_assert (insert_app.bind_text (AppRow.DESKTOPFILE +1, item.desktop_file), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.AUTHOR, item.author), "assign value");
+			db_assert (insert_app.bind_text (AppRow.AUTHOR +1, item.author), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.PUBLISHER, item.publisher), "assign value");
+			db_assert (insert_app.bind_text (AppRow.PUBLISHER +1, item.publisher), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.CATEGORIES, item.categories), "assign value");
+			db_assert (insert_app.bind_text (AppRow.CATEGORIES +1, item.categories), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.DESCRIPTION, "%s\n\n%s".printf (item.summary, item.description)), "assign value");
+			db_assert (insert_app.bind_text (AppRow.DESCRIPTION +1, "%s\n\n%s".printf (item.summary, item.description)), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.HOMEPAGE, item.website), "assign value");
+			db_assert (insert_app.bind_text (AppRow.HOMEPAGE +1, item.website), "assign value");
 
 			//TODO: Handle arch field
-			db_assert (insert_app.bind_text (AppRow.ARCHITECTURE, "current"), "assign value");
+			db_assert (insert_app.bind_text (AppRow.ARCHITECTURE +1, "current"), "assign value");
 
-			db_assert (insert_app.bind_int64 (AppRow.INST_TIME, item.install_time), "assign value");
+			db_assert (insert_app.bind_int64 (AppRow.INST_TIME +1, item.install_time), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.ORIGIN, item.origin.to_string ()), "assign value");
+			db_assert (insert_app.bind_text (AppRow.ORIGIN +1, item.origin.to_string ()), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.DEPS, item.dependencies), "assign value");
+			db_assert (insert_app.bind_text (AppRow.DEPS +1, item.dependencies), "assign value");
 
-			db_assert (insert_app.bind_text (AppRow.REPLACES, item.replaces), "assign value");
+			db_assert (insert_app.bind_text (AppRow.REPLACES +1, item.replaces), "assign value");
 
 			db_assert (insert_app.step (), "execute app insert");
 
@@ -540,7 +536,6 @@ private class InternalDB : Object {
 	private AppItem? retrieve_app_item (Sqlite.Statement stmt) {
 		AppItem item = new AppItem.blank ();
 
-		item.dbid = stmt.column_int (AppRow.DBID);
 		item.idname = stmt.column_text (AppRow.IDNAME);
 		item.full_name = stmt.column_text (AppRow.FULLNAME);
 		item.version = stmt.column_text (AppRow.VERSION);
@@ -639,13 +634,12 @@ private class InternalDB : Object {
 		return itemList;
 	}
 
-	public AppItem? get_application_by_dbid (uint databaseId) throws DatabaseError {
+	public ArrayList<AppItem>? get_applications_all () throws DatabaseError {
 		Sqlite.Statement stmt;
-		int res = db.prepare_v2 ("SELECT * FROM applications WHERE id=?", -1, out stmt);
+		int res = db.prepare_v2 ("SELECT * FROM applications", -1, out stmt);
 
 		try {
-			db_assert (res, "get application (by database-id)");
-			db_assert (stmt.bind_int64 (1, databaseId), "bind value");
+			db_assert (res, "get application (by full_name)");
 
 			res = stmt.step ();
 			db_assert (res, "execute");
@@ -655,13 +649,33 @@ private class InternalDB : Object {
 			throw new DatabaseError.ERROR (e.message);
 		}
 
-		AppItem? item = retrieve_app_item (stmt);
+		ArrayList<AppItem>? itemList = null;
+		do {
+			res = stmt.step ();
+			switch (res) {
+				case Sqlite.DONE:
+					break;
+				case Sqlite.ROW:
+					// Check if we have the container ready
+					if (itemList == null)
+						itemList = new ArrayList<AppItem> ();
 
-		// Fast sanity checks
-		if (item != null)
-			item.fast_check ();
+					// Fetch a new AppItem
+					AppItem? tmpApp = retrieve_app_item (stmt);
+					// Fast sanity checks
+					if (tmpApp != null)
+						tmpApp.fast_check ();
+					else
+						throw new DatabaseError.ERROR ("Unable to retrieve an application from database! DB might be in an inconstistent state!");
+					itemList.add (tmpApp);
+					break;
+				default:
+					db_assert (res, "execute");
+					break;
+			}
+		} while (res == Sqlite.ROW);
 
-		return item;
+		return itemList;
 	}
 
 	public AppItem? get_application_by_name_version (string appName, string appVersion) throws DatabaseError {
@@ -806,29 +820,29 @@ private class InternalDB : Object {
 
 		try {
 			// Assign values
-			db_assert (insert_dep.bind_text (DepRow.IDNAME, dep.idname), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.IDNAME +1, dep.idname), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.FULLNAME, dep.full_name), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.FULLNAME +1, dep.full_name), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.VERSION, dep.version), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.VERSION +1, dep.version), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.DESCRIPTION, "%s\n\n%s".printf (dep.summary, dep.description)), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.DESCRIPTION +1, "%s\n\n%s".printf (dep.summary, dep.description)), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.HOMEPAGE, dep.homepage), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.HOMEPAGE +1, dep.homepage), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.AUTHOR, dep.author), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.AUTHOR +1, dep.author), "bind value");
 
-			db_assert (insert_dep.bind_int64 (DepRow.INST_TIME, dep.install_time), "bind value");
+			db_assert (insert_dep.bind_int64 (DepRow.INST_TIME +1, dep.install_time), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.ARCHITECTURE, dep.architecture), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.ARCHITECTURE +1, dep.architecture), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.PROVIDED_BY, dep.get_installdata_as_string ()), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.PROVIDED_BY +1, dep.get_installdata_as_string ()), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.COMPONENTS, dep.get_componentdata_as_string ()), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.COMPONENTS +1, dep.get_componentdata_as_string ()), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.ENVIRONMENT, dep.environment), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.ENVIRONMENT +1, dep.environment), "bind value");
 
-			db_assert (insert_dep.bind_text (DepRow.DEPENDENCIES, ""), "bind value");
+			db_assert (insert_dep.bind_text (DepRow.DEPENDENCIES +1, ""), "bind value");
 
 			db_assert (insert_dep.step (), "add dependency");
 
diff --git a/src/database.vala b/src/database.vala
index cfda0d6..077297c 100644
--- a/src/database.vala
+++ b/src/database.vala
@@ -289,22 +289,7 @@ private class SoftwareDB : MsgObject {
 
 	public AppItem? get_application_by_id (AppItem app) {
 		AppItem? resApp;
-		try  {
-			if (app.shared) {
-				if (shared_db_canbeused ())
-					resApp = db_shared.get_application_by_idname (app.idname);
-				else
-					return null;
-			} else {
-				if (private_db_canbeused ())
-					resApp = db_priv.get_application_by_idname (app.idname);
-				else
-					return null;
-			}
-		} catch (Error e) {
-			emit_dberror (_("Unable to fetch application by id: %s").printf (e.message));
-			resApp = null;
-		}
+		resApp = get_application_by_idname (app.idname);
 		return resApp;
 	}
 
@@ -364,16 +349,12 @@ private class SoftwareDB : MsgObject {
 		return list;
 	}
 
-	public void _internal_process_dbapps (InternalDB db, double one, ref ArrayList<AppItem> appList) {
+	public void _internal_emit_dbapps (double one, ref ArrayList<AppItem> appList) {
 		uint i = 1;
-		AppItem? capp = db.get_application_by_dbid (i);
-		while (capp != null) {
-			application (capp);
-			appList.add (capp);
+		foreach (AppItem app in appList) {
+			application (app);
 			change_main_progress ((int) Math.round (one * i));
-
 			i++;
-			capp = db.get_application_by_dbid (i);
 		}
 	}
 
@@ -383,14 +364,17 @@ private class SoftwareDB : MsgObject {
 		double one = 100d / get_applications_count ();
 
 		if (private_db_canbeused ()) {
-			_internal_process_dbapps (db_priv, one, ref alist);
+			alist = db_priv.get_applications_all ();
 		}
 		if (shared_db_canbeused ()) {
-			// TODO: A nicer solution is needed here...
-			// We set this to 0 to not get the "Progress cannot go down" message
-			change_main_progress (0);
-			_internal_process_dbapps (db_shared, one, ref alist);
+			if (alist == null)
+				alist = db_shared.get_applications_all ();
+			else
+				alist.add_all (db_shared.get_applications_all ());
 		}
+		if (alist == null)
+			return false;
+		_internal_emit_dbapps (one, ref alist);
 		appList = alist;
 
 		return true;
diff --git a/src/manager.vala b/src/manager.vala
index 9cc64a9..164404e 100644
--- a/src/manager.vala
+++ b/src/manager.vala
@@ -291,8 +291,9 @@ public class Manager : MsgObject {
 	}
 
 	public string get_app_ld_environment (AppItem app) {
-		if (app.dbid < 0) {
-			debug ("AppItem database id was < 0! Application was maybe not retrieved from software DB and therefore lacks the required data.");
+		string[] depStr = app.dependencies.split ("\n");
+		if (depStr.length <= 0) {
+			debug ("No dependencies set! Application was maybe not retrieved from software DB and therefore lacks the required data.");
 			debug ("Setting empty environment...");
 			return "";
 		}
@@ -309,11 +310,9 @@ public class Manager : MsgObject {
 		else
 			db.force_db = ForceDB.PRIVATE;
 
-		// A new DepManager for the resolving...
+		// A new DepManager to resolve environment
 		DepManager depman = new DepManager (db);
 
-		string[] depStr = app.dependencies.split ("\n");
-
 		string paths = "";
 
 		HashSet<IPK.Dependency> depList = depman.dependencies_from_idlist (depStr);
diff --git a/src/settings.vala b/src/settings.vala
index 7a3d8f4..3a61119 100644
--- a/src/settings.vala
+++ b/src/settings.vala
@@ -1,4 +1,4 @@
-/* settings.vala
+/* settings.vala -- Store global settings which affect all Listaller modules
  *
  * Copyright (C) 2009-2012 Matthias Klumpp <matthias@tenstral.net>
  *
@@ -112,7 +112,7 @@ public class Settings : Object {
 	}
 
 	public string database_file () {
-		return appregister_dir () + "/software.db";
+		return appregister_dir () + "/installed.db";
 	}
 
 	[CCode (array_length = false, array_null_terminated = true)]
diff --git a/src/utils.vala b/src/utils.vala
index 261d57f..05de486 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -350,7 +350,7 @@ private bool dir_is_empty (string dirname) {
 	return n == 0;
 }
 
-private string fold_user_dir (string path) {
+private string fold_user_dir (string? path) {
 	if ((path == null) || (path == ""))
 		return "";
 	string udir = Environment.get_home_dir ();
diff --git a/tests/tests-database.vala b/tests/tests-database.vala
index da02328..0515bff 100644
--- a/tests/tests-database.vala
+++ b/tests/tests-database.vala
@@ -70,7 +70,8 @@ void test_software_db () {
 	msg ("Retrieving AppItem from database...");
 	AppItem newItem = sdb.get_application_by_idname ("test");
 	assert (newItem != null);
-	assert (newItem.dbid == 1);
+	assert (newItem.idname == "test");
+	assert (newItem.full_name == "Test");
 
 	msg ("Item is: %s".printf (newItem.to_string ()));
 
-- 
1.7.10