This algorithm is used for uninstalling bundles and packages with gpt-uninstall. The key to this algorithm is that only those packages which do not fulfill dependencies to other packages and are not owned by any installed bundles can be deleted. The algorithm starts with two sets of packages, two sets of bundles, the -force flag.
List of bundles the user wants to remove from an installation.
List of packages the user wants to remove from an installation.
List of bundles that are currently installed.
List of packages that are currently installed.
The algorithm is outlined in the following steps:
The ToBeUninstalledBundles set is expanded to packages which are added to the ToBeUninstalledPackages set.
This check is skipped if -force is true. Each package in ToBeUninstalledPackages is examined to determine which bundles include the package in their packaging list. If any of these bundles are not in ToBeUninstalledBundles then the package is removed from ToBeUninstalledPackages.
This check is skipped if -force is true. Each package in ToBeUninstalledPackages is examined to determine if the package provides dependencies to other packages in InstalledPackages. If any of these dependent packages are not in ToBeUninstalledPackages the package is simply from ToBeUninstalledPackages.
ToBeUninstalledBundles and ToBeUninstalledPackages are passed to the code that does the actual removals.