Skip to content

transaction: Add delete app data option - #6728

Merged
swick merged 5 commits into
flatpak:mainfrom
razzeee:transaction-delete-data
Sep 23, 2026
Merged

swick merged 5 commits into
flatpak:mainfrom
razzeee:transaction-delete-data

Conversation

@razzeee

@razzeee razzeee commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Story here is, that I've read https://linuxnews.de/flatsweep-aufraeumhelfer-fuer-flatpak-reste/ and wondered, why there is even a need for an app like flatsweep

Looked a bit into it and there are legimate usecases, where flatpak can't remove the user data (e.g. its a system app and gets uninstalled by an admin while the user partition is not unlocked etc)

Then looked how stores like bazaar implement it right now and it turns out, they all need to roll their own logic.
So while you can run flatpak remove my.demo.app --delete-data from the cli, there is no way to get that behavior via libflatpak.

@razzeee
razzeee force-pushed the transaction-delete-data branch from 01d8468 to 4764f3b Compare July 8, 2026 18:41
@razzeee razzeee changed the title transaction: Add delete-data option transaction: Add delete app data option Jul 8, 2026
@razzeee
razzeee force-pushed the transaction-delete-data branch from 4764f3b to 1154be5 Compare July 8, 2026 19:06
@swick

swick commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This really needs to be split up but most importantly needs a motivation (ideally in the PR description and the commits).

@razzeee

razzeee commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Is this shape for splitting commits fine? I would then rework like this:

  • Move old code into common
  • Improve old code in some places
  • Allow usage from libflatpak (which was the main motivation)

@swick

swick commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Sure, seems reasonable.

@razzeee
razzeee force-pushed the transaction-delete-data branch 8 times, most recently from bbaa11e to 6c0838c Compare July 10, 2026 00:37
@swick

swick commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

You really need to work on your commit splitting and commit messages. For one, the formatting: 80 chars per line. The first two commits don't give me enough information. The commit message tells me exactly the same as looking at the code, but not why (mention the broader goal), and not how (improve? seems like two commits, one removing the XdpDbusPermissionStore argument, one improving ownership).

@razzeee

razzeee commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

The broader goal is only archived by the 1st and last commits in tandem. I guess I can mention that there again, but it feels weird, as it's not complete without the third commit. (and was one of the reasons this was one commit in the first place)

I can split up the 2nd one or drop it and focus on the other commits. It's not needed, just removing an unused param and modernizing the pointer logic. (but my C is still very rusty, so happy to drop that)

Edit: Filled in the description in addition

@swick

swick commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

The first commit is just "common: Move app data helpers out of builtins".

I can see that. Why though? It only becomes clear when you reach the third commit. Just adding "We're going to expose them in libflatpak in a few commits" to the body is enough for a reviewer to understand.

The improvements in the second commit are good. It only needs to be split appropriately and have a message which isn't just "Improve things". Say what you're improving.

I know this can be annoying but it's an important part to get right and once you get it, it becomes pretty easy.

@razzeee

razzeee commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

No, it's totally fine, I was in a rush yesterday and shouldn't have pushed.

@razzeee
razzeee force-pushed the transaction-delete-data branch from 6c0838c to e721335 Compare July 10, 2026 11:20
@razzeee

razzeee commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Should the commit header also be shorter?

Comment thread doc/reference/meson.build
install : true,
install_dir : docdir,
)
endif

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like an extra newline snuck in here.

