-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
563da6e
to
bcb26c0
Compare
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
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? |
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.