Compare commits

...

2 Commits

Author SHA1 Message Date
Gabriele Modena
1d8bd8fc71
Merge e637f51f65 into 1cba177bb0 2024-11-10 15:35:08 +00:00
Gabriele Modena
e637f51f65 remotes: test for existance before delete.
Test if the remote exists before deleting it. This guards against two potential issues:
1. A Flatpakref might install non-enumerable remotes that are automatically deleted
   when the application is uninstalled, so attempting to delete them without checking
   could cause errors.
2. Users might manually delete apps/remotes, which could impact nix-flatpak state;
   checking prevents errors if the remote has already been removed.
2024-11-10 16:33:00 +01:00

View File

@ -16,13 +16,23 @@ let
# Delete all remotes that are present in the old state but not the new one
# $OLD_STATE and $NEW_STATE are globals, declared in the output of pkgs.writeShellScript.
# If uninstallUnmanagedState is true, then the remotes will be deleted forcefully.
#
# Test if the remote exists before deleting it. This guards against two potential issues:
# 1. A Flatpakref might install non-enumerable remotes that are automatically deleted
# when the application is uninstalled, so attempting to delete them without checking
# could cause errors.
# 2. Users might manually delete apps/remotes, which could impact nix-flatpak state;
# checking prevents errors if the remote has already been removed.
${pkgs.jq}/bin/jq -r -n \
--argjson old "$OLD_STATE" \
--argjson new "$NEW_STATE" \
'(($old.remotes // []) - ($new.remotes // []))[]' \
| while read -r REMOTE_NAME; do
${pkgs.flatpak}/bin/flatpak remote-delete ${if uninstallUnmanaged then " --force " else " " } --${installation} $REMOTE_NAME
if ${pkgs.flatpak}/bin/flatpak --${installation} remotes --columns=name | grep -q "^$REMOTE_NAME$"; then
${pkgs.flatpak}/bin/flatpak remote-delete ${if uninstallUnmanaged then " --force " else " " } --${installation} $REMOTE_NAME
else
echo "Remote '$REMOTE_NAME' not found in flatpak remotes"
fi
done
'';