Skip to content
Snippets Groups Projects
Commit 07511a99 authored by guinux's avatar guinux
Browse files

[cli] add reinstall action

parent b365baac
No related branches found
No related tags found
No related merge requests found
...@@ -181,6 +181,8 @@ namespace Pamac { ...@@ -181,6 +181,8 @@ namespace Pamac {
display_build_help (); display_build_help ();
} else if (args[2] == "install") { } else if (args[2] == "install") {
display_install_help (); display_install_help ();
} else if (args[2] == "reinstall") {
display_reinstall_help ();
} else if (args[2] == "remove") { } else if (args[2] == "remove") {
display_remove_help (); display_remove_help ();
} else if (args[2] == "checkupdates") { } else if (args[2] == "checkupdates") {
...@@ -305,6 +307,16 @@ namespace Pamac { ...@@ -305,6 +307,16 @@ namespace Pamac {
} else { } else {
display_install_help (); display_install_help ();
} }
} else if (args[1] == "reinstall") {
if (args.length > 2) {
if (args[2] == "--help" || args[2] == "-h") {
display_reinstall_help ();
} else {
reinstall_pkgs (args[2:args.length]);
}
} else {
display_reinstall_help ();
}
} else if (args[1] == "remove") { } else if (args[1] == "remove") {
if (args.length > 2) { if (args.length > 2) {
if (args[2] == "--help" || args[2] == "-h") { if (args[2] == "--help" || args[2] == "-h") {
...@@ -690,7 +702,7 @@ namespace Pamac { ...@@ -690,7 +702,7 @@ namespace Pamac {
void display_install_help () { void display_install_help () {
stdout.printf (dgettext (null, "Install packages from the repositories")); stdout.printf (dgettext (null, "Install packages from the repositories"));
stdout.printf ("\n\n"); stdout.printf ("\n\n");
stdout.printf ("pamac install [%s] <%s>".printf (dgettext (null, "options"), dgettext (null, "package(s)"))); stdout.printf ("pamac install [%s] <%s>".printf (dgettext (null, "options"), "%s,%s".printf (dgettext (null, "package(s)"), dgettext (null, "group(s)"))));
stdout.printf ("\n\n"); stdout.printf ("\n\n");
stdout.printf (dgettext (null, "options") + ":\n"); stdout.printf (dgettext (null, "options") + ":\n");
int max_length = 25; int max_length = 25;
...@@ -703,10 +715,17 @@ namespace Pamac { ...@@ -703,10 +715,17 @@ namespace Pamac {
} }
} }
void display_reinstall_help () {
stdout.printf (dgettext (null, "Reinstall packages from the repositories"));
stdout.printf ("\n\n");
stdout.printf ("pamac reinstall <%s>".printf ("%s,%s".printf (dgettext (null, "package(s)"), dgettext (null, "group(s)"))));
stdout.printf ("\n\n");
}
void display_remove_help () { void display_remove_help () {
stdout.printf (dgettext (null, "Remove packages")); stdout.printf (dgettext (null, "Remove packages"));
stdout.printf ("\n\n"); stdout.printf ("\n\n");
stdout.printf ("pamac remove [%s] [%s]".printf (dgettext (null, "options"), dgettext (null, "package(s)"))); stdout.printf ("pamac remove [%s] [%s]".printf (dgettext (null, "options"), "%s,%s".printf (dgettext (null, "package(s)"), dgettext (null, "group(s)"))));
stdout.printf ("\n\n"); stdout.printf ("\n\n");
stdout.printf (dgettext (null, "options") + ":\n"); stdout.printf (dgettext (null, "options") + ":\n");
int max_length = 15; int max_length = 15;
...@@ -1394,7 +1413,7 @@ namespace Pamac { ...@@ -1394,7 +1413,7 @@ namespace Pamac {
try { try {
var pkgs = user_daemon.get_group_pkgs_sync (name); var pkgs = user_daemon.get_group_pkgs_sync (name);
if (pkgs.length == 0) { if (pkgs.length == 0) {
print_error (dgettext (null, "target not found: %s").printf (name) + "\n"); print_error (dgettext (null, "target not found: %s").printf (name));
} else { } else {
print_pkgs (pkgs, true); print_pkgs (pkgs, true);
} }
...@@ -1421,7 +1440,7 @@ namespace Pamac { ...@@ -1421,7 +1440,7 @@ namespace Pamac {
try { try {
var pkgs = user_daemon.get_repo_pkgs_sync (name); var pkgs = user_daemon.get_repo_pkgs_sync (name);
if (pkgs.length == 0) { if (pkgs.length == 0) {
print_error (dgettext (null, "target not found: %s").printf (name) + "\n"); print_error (dgettext (null, "target not found: %s").printf (name));
} else { } else {
print_pkgs (pkgs, true); print_pkgs (pkgs, true);
} }
...@@ -1437,7 +1456,7 @@ namespace Pamac { ...@@ -1437,7 +1456,7 @@ namespace Pamac {
try { try {
string[] files = user_daemon.get_pkg_files (name); string[] files = user_daemon.get_pkg_files (name);
if (files.length == 0) { if (files.length == 0) {
print_error (dgettext (null, "target not found: %s").printf (name) + "\n"); print_error (dgettext (null, "target not found: %s").printf (name));
} else { } else {
foreach (unowned string path in files) { foreach (unowned string path in files) {
stdout.printf ("%s\n", path); stdout.printf ("%s\n", path);
...@@ -1562,6 +1581,7 @@ namespace Pamac { ...@@ -1562,6 +1581,7 @@ namespace Pamac {
void install_pkgs (string[] targets) { void install_pkgs (string[] targets) {
try { try {
foreach (unowned string target in targets) { foreach (unowned string target in targets) {
bool found = false;
// check for local or remote path // check for local or remote path
if (".pkg.tar" in target) { if (".pkg.tar" in target) {
if ("://" in target) { if ("://" in target) {
...@@ -1571,13 +1591,12 @@ namespace Pamac { ...@@ -1571,13 +1591,12 @@ namespace Pamac {
string? absolute_path = file.get_path (); string? absolute_path = file.get_path ();
if (absolute_path != null) { if (absolute_path != null) {
to_load += absolute_path; to_load += absolute_path;
} else { found = true;
print_error (dgettext (null, "target not found: %s").printf (target) + "\n");
return;
} }
} else { } else {
// add url in to_load, pkg will be donwload by system_daemon // add url in to_load, pkg will be downloaded by system_daemon
to_load += target; to_load += target;
found = true;
} }
} else { } else {
// handle local or absolute path // handle local or absolute path
...@@ -1585,33 +1604,36 @@ namespace Pamac { ...@@ -1585,33 +1604,36 @@ namespace Pamac {
string? absolute_path = file.get_path (); string? absolute_path = file.get_path ();
if (absolute_path != null) { if (absolute_path != null) {
to_load += absolute_path; to_load += absolute_path;
} else { found = true;
print_error (dgettext (null, "target not found: %s").printf (target) + "\n");
return;
} }
} }
} else { } else {
var pkg = user_daemon.find_sync_satisfier (target); var pkg = user_daemon.find_sync_satisfier (target);
if (pkg.name != "") { if (pkg.name != "") {
to_install += target; to_install += target;
found = true;
} else { } else {
string[] groupnames = user_daemon.get_groups_names (); string[] groupnames = user_daemon.get_groups_names ();
if (target in groupnames) { if (target in groupnames) {
ask_group_confirmation (target); ask_group_confirmation (target);
} else { found = true;
print_error (dgettext (null, "target not found: %s").printf (target) + "\n");
return;
} }
} }
} }
if (!found) {
print_error (dgettext (null, "target not found: %s").printf (target));
return;
}
} }
} catch (Error e) { } catch (Error e) {
print_error (e.message); print_error (e.message);
} }
if (to_install.length == 0 && to_load.length == 0) { if (to_install.length == 0 && to_load.length == 0) {
// nothing to do stdout.printf (dgettext (null, "Nothing to do") + ".\n");
return; return;
} }
// do not install a package if it is already installed and up to date
transflags = (1 << 13); //Alpm.TransFlag.NEEDED
stdout.printf (dgettext (null, "Preparing") + "...\n"); stdout.printf (dgettext (null, "Preparing") + "...\n");
this.hold (); this.hold ();
start_trans_prepare (); start_trans_prepare ();
...@@ -1710,6 +1732,54 @@ namespace Pamac { ...@@ -1710,6 +1732,54 @@ namespace Pamac {
} }
} }
void reinstall_pkgs (string[] names) {
try {
foreach (unowned string name in names) {
bool found = false;
string version = "";
var local_pkg = user_daemon.get_installed_pkg (name);
if (local_pkg.name != "") {
version = local_pkg.version;
var sync_pkg = user_daemon.get_sync_pkg (name);
if (sync_pkg.name != "") {
if (local_pkg.version == sync_pkg.version) {
to_install += name;
found = true;
}
}
} else {
string[] groupnames = user_daemon.get_groups_names ();
if (name in groupnames) {
found = true;
var pkgs = user_daemon.get_group_pkgs_sync (name);
foreach (unowned AlpmPackage pkg in pkgs) {
if (pkg.version == pkg.installed_version) {
to_install += name;
}
}
}
}
if (!found) {
if (version == "") {
print_error (dgettext (null, "target not found: %s").printf (name));
} else {
print_error (dgettext (null, "target not found: %s").printf (name + "-" + version));
}
return;
}
}
} catch (Error e) {
print_error (e.message);
}
if (to_install.length == 0 && to_load.length == 0) {
stdout.printf (dgettext (null, "Nothing to do") + ".\n");
return;
}
stdout.printf (dgettext (null, "Preparing") + "...\n");
this.hold ();
start_trans_prepare ();
}
void remove_pkgs (string[] names, bool recurse = false) { void remove_pkgs (string[] names, bool recurse = false) {
stdout.printf (dgettext (null, "Preparing") + "...\n"); stdout.printf (dgettext (null, "Preparing") + "...\n");
to_remove = names; to_remove = names;
......
...@@ -808,9 +808,9 @@ namespace Pamac { ...@@ -808,9 +808,9 @@ namespace Pamac {
details.packagebase = (owned) packagebase; details.packagebase = (owned) packagebase;
details.url = (owned) url; details.url = (owned) url;
details.maintainer = (owned) maintainer ; details.maintainer = (owned) maintainer ;
details.firstsubmitted = firstsubmitted; details.firstsubmitted = (owned) firstsubmitted;
details.lastmodified = lastmodified; details.lastmodified = (owned) lastmodified;
details.outofdate = outofdate; details.outofdate = (owned) outofdate;
details.numvotes = numvotes; details.numvotes = numvotes;
details.licenses = (owned) licenses; details.licenses = (owned) licenses;
details.depends = (owned) depends; details.depends = (owned) depends;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment