Merge lp:~kyrofa/click/bugfix_1479001 into lp:click

Proposed by Kyle Fazzari
Status: Superseded
Proposed branch: lp:~kyrofa/click/bugfix_1479001
Merge into: lp:click
Diff against target: 118 lines (+88/-2)
2 files modified
click/tests/test_database.py (+68/-0)
lib/click/database.vala (+20/-2)
To merge this branch: bzr merge lp:~kyrofa/click/bugfix_1479001
Reviewer Review Type Date Requested Status
Alejandro J. Cura Pending
dobey Pending
click hackers Pending
Review via email: mp+273469@code.launchpad.net

This proposal has been superseded by a proposal from 2015-10-06.

Commit message

Garbage collect old user registrations.

Description of the change

Garbage collect old user registrations.

This should fix bug #1479001, but introduces the following known regression:

Users can only register old versions of an app between reboots-- the system hooks (which are run on boot) will update old registrations to be pointing to the newest version of an app in any database. This is fixable but requires comparing timestamps of the registrations to the app, which is a more in-depth change.

To post a comment you must log in.
lp:~kyrofa/click/bugfix_1479001 updated
582. By Kyle Fazzari

Garbage collect old user registrations.

583. By Kyle Fazzari

Move version comparisons to dpkg --compare-versions.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'click/tests/test_database.py'
--- click/tests/test_database.py 2014-09-29 11:40:56 +0000
+++ click/tests/test_database.py 2015-10-05 20:44:54 +0000
@@ -412,6 +412,74 @@
412 self.db.gc()412 self.db.gc()
413 self.assertTrue(os.path.exists(a_path))413 self.assertTrue(os.path.exists(a_path))
414414
415 # Test that bug #1479001 is fixed. Uses the following scenario:
416 #
417 # - Two databases: db1 and db2.
418 # - One package, "test-package":
419 # - Versions 1 and 3 installed in db1
420 # - Version 2 installed in db2
421 # - User has a registration in db2 for version 2, where the registration
422 # timestamp precedes the installation of version 3.
423 #
424 # In this case, bug #1479001 expects that the user's registration would
425 # be updated to 3, since it was installed after the user registered for
426 # 2, which implies that the user would like the update to 3.
427 def test_gc_fixes_old_user_registrations(self):
428 with self.run_in_subprocess("getpwnam") as (enter, preloads):
429 enter()
430
431 # Setup the system hook
432 preloads["getpwnam"].side_effect = (
433 lambda name: self.make_pointer(Passwd(pw_dir=b"/foo")))
434
435 # Setup both databases
436 db1 = os.path.join(self.temp_dir, "db1")
437 db2 = os.path.join(self.temp_dir, "db2")
438 db = Click.DB()
439 db.add(db1)
440 db.add(db2)
441
442 # Prepare common manifest for the packages
443 manifest = {"hooks": {"test-app": {"test": "foo"}}}
444
445 # Setup versions 1.0 and 3.0 of package in db1
446 version1 = os.path.join(db1, "test-package", "1.0")
447 with mkfile(os.path.join(version1, ".click", "info",
448 "test-package.manifest")) as f:
449 json.dump(manifest, f)
450
451 version3 = os.path.join(db1, "test-package", "3.0")
452 with mkfile(os.path.join(version3, ".click", "info",
453 "test-package.manifest")) as f:
454 json.dump(manifest, f)
455
456 # Setup version 0.2 of package in db2
457 version2 = os.path.join(db2, "test-package", "2.0")
458 with mkfile(os.path.join(version2, ".click", "info",
459 "test-package.manifest")) as f:
460 json.dump(manifest, f)
461
462 # Setup the user registration for 2.0 in db2.
463 registrationPath = os.path.join(
464 db2, ".click", "users", "foo", "test-package")
465 os.makedirs(os.path.dirname(registrationPath))
466 os.symlink(version2, registrationPath)
467
468 # Run the garbage collection to update the registrations.
469 db.gc()
470
471 # Verify that the user still has a registration for the package,
472 # and that it's now registered for version 3.0.
473 self.assertTrue(os.path.lexists(registrationPath))
474 self.assertEqual(version3, os.readlink(registrationPath))
475
476 user_db = Click.User.for_user(db, "foo")
477 try:
478 version = user_db.get_version("test-package")
479 self.assertEqual("3.0", version)
480 except:
481 self.fail("No user registration for 'test-package'")
482
415 def _make_ownership_test(self):483 def _make_ownership_test(self):
416 path = os.path.join(self.temp_dir, "a", "1.0")484 path = os.path.join(self.temp_dir, "a", "1.0")
417 touch(os.path.join(path, ".click", "info", "a.manifest"))485 touch(os.path.join(path, ".click", "info", "a.manifest"))
418486
=== modified file 'lib/click/database.vala'
--- lib/click/database.vala 2014-09-29 11:40:56 +0000
+++ lib/click/database.vala 2015-10-05 20:44:54 +0000
@@ -430,6 +430,24 @@
430 public void430 public void
431 gc () throws Error431 gc () throws Error
432 {432 {
433 // Clean up user registrations-- registering for an old version of the
434 // package is no longer allowed.
435 foreach (var package in master_db.get_packages(true)) {
436 var users_db = new Users (master_db);
437 foreach (var name in users_db.get_user_names ()) {
438 var user_db = users_db.get_user (name);
439 try {
440 string registered_version = user_db.get_version (package.package);
441 // Update the user's registered version if necessary.
442 if (registered_version < package.version) {
443 user_db.set_version (package.package, package.version);
444 }
445 } catch (UserError e) {
446 // User isn't registered for this app. Skip it.
447 }
448 }
449 }
450
433 var users_db = new Users (master_db);451 var users_db = new Users (master_db);
434 var user_reg = new Gee.HashMultiMap<string, string> ();452 var user_reg = new Gee.HashMultiMap<string, string> ();
435 foreach (var user_name in users_db.get_user_names ()) {453 foreach (var user_name in users_db.get_user_names ()) {
@@ -625,8 +643,8 @@
625 *643 *
626 * The directory where changes should be written.644 * The directory where changes should be written.
627 */645 */
628 public string overlay 646 public string overlay
629 { 647 {
630 get {648 get {
631 if (db.size == 0)649 if (db.size == 0)
632 return "";650 return "";

Subscribers

People subscribed via source and target branches

to all changes: