feat(flatpak): let the user choose which installation to act on
The same application can be present twice — in the user installation and system-wide, or from two remotes or two branches — and flatpak then refuses to act on the application id alone: "Multiple installed refs match 'com.hoptodesk.HopToDesk'". Removing either copy was impossible from the app. A row now stands for the application and carries the copies it is made of, so the details panel lists them and Remove opens one checkbox per copy; the provider gets back the exact target it listed, and naming a ref plus its installation is what makes the call unambiguous. Update gains the same resolution, since it hit the very same refusal, and removing one copy of two no longer takes the other one's launcher entry away with it. The listing that feeds it now asks flatpak for the ref, the branch and the installation, and reads those columns by position: a branch installed from a subdirectory has no version, and dropping that empty column shifted every field after it.
This commit is contained in:
14 files changed
+559
-20
No files matched your search
@@ -67,6 +67,62 @@ static void testParseInstalledOutput_emptyInput() {
|
||||
assert(FlatpakManager::parseInstalledOutput("").empty());
|
||||
}
|
||||
|
||||
// The same application installed more than once: one copy per installation,
|
||||
// per remote or per branch. Each row must say which one it is, or the view
|
||||
// cannot list the copies and the provider cannot act on any of them.
|
||||
static void testParseInstalledOutput_namesEveryInstallation() {
|
||||
std::string output =
|
||||
"com.hoptodesk.HopToDesk\t\thoptodesk-origin\tcom.hoptodesk.HopToDesk/x86_64/master\tmaster\tuser\n"
|
||||
"com.hoptodesk.HopToDesk\t1.46.38\tflathub\tcom.hoptodesk.HopToDesk/x86_64/stable\tstable\tuser\n"
|
||||
"com.usebottles.bottles\t67.3\tflathub\tcom.usebottles.bottles/x86_64/stable\tstable\tsystem\n"
|
||||
"com.usebottles.bottles\t67.3\tflathub\tcom.usebottles.bottles/x86_64/stable\tstable\tuser\n";
|
||||
|
||||
auto pkgs = FlatpakManager::parseInstalledOutput(output);
|
||||
|
||||
assert(pkgs.size() == 4);
|
||||
// An empty version is a column, not a gap: dropping it shifted every field
|
||||
// after it, and the row said nothing about which copy it was.
|
||||
assert(pkgs[0].version.empty());
|
||||
assert(pkgs[0].repository == "hoptodesk-origin");
|
||||
// The target is "<installation>:<ref>": the two halves are what flatpak
|
||||
// needs to refuse the application id and name this copy instead.
|
||||
assert(pkgs[0].instances[0].target == "user:com.hoptodesk.HopToDesk/x86_64/master");
|
||||
assert(pkgs[1].instances[0].target == "user:com.hoptodesk.HopToDesk/x86_64/stable");
|
||||
assert(pkgs[2].instances[0].target == "system:com.usebottles.bottles/x86_64/stable");
|
||||
assert(pkgs[3].instances[0].target == "user:com.usebottles.bottles/x86_64/stable");
|
||||
|
||||
// A label says the installation, and the remote or branch when it is what
|
||||
// tells two copies of the same id apart.
|
||||
assert(pkgs[0].instances[0].label == "utilisateur · hoptodesk-origin · master");
|
||||
assert(pkgs[1].instances[0].label == "utilisateur");
|
||||
assert(pkgs[2].instances[0].label == "système");
|
||||
}
|
||||
|
||||
// A listing without the ref/branch/installation columns stays readable: the
|
||||
// row is the application, with no copy to choose between.
|
||||
static void testParseInstalledOutput_withoutInstallationColumns() {
|
||||
auto pkgs = FlatpakManager::parseInstalledOutput("org.gnome.Calculator\t47.0\tflathub\n");
|
||||
|
||||
assert(pkgs.size() == 1);
|
||||
assert(pkgs[0].name == "org.gnome.Calculator");
|
||||
assert(pkgs[0].instances.empty());
|
||||
}
|
||||
|
||||
// Once merged, a row must keep the copies of every row it absorbed: that is
|
||||
// what the chooser lists.
|
||||
static void testMergedRowKeepsEveryCopy() {
|
||||
std::vector<PackageInfo> rows = FlatpakManager::parseInstalledOutput(
|
||||
"com.usebottles.bottles\t67.3\tflathub\tcom.usebottles.bottles/x86_64/stable\tstable\tsystem\n"
|
||||
"com.usebottles.bottles\t67.3\tflathub\tcom.usebottles.bottles/x86_64/stable\tstable\tuser\n");
|
||||
|
||||
mergeProviderDuplicates(rows);
|
||||
|
||||
assert(rows.size() == 1);
|
||||
assert(rows[0].instances.size() == 2);
|
||||
assert(rows[0].instances[0].target == "system:com.usebottles.bottles/x86_64/stable");
|
||||
assert(rows[0].instances[1].target == "user:com.usebottles.bottles/x86_64/stable");
|
||||
}
|
||||
|
||||
static void testParseUpdatesOutput_parsesRows() {
|
||||
std::string output =
|
||||
"org.mozilla.firefox\t130.0\n"
|
||||
@@ -150,6 +206,40 @@ static void testInstallFileCommand_buildsTheFlatpakCalls() {
|
||||
assert(quoted.find("'/tmp/mon paquet.flatpak'") != std::string::npos);
|
||||
}
|
||||
|
||||
// Naming one copy is what makes the call unambiguous: the ref alone picks the
|
||||
// remote and the branch, the scope picks the installation.
|
||||
static void testUninstallAndUpdateCommands_targetOneCopy() {
|
||||
const std::string userCopy =
|
||||
FlatpakManager::uninstallCommand("user:com.example.App/x86_64/stable");
|
||||
assert(userCopy.find("flatpak uninstall") == 0);
|
||||
assert(userCopy.find("--user") != std::string::npos);
|
||||
assert(userCopy.find("com.example.App/x86_64/stable") != std::string::npos);
|
||||
// The application's own id must not be in there any more: that is exactly
|
||||
// what flatpak refuses when several copies exist.
|
||||
assert(userCopy.find("--assumeyes com.example.App ") == std::string::npos);
|
||||
|
||||
const std::string systemCopy =
|
||||
FlatpakManager::uninstallCommand("system:com.example.App/x86_64/stable");
|
||||
assert(systemCopy.find("flatpak uninstall") == 0);
|
||||
assert(systemCopy.find("--user") == std::string::npos);
|
||||
assert(systemCopy.find("com.example.App/x86_64/stable") != std::string::npos);
|
||||
|
||||
const std::string update = FlatpakManager::updateCommand("user:com.example.App/x86_64/stable");
|
||||
assert(update.find("flatpak update") == 0);
|
||||
assert(update.find("--user") != std::string::npos);
|
||||
assert(update.find("com.example.App/x86_64/stable") != std::string::npos);
|
||||
}
|
||||
|
||||
// A plain application id keeps working as it always did — the provider only
|
||||
// needs the target when the id is ambiguous, and finds out by trying.
|
||||
static void testUninstallCommand_stillAcceptsAnApplicationId() {
|
||||
const std::string plain = FlatpakManager::uninstallCommand("com.example.App");
|
||||
|
||||
assert(plain.find("flatpak uninstall") == 0);
|
||||
assert(plain.find("com.example.App") != std::string::npos);
|
||||
assert(plain.find("--user") == std::string::npos);
|
||||
}
|
||||
|
||||
int main() {
|
||||
testParseSearchOutput_parsesAlignedRows();
|
||||
testParseSearchOutput_keepsMultiWordDescriptions();
|
||||
@@ -158,6 +248,9 @@ int main() {
|
||||
|
||||
testParseInstalledOutput_parsesTabSeparated();
|
||||
testParseInstalledOutput_emptyInput();
|
||||
testParseInstalledOutput_namesEveryInstallation();
|
||||
testParseInstalledOutput_withoutInstallationColumns();
|
||||
testMergedRowKeepsEveryCopy();
|
||||
|
||||
testParseUpdatesOutput_parsesRows();
|
||||
testParseUpdatesOutput_emptyInput();
|
||||
@@ -165,6 +258,8 @@ int main() {
|
||||
testClassifyFile_recognisesTheThreeFlatpakFormats();
|
||||
testRepoName_comesFromTheFileName();
|
||||
testInstallFileCommand_buildsTheFlatpakCalls();
|
||||
testUninstallAndUpdateCommands_targetOneCopy();
|
||||
testUninstallCommand_stillAcceptsAnApplicationId();
|
||||
|
||||
std::cout << "All flatpak-manager tests passed." << std::endl;
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user