Comment thread common/flatpak-app-data.c Outdated
@@ -131,8 +131,5 @@ flatpak_delete_app_data (const char *app_id,
return FALSE;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix common is not helpful because it's too generic. Use app-data:.

Comment thread common/flatpak-transaction.c Outdated

if (res)
{
if (priv->delete_data && flatpak_decomposed_is_app (op->ref))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes:

  • Should this really be part of a transaction or of individual ops?
  • If it is per-op, then I guess we should only allow this for apps when setting it
  • What happens when this fails? The app has been uninstalled but the data has not been removed, now there is no way to remove the data via libflatpak.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. you mean it's own operation?
  2. we do skip non apps - but this is still the transaction implementation (not sure I follow)
  3. Yeah, I actually iterated on this over the past days. But ended up here again as I don't think we can recover. We could give a better return, but that would probably not be as backwards compatible.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean it's own operation?

Either that, or part of the uninstall op?

I mean, I'm not even sure if this really should be part of a transaction in the first place. Maybe it's fine to just provide a separate api to delete the data?

we do skip non apps - but this is still the transaction implementation (not sure I follow)

Right, my point is that if this were on the uninstall op, we could error out when constructing the transaction/op and it's not an app.

@razzeee razzeee Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having it's own operation seems simpler for us, but might not be the ideal API. Which would you prefer?

Edit: Give me a gut feeling, I can explore from there

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try to answer the question what we get from it being part of a transaction? If there isn't a good reason, let's not make it part of a transaction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My feeling is, that having a separate method to call would be better - even if it causes some implementation detail on the apps that are using it.

But it also might allow cleaning up app data, when the app is not installed at all or resetting it with keeping the app installed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, then let's do that instead.

@razzeee
razzeee force-pushed the transaction-delete-data branch 2 times, most recently from dd805fe to d266554 Compare August 6, 2026 10:14

@swick swick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks almost good. The merge commit needs to go and a few things should probably change.

Btw, if you want me to re-review something, please add a comment and say something.

Comment thread common/flatpak-app-data.c Outdated
#include "flatpak-utils-private.h"

char **
get_permission_tables (XdpDbusPermissionStore *store)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't seem to be the right place. The app data has nothing to do with the permission tables.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it's own common file now

Comment thread common/flatpak-app-data.c
Comment thread common/flatpak-app-data.c Outdated
gboolean
flatpak_delete_app_data (const char *app_id,
GError **error)
flatpak_delete_app_data_for_file (const char *app_id,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of flatpak_delete_app_data_for_file? We need an app id anyway, so why make it variable on the path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of it, don't remember why I did this.

if (!flatpak_is_valid_name (app_id, -1, error))
return FALSE;

path = g_build_filename (g_get_home_dir (), ".var", "app", app_id, NULL);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to be careful about paths. If any of the components is attacker controlled, a path can point to anywhere via symlinks. In this case everything is fine because ~/.var/app/$app_id is still all not attacker controlled (any path inside would be a vulnerability). Probably worth documenting.

@razzeee
razzeee force-pushed the transaction-delete-data branch from 6f8ec3e to 3849485 Compare August 18, 2026 13:51
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexander Larsson <[email protected]>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inherited from app/flatpak-builtins-uninstall.c

@razzeee
razzeee force-pushed the transaction-delete-data branch from 3849485 to 62cb28b Compare August 18, 2026 14:15
@razzeee
razzeee requested a review from swick August 18, 2026 14:31
@razzeee

razzeee commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

@swick hopefully addesses everything

@swick swick left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more nitpicks

Comment thread common/flatpak-permission-private.h Outdated

char ** get_permission_tables (XdpDbusPermissionStore *store);
gboolean flatpak_reset_permissions_for_app (const char *app_id,
GError **error);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classic claude. It often fails to properly align things.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully better now

Comment thread common/flatpak-permission.c Outdated
}

gboolean
flatpak_reset_permissions_for_app (const char *app_id,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, two things:

  1. We have a FlatpakPermission struct already, which makes this a bit awkard
  2. The functions here don't operate on an object but are just a collection of useful things, so it's probably better to call it something -utils in the name (or find an existing utils file which fits)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. not really sure, what you expect me to do here
  2. added -utils to the file name

Comment thread common/flatpak-app-data-private.h Outdated

#include <gio/gio.h>

gboolean flatpak_delete_app_data (const char *app_id,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the file is called flatpak-app-data, and we operate on the app data, it's better to name things accordingly: $prefix_$thing_$verb, so flatpak_app_data_delete

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be addressed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still flatpak_delete_app_data instead of flatpak_app_data_delete

@razzeee
razzeee force-pushed the transaction-delete-data branch 3 times, most recently from fb5b5ef to 522f3a1 Compare August 19, 2026 23:00
@razzeee
razzeee requested a review from swick August 19, 2026 23:30
@razzeee
razzeee force-pushed the transaction-delete-data branch from 522f3a1 to cea39b5 Compare August 23, 2026 16:17
@razzeee

razzeee commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebase due to test changes

Comment thread common/meson.build Outdated
Comment on lines 190 to 191
'flatpak-app-data.c',
'flatpak-appdata.c',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is super confusing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, changed

Comment thread common/flatpak-app-data-private.h Outdated

#include <gio/gio.h>

gboolean flatpak_delete_app_data (const char *app_id,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still flatpak_delete_app_data instead of flatpak_app_data_delete

@razzeee
razzeee force-pushed the transaction-delete-data branch from cea39b5 to cb2d7d3 Compare August 27, 2026 19:49
@swick

swick commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Mh, just calling the file app-data-delete.c doesn't really help with the app-data name conflict. The header is still just app-data.h as well. A function also gets renamed flatpak_delete_app_data to flatpak_app_data_delete in one commit to the next. Not super happy with all of that.

Libflatpak needs to reuse user-data deletion and permission reset logic
that was previously private to the command-line builtins. This will let
software stores offer the equivalent of uninstall --delete-data.

Move each concern into a separate common module without changing behavior
so a public API can be added in a later commit. Name the user-data module
and its helper consistently here, and keep them distinct from the
existing appdata metadata code.
Return the permission reset result directly after app data removal. This
keeps the success and error paths equivalent while removing an unnecessary
conditional.
Use GLib's automatic string-vector cleanup for permission table lists.
This makes ownership explicit and ensures early returns release the list.
Permission table discovery reads the on-disk database directory and does
not use the D-Bus permission store proxy. Remove the unused argument and
update callers.
@razzeee
razzeee force-pushed the transaction-delete-data branch from cb2d7d3 to db3a84c Compare September 22, 2026 22:40
Applications using libflatpak currently have to duplicate the CLI's
private cleanup logic to offer the equivalent of uninstall --delete-data.

Add a standalone API that removes ~/.var/app data and resets permission
store entries without requiring the app to be installed. Keep it separate
from transactions so callers can retry partial failures or reset data for
an installed app.

Validate app IDs before constructing paths, propagate cancellation and
permission table errors, and document partial failure behavior.
@razzeee
razzeee force-pushed the transaction-delete-data branch from db3a84c to 2c97205 Compare September 22, 2026 23:20
@swick
swick added this pull request to the merge queue Sep 23, 2026
Merged via the queue into flatpak:main with commit dec343a Sep 23, 2026
11 checks passed
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