Skip to content

Commit

Permalink
remotes: test for existance before delete.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gmodena committed Nov 10, 2024
1 parent b4613e7 commit e637f51
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions modules/remotes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';

Expand Down

0 comments on commit e637f51

Please sign in to comment.