Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorize PackageKit functionality into common library #8772

Merged
merged 6 commits into from
Mar 9, 2018

Conversation

martinpitt
Copy link
Member

@martinpitt martinpitt commented Mar 5, 2018

PackageKit is currently being used by apps and updates, but we need that functionality in a lot more places soon. Provide a common interface in pkg/lib and use it in apps and updates.

@martinpitt martinpitt changed the title Factorize PackageKit functionality into common library WIP: Factorize PackageKit functionality into common library Mar 5, 2018
@martinpitt martinpitt force-pushed the pk-lib branch 4 times, most recently from 563da6e to bcb26c0 Compare March 6, 2018 13:47
@martinpitt
Copy link
Member Author

There was a load error failure in testInfoSecurity, which was previously hidden due to not properly propagating PackageKit errors in all cases. I pushed a separate commit to fix the tests.

Some PackageKit related test include a reboot, which removes the test
repository in /tmp/repo/. Move it to /var/tmp/repo/ instead to avoid
load errors with "/tmp/repo was not found" PackageKit errors.

Also avoid hardcoding the path in a gazillion places.
We are using PackageKit in updates and apps already, and are going to
use it in more places in the future. So create pkg/lib/packagekit.es6
with the common and generic code.
…library

Add functions for running and watching a PackageKit transaction to
pkg/lib/packagekit.es6. Replace the `failHandler` argument (as the
version in pkg/packagekit/updates.jsx had) with a promise rejection,
which is much more common JS style.

The apps' `transaction()` is significantly more complex than this basic
transaction, so write a shim for it for now.

Save the extra cockpit D-Bus proxy (which is rather expensive, and
occasionally causes hiccups with PackageKit) by remembering the progress
data throughout the entire transaction.
Attaching a notify handler with `cockpit.dbus().watch()` is not
instantaneous, so change packagekit.es6 `transaction()` to watch for
that to finish before calling the transaction method. This avoids
missing property notifications.

This bug was even worse in update.jsx's `UpdatePackages()` call, as this
sets up the whole transaction manually (in order to be able to reattach
to it). Restructure the code to watch the transaction *before* starting
the update, so that the signal handlers (like `ErrorCode`) are set up.
Otherwise it could happen that a transaction fails very fast, but the
signal would be missed and thus the UI is forever stuck at the
"Initializing..." state of the progress bar.

This was spot by a flaky `check-packagekit TestUpdates.testUpdateError`.
Move from `cockpit.defer` to using standard JavaScript `Promise`, so
that we can use the shared PackageKit library.

Use arrow functions in some places, which makes some code more concise.

Pass exceptions as an object, as `Promise.reject()` does not accept
multiple arguments.
Generalize apps's packagekit transaction shim from the previous commit
into pkg/lib/packagekit.es6 `cancellableTransaction()`. This resolves
when the transaction is done and handles the final signals (Finished or
ErrorCode), cancellation, progress reporting, and sensible "waiting for
lock" detection by itself. But let the client specify Package: and other
signal handlers to keep this code generic, and avoid passing around
extra callbacks.

Closes cockpit-project#8772
@martinpitt martinpitt changed the title WIP: Factorize PackageKit functionality into common library Factorize PackageKit functionality into common library Mar 6, 2018
@martinpitt martinpitt requested a review from mvollmer March 6, 2018 15:54
@martinpitt
Copy link
Member Author

I'm now reasonably happy about this for the first round. There's certainly more stuff which we can pull out of pkg/apps/packagekit.es6 and generalize, but I think this PR is already big enough as it is. @mvollmer, can you please review?

@martinpitt martinpitt mentioned this pull request Mar 6, 2018
4 tasks
@mvollmer mvollmer merged commit 1edf972 into cockpit-project:master Mar 9, 2018
@martinpitt martinpitt deleted the pk-lib branch March 9, 2018 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants