Factorize PackageKit functionality into common library#8772
Merged
mvollmer merged 6 commits intocockpit-project:masterfrom Mar 9, 2018
Merged
Factorize PackageKit functionality into common library#8772mvollmer merged 6 commits intocockpit-project:masterfrom
mvollmer merged 6 commits intocockpit-project:masterfrom
Conversation
563da6e to
bcb26c0
Compare
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
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? |
4 tasks
mvollmer
approved these changes
Mar 9, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.