From e637f51f6523c8fad28af79ea6b1f64697fa9945 Mon Sep 17 00:00:00 2001 From: Gabriele Modena Date: Sun, 10 Nov 2024 16:33:00 +0100 Subject: [PATCH] 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. --- modules/remotes.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/remotes.nix b/modules/remotes.nix index 856c3a7..fa21955 100644 --- a/modules/remotes.nix +++ b/modules/remotes.nix @@ -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 '';