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

FlatpakTransaction end-of-lifed-with-rebase API improvement #3991

Closed
mwleeds opened this issue Nov 26, 2020 · 5 comments · Fixed by #5332
Closed

FlatpakTransaction end-of-lifed-with-rebase API improvement #3991

mwleeds opened this issue Nov 26, 2020 · 5 comments · Fixed by #5332
Labels
enhancement libflatpak Issues involving the library

Comments

@mwleeds
Copy link
Collaborator

mwleeds commented Nov 26, 2020

Currently, when a FlatpakTransaction emits a end-of-lifed-with-rebase signal, the signal handler is expected to execute flatpak_transaction_add_uninstall() and flatpak_transaction_add_rebase(). However, as pointed out here, this isn't ideal because what you really want is to uninstall the old ref and rebase to the new one atomically, not potentially be in a situation where you do one but not the other (though rebasing without uninstalling is not as bad as uninstalling without rebasing).

So perhaps we need a way to remove something from the transaction, or a combined "uninstall and rebase" function.

@mwleeds mwleeds added enhancement libflatpak Issues involving the library labels Nov 26, 2020
@mwleeds mwleeds changed the title FlatpakTransaction API improvement FlatpakTransaction end-of-lifed-with-rebase API improvement Nov 26, 2020
@mwleeds
Copy link
Collaborator Author

mwleeds commented Nov 26, 2020

It is also possibly an issue that there's no way to abort the transaction in case of errors here. Perhaps that could be desirable.

mwleeds added a commit to mwleeds/flatpak that referenced this issue Nov 26, 2020
In case the second of these two fails, the first will still have been
added to the transaction. And since it's better to install the renamed
app but not uninstall the old one, than to uninstall the old one but not
install the new one, swap the order.

See also flatpak#3991
alexlarsson pushed a commit that referenced this issue Dec 9, 2020
In case the second of these two fails, the first will still have been
added to the transaction. And since it's better to install the renamed
app but not uninstall the old one, than to uninstall the old one but not
install the new one, swap the order.

See also #3991
@pwithnall
Copy link
Collaborator

pwithnall commented Mar 2, 2023

I’ve just been looking into this, and can reproduce it:

  1. Add the following code in flatpak-transaction.c around line 5150, just before the _run_op_kind() call:
if ((op->kind == FLATPAK_TRANSACTION_OPERATION_INSTALL_OR_UPDATE ||
     op->kind == FLATPAK_TRANSACTION_OPERATION_INSTALL) &&
    g_str_equal (pref, "app.drey.Dialect/x86_64/stable"))
  {
    g_set_error (&local_error, FLATPAK_ERROR, FLATPAK_ERROR_OUT_OF_SPACE, "er ner, out of space");
    res = FALSE;
  }
  1. Run flatpak uninstall --user -y app.drey.Dialect && flatpak install --user flathub app/com.github.gi_lom.dialect/x86_64/stable and when the second command asks you if you want to rebase, answer n
  2. Run flatpak update --user and watch as it fails to install the rebased app, and happily uninstalls the old app

You’ll be left with com.github.gi_lom.dialect.Locale installed and nothing else from the new or old versions of Dialect.

It’s not possible to work around this in the operation_error() handler in FlatpakCliTransaction, because FlatpakTransaction doesn’t impose any order on the rebase and uninstall ops, meaning that it happens that the uninstall op seems to always happen first.


I agree with @mwleeds that the fix here is to add a new flatpak_transaction_add_rebase_and_uninstall() API which combines the two existing add_rebase() and add_uninstall() calls, adds an ordering dependency between their ops, and sets op->fail_if_op_fails between them too.

I’ll look into implementing that now.

@ramcq
Copy link
Contributor

ramcq commented Mar 2, 2023

This always struck me as an odd API anyway; basically a signal that requires you to copy/paste code rather than like... return TRUE if you want to "do the thing".

pwithnall added a commit to pwithnall/flatpak that referenced this issue Mar 3, 2023
This will be used in the next commit to simplify some new code.
Currently, this introduces no functional changes.

Signed-off-by: Philip Withnall <[email protected]>

Helps: flatpak#3991
pwithnall added a commit to pwithnall/flatpak that referenced this issue Mar 3, 2023
This mostly replaces `flatpak_transaction_add_rebase()`. It’s necessary
because the uninstall op for an eol-rebased app needs to be linked to
the install/update op for the rebased app, otherwise one op can proceed
after the other has failed (or they can be run in the wrong order) and
result in the old app being uninstalled but the new one not installed.

The following commit will port the internal flatpak `FlatpakTransaction`
subclasses to use it. Other consumers of `FlatpakTransaction` (such as
gnome-software) will have to be ported as well.

Signed-off-by: Philip Withnall <[email protected]>

Fixes: flatpak#3991
pwithnall added a commit to pwithnall/flatpak that referenced this issue Mar 3, 2023
This fixes the possible situation where an eol-rebase app can be
uninstalled and the new version not correctly installed (due to, for
example, the install op failing due to a lack of disk space).

Signed-off-by: Philip Withnall <[email protected]>

Fixes: flatpak#3991
@pwithnall
Copy link
Collaborator

This always struck me as an odd API anyway; basically a signal that requires you to copy/paste code rather than like... return TRUE if you want to "do the thing".

Yeah, the end-of-lifed and end-of-lifed-with-rebase signals do seem a bit odd. I decided to go with adding a new flatpak_transaction_add_rebase_and_uninstall() though because the existing flatpak_transaction_add_rebase() method is impossible to use correctly (because it’s not possible to link it to an uninstall op), so it would have to be replaced/deprecated at some point anyway.

The changes in #5332 don’t preclude some other changes in future to rearrange how FlatpakTransaction::end-of-lifed{,-with-rebase} work. It’s not something I’m digging into now though, since I haven’t entirely read up on the history and all the intended uses of those signals.

@pwithnall
Copy link
Collaborator

I’ll look into implementing that now.

Fix available as #5332. It adds a new flatpak_transaction_add_rebase_and_uninstall() method and doesn’t touch the FlatpakTransaction::end-of-lifed-with-rebase signal.

pwithnall pushed a commit to pwithnall/flatpak that referenced this issue Mar 16, 2023
This adds a test to cover the changes in the previous commit.

Helps: flatpak#3991
pwithnall added a commit to pwithnall/flatpak that referenced this issue Mar 20, 2023
This mostly replaces `flatpak_transaction_add_rebase()`. It’s necessary
because the uninstall op for an eol-rebased app needs to be linked to
the install/update op for the rebased app, otherwise one op can proceed
after the other has failed (or they can be run in the wrong order) and
result in the old app being uninstalled but the new one not installed.

The following commit will port the internal flatpak `FlatpakTransaction`
subclasses to use it. Other consumers of `FlatpakTransaction` (such as
gnome-software) will have to be ported as well.

Signed-off-by: Philip Withnall <[email protected]>

Fixes: flatpak#3991
pwithnall added a commit to pwithnall/flatpak that referenced this issue Mar 20, 2023
This fixes the possible situation where an eol-rebase app can be
uninstalled and the new version not correctly installed (due to, for
example, the install op failing due to a lack of disk space).

Signed-off-by: Philip Withnall <[email protected]>

Fixes: flatpak#3991
pwithnall pushed a commit to pwithnall/flatpak that referenced this issue Mar 20, 2023
This adds a test to cover the changes in the previous commit.

Helps: flatpak#3991
alexlarsson pushed a commit that referenced this issue Mar 30, 2023
This will be used in the next commit to simplify some new code.
Currently, this introduces no functional changes.

Signed-off-by: Philip Withnall <[email protected]>

Helps: #3991
alexlarsson pushed a commit that referenced this issue Mar 30, 2023
This mostly replaces `flatpak_transaction_add_rebase()`. It’s necessary
because the uninstall op for an eol-rebased app needs to be linked to
the install/update op for the rebased app, otherwise one op can proceed
after the other has failed (or they can be run in the wrong order) and
result in the old app being uninstalled but the new one not installed.

The following commit will port the internal flatpak `FlatpakTransaction`
subclasses to use it. Other consumers of `FlatpakTransaction` (such as
gnome-software) will have to be ported as well.

Signed-off-by: Philip Withnall <[email protected]>

Fixes: #3991
alexlarsson pushed a commit that referenced this issue Mar 30, 2023
This fixes the possible situation where an eol-rebase app can be
uninstalled and the new version not correctly installed (due to, for
example, the install op failing due to a lack of disk space).

Signed-off-by: Philip Withnall <[email protected]>

Fixes: #3991
alexlarsson pushed a commit that referenced this issue Mar 30, 2023
This adds a test to cover the changes in the previous commit.

Helps: #3991
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement libflatpak Issues involving the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants