some fixes

This commit is contained in:
guinux 2017-03-06 20:58:30 +01:00
parent 61981732bf
commit 9ac8dc81e6
4 changed files with 96 additions and 40 deletions

View File

@ -411,7 +411,6 @@ namespace Pamac {
unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (pkgname); unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (pkgname);
if (pkg != null) { if (pkg != null) {
pkg.reason = (Alpm.Package.Reason) reason; pkg.reason = (Alpm.Package.Reason) reason;
refresh_handle ();
} }
} }
set_pkgreason_finished (); set_pkgreason_finished ();
@ -419,18 +418,19 @@ namespace Pamac {
} }
private void refresh () { private void refresh () {
current_error = ErrorInfos ();
if (!databases_lock_mutex.trylock ()) { if (!databases_lock_mutex.trylock ()) {
// Wait for pacman to finish // Wait for pacman to finish
emit_event (0, 0, {}); emit_event (0, 0, {});
databases_lock_mutex.lock (); databases_lock_mutex.lock ();
} }
if (cancellable.is_cancelled ()) { if (cancellable.is_cancelled ()) {
databases_lock_mutex.unlock ();
cancellable.reset (); cancellable.reset ();
refresh_finished (true);
databases_lock_mutex.unlock ();
return; return;
} }
write_log_file ("synchronizing package lists"); write_log_file ("synchronizing package lists");
current_error = ErrorInfos ();
int force = (force_refresh) ? 1 : 0; int force = (force_refresh) ? 1 : 0;
uint success = 0; uint success = 0;
cancellable.reset (); cancellable.reset ();
@ -440,7 +440,8 @@ namespace Pamac {
while (syncdbs != null) { while (syncdbs != null) {
unowned Alpm.DB db = syncdbs.data; unowned Alpm.DB db = syncdbs.data;
if (cancellable.is_cancelled ()) { if (cancellable.is_cancelled ()) {
refresh_handle (); delete curl;
alpm_handle.dbext = ".db";
refresh_finished (false); refresh_finished (false);
databases_lock_mutex.unlock (); databases_lock_mutex.unlock ();
return; return;
@ -460,7 +461,7 @@ namespace Pamac {
syncdbs.next (); syncdbs.next ();
} }
delete curl; delete curl;
refresh_handle (); alpm_handle.dbext = ".db";
// We should always succeed if at least one DB was upgraded - we may possibly // We should always succeed if at least one DB was upgraded - we may possibly
// fail later with unresolved deps, but that should be rare, and would be expected // fail later with unresolved deps, but that should be rare, and would be expected
if (success == 0) { if (success == 0) {
@ -1488,17 +1489,17 @@ namespace Pamac {
} }
private bool trans_init (Alpm.TransFlag flags) { private bool trans_init (Alpm.TransFlag flags) {
current_error = ErrorInfos ();
if (!databases_lock_mutex.trylock ()) { if (!databases_lock_mutex.trylock ()) {
// Wait for pacman to finish // Wait for pacman to finish
emit_event (0, 0, {}); emit_event (0, 0, {});
databases_lock_mutex.lock (); databases_lock_mutex.lock ();
} }
if (cancellable.is_cancelled ()) { if (cancellable.is_cancelled ()) {
databases_lock_mutex.unlock ();
cancellable.reset (); cancellable.reset ();
databases_lock_mutex.unlock ();
return false; return false;
} }
current_error = ErrorInfos ();
cancellable.reset (); cancellable.reset ();
if (alpm_handle.trans_init (flags) == -1) { if (alpm_handle.trans_init (flags) == -1) {
Alpm.Errno errno = alpm_handle.errno (); Alpm.Errno errno = alpm_handle.errno ();
@ -1637,14 +1638,19 @@ namespace Pamac {
return false; return false;
} else if (alpm_handle.trans_add_pkg (pkg) == -1) { } else if (alpm_handle.trans_add_pkg (pkg) == -1) {
Alpm.Errno errno = alpm_handle.errno (); Alpm.Errno errno = alpm_handle.errno ();
current_error.errno = (uint) errno; if (errno == Alpm.Errno.TRANS_DUP_TARGET || errno == Alpm.Errno.PKG_IGNORED) {
current_error.message = _("Failed to prepare transaction"); // just skip duplicate or ignored targets
if (errno != 0) { return true;
current_error.details = { "%s: %s".printf (pkg->name, Alpm.strerror (errno)) }; } else {
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction");
if (errno != 0) {
current_error.details = { "%s: %s".printf (pkg->name, Alpm.strerror (errno)) };
}
// free the package because it will not be used
delete pkg;
return false;
} }
// free the package because it will not be used
delete pkg;
return false;
} }
return true; return true;
} }
@ -1658,12 +1664,17 @@ namespace Pamac {
return false; return false;
} else if (alpm_handle.trans_remove_pkg (pkg) == -1) { } else if (alpm_handle.trans_remove_pkg (pkg) == -1) {
Alpm.Errno errno = alpm_handle.errno (); Alpm.Errno errno = alpm_handle.errno ();
current_error.errno = (uint) errno; if (errno == Alpm.Errno.TRANS_DUP_TARGET) {
current_error.message = _("Failed to prepare transaction"); // just skip duplicate targets
if (errno != 0) { return true;
current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) }; } else {
current_error.errno = (uint) errno;
current_error.message = _("Failed to prepare transaction");
if (errno != 0) {
current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) };
}
return false;
} }
return false;
} }
return true; return true;
} }
@ -1824,7 +1835,7 @@ namespace Pamac {
alpm_handle.logcb = (Alpm.LogCallBack) cb_log; alpm_handle.logcb = (Alpm.LogCallBack) cb_log;
lockfile = GLib.File.new_for_path (alpm_handle.lockfile); lockfile = GLib.File.new_for_path (alpm_handle.lockfile);
// fake aur db // fake aur db
alpm_handle.register_syncdb ("aur", Alpm.Signature.Level.PACKAGE_OPTIONAL | Alpm.Signature.Level.DATABASE_OPTIONAL); alpm_handle.register_syncdb ("aur", 0);
// add to_build in to_install for the fake trans prpeapre // add to_build in to_install for the fake trans prpeapre
foreach (unowned string name in to_build) { foreach (unowned string name in to_build) {
to_install += name; to_install += name;
@ -2085,7 +2096,6 @@ namespace Pamac {
// cancel the download return an EXTERNAL_DOWNLOAD error // cancel the download return an EXTERNAL_DOWNLOAD error
if (errno == Alpm.Errno.EXTERNAL_DOWNLOAD && cancellable.is_cancelled ()) { if (errno == Alpm.Errno.EXTERNAL_DOWNLOAD && cancellable.is_cancelled ()) {
trans_release (); trans_release ();
refresh_handle ();
trans_commit_finished (false); trans_commit_finished (false);
return; return;
} }
@ -2136,20 +2146,14 @@ namespace Pamac {
success = false; success = false;
} }
trans_release (); trans_release ();
refresh_handle ();
bool need_refresh = false;
to_install_as_dep.foreach_remove ((pkgname, val) => { to_install_as_dep.foreach_remove ((pkgname, val) => {
unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (pkgname); unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (pkgname);
if (pkg != null) { if (pkg != null) {
pkg.reason = Alpm.Package.Reason.DEPEND; pkg.reason = Alpm.Package.Reason.DEPEND;
need_refresh = true;
return true; // remove current pkgname return true; // remove current pkgname
} }
return false; return false;
}); });
if (need_refresh) {
refresh_handle ();
}
trans_commit_finished (success); trans_commit_finished (success);
} }
@ -2167,7 +2171,6 @@ namespace Pamac {
message = _("Authentication failed") message = _("Authentication failed")
}; };
trans_release (); trans_release ();
refresh_handle ();
trans_commit_finished (false); trans_commit_finished (false);
} }
}); });

View File

@ -279,8 +279,12 @@ namespace Pamac {
transaction = new Transaction (this as Gtk.ApplicationWindow); transaction = new Transaction (this as Gtk.ApplicationWindow);
transaction.mode = Mode.MANAGER; transaction.mode = Mode.MANAGER;
transaction.start_transaction.connect (on_start_transaction); transaction.start_waiting.connect (on_start_waiting);
transaction.stop_waiting.connect (on_stop_waiting);
transaction.start_downloading.connect (on_start_downloading);
transaction.stop_downloading.connect (on_stop_downloading);
transaction.start_building.connect (on_start_building); transaction.start_building.connect (on_start_building);
transaction.stop_building.connect (on_stop_building);
transaction.important_details_outpout.connect (on_important_details_outpout); transaction.important_details_outpout.connect (on_important_details_outpout);
transaction.finished.connect (on_transaction_finished); transaction.finished.connect (on_transaction_finished);
transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished); transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
@ -1631,12 +1635,14 @@ namespace Pamac {
void on_apply_button_clicked () { void on_apply_button_clicked () {
transaction_running = true; transaction_running = true;
apply_button.sensitive = false; apply_button.sensitive = false;
cancel_button.sensitive = false;
transaction.run (); transaction.run ();
} }
[GtkCallback] [GtkCallback]
void on_cancel_button_clicked () { void on_cancel_button_clicked () {
if (transaction_running) { if (transaction_running || refreshing) {
transaction_running = false;
transaction.cancel (); transaction.cancel ();
} else { } else {
transaction.clear_lists (); transaction.clear_lists ();
@ -1665,7 +1671,19 @@ namespace Pamac {
transaction_infobox.show_all (); transaction_infobox.show_all ();
} }
void on_start_transaction () { void on_start_waiting () {
cancel_button.sensitive = true;
}
void on_stop_waiting () {
set_pendings_operations ();
}
void on_start_downloading () {
cancel_button.sensitive = true;
}
void on_stop_downloading () {
cancel_button.sensitive = false; cancel_button.sensitive = false;
} }
@ -1673,6 +1691,10 @@ namespace Pamac {
cancel_button.sensitive = true; cancel_button.sensitive = true;
} }
void on_stop_building () {
cancel_button.sensitive = false;
}
void on_important_details_outpout (bool must_show) { void on_important_details_outpout (bool must_show) {
if (must_show) { if (must_show) {
main_stack.visible_child_name = "term"; main_stack.visible_child_name = "term";

View File

@ -154,8 +154,12 @@ namespace Pamac {
//parent window //parent window
public Gtk.ApplicationWindow? application_window { get; private set; } public Gtk.ApplicationWindow? application_window { get; private set; }
public signal void start_transaction (); public signal void start_waiting ();
public signal void stop_waiting ();
public signal void start_downloading ();
public signal void stop_downloading ();
public signal void start_building (); public signal void start_building ();
public signal void stop_building ();
public signal void important_details_outpout (bool must_show); public signal void important_details_outpout (bool must_show);
public signal void alpm_handle_refreshed (); public signal void alpm_handle_refreshed ();
public signal void finished (bool success); public signal void finished (bool success);
@ -395,11 +399,13 @@ namespace Pamac {
void reset_progress_box (string action) { void reset_progress_box (string action) {
show_in_term (action); show_in_term (action);
progress_box.action_label.label = action; progress_box.action_label.label = action;
stop_progressbar_pulse ();
progress_box.progressbar.fraction = 0; progress_box.progressbar.fraction = 0;
progress_box.progressbar.text = ""; progress_box.progressbar.text = "";
} }
void start_progressbar_pulse () { void start_progressbar_pulse () {
stop_progressbar_pulse ();
pulse_timeout_id = Timeout.add (500, (GLib.SourceFunc) progress_box.progressbar.pulse); pulse_timeout_id = Timeout.add (500, (GLib.SourceFunc) progress_box.progressbar.pulse);
} }
@ -1062,7 +1068,7 @@ namespace Pamac {
out status); out status);
if (status == 0) { if (status == 0) {
foreach (unowned string path in standard_output.split ("\n")) { foreach (unowned string path in standard_output.split ("\n")) {
if (path != "") { if (path != "" && !(path in built_pkgs)) {
built_pkgs += path; built_pkgs += path;
} }
} }
@ -1074,6 +1080,7 @@ namespace Pamac {
} }
} }
} }
stop_building ();
} }
} else { } else {
status = 1; status = 1;
@ -1107,6 +1114,9 @@ namespace Pamac {
} }
} }
show_in_term ("\n" + dgettext (null, "Transaction cancelled") + ".\n"); show_in_term ("\n" + dgettext (null, "Transaction cancelled") + ".\n");
progress_box.action_label.label = "";
stop_progressbar_pulse ();
stop_waiting ();
warning_textbuffer = new StringBuilder (); warning_textbuffer = new StringBuilder ();
} }
@ -1134,12 +1144,12 @@ namespace Pamac {
case 0: //special case: wait for database lock case 0: //special case: wait for database lock
action = dgettext (null, "Waiting for another package manager to quit") + "..."; action = dgettext (null, "Waiting for another package manager to quit") + "...";
start_progressbar_pulse (); start_progressbar_pulse ();
start_waiting ();
break; break;
case 1: //Alpm.Event.Type.CHECKDEPS_START case 1: //Alpm.Event.Type.CHECKDEPS_START
action = dgettext (null, "Checking dependencies") + "..."; action = dgettext (null, "Checking dependencies") + "...";
break; break;
case 3: //Alpm.Event.Type.FILECONFLICTS_START case 3: //Alpm.Event.Type.FILECONFLICTS_START
start_transaction ();
action = dgettext (null, "Checking file conflicts") + "..."; action = dgettext (null, "Checking file conflicts") + "...";
break; break;
case 5: //Alpm.Event.Type.RESOLVEDEPS_START case 5: //Alpm.Event.Type.RESOLVEDEPS_START
@ -1148,9 +1158,6 @@ namespace Pamac {
case 7: //Alpm.Event.Type.INTERCONFLICTS_START case 7: //Alpm.Event.Type.INTERCONFLICTS_START
action = dgettext (null, "Checking inter-conflicts") + "..."; action = dgettext (null, "Checking inter-conflicts") + "...";
break; break;
case 9: //Alpm.Event.Type.TRANSACTION_START
start_transaction ();
break;
case 11: //Alpm.Event.Type.PACKAGE_OPERATION_START case 11: //Alpm.Event.Type.PACKAGE_OPERATION_START
switch (secondary_event) { switch (secondary_event) {
// special case handle differently // special case handle differently
@ -1213,8 +1220,13 @@ namespace Pamac {
important_details_outpout (false); important_details_outpout (false);
break; break;
case 25: //Alpm.Event.Type.RETRIEVE_START case 25: //Alpm.Event.Type.RETRIEVE_START
start_downloading ();
action = dgettext (null, "Downloading") + "..."; action = dgettext (null, "Downloading") + "...";
break; break;
case 26: //Alpm.Event.Type.RETRIEVE_DONE
case 27: //Alpm.Event.Type.RETRIEVE_FAILED
stop_downloading ();
break;
case 28: //Alpm.Event.Type.PKGDOWNLOAD_START case 28: //Alpm.Event.Type.PKGDOWNLOAD_START
// special case handle differently // special case handle differently
show_in_term (dgettext (null, "Downloading %s").printf (details[0]) + "..."); show_in_term (dgettext (null, "Downloading %s").printf (details[0]) + "...");
@ -1248,7 +1260,6 @@ namespace Pamac {
case 41: //Alpm.Event.Type.HOOK_START case 41: //Alpm.Event.Type.HOOK_START
switch (secondary_event) { switch (secondary_event) {
case 1: //Alpm.HookWhen.PRE_TRANSACTION case 1: //Alpm.HookWhen.PRE_TRANSACTION
start_transaction ();
action = dgettext (null, "Running pre-transaction hooks") + "..."; action = dgettext (null, "Running pre-transaction hooks") + "...";
break; break;
case 2: //Alpm.HookWhen.POST_TRANSACTION case 2: //Alpm.HookWhen.POST_TRANSACTION

View File

@ -89,8 +89,12 @@ namespace Pamac {
transaction = new Transaction (this as Gtk.ApplicationWindow); transaction = new Transaction (this as Gtk.ApplicationWindow);
transaction.mode = Mode.UPDATER; transaction.mode = Mode.UPDATER;
transaction.start_transaction.connect (on_start_transaction); transaction.start_waiting.connect (on_start_waiting);
transaction.stop_waiting.connect (on_stop_waiting);
transaction.start_downloading.connect (on_start_downloading);
transaction.stop_downloading.connect (on_stop_downloading);
transaction.start_building.connect (on_start_building); transaction.start_building.connect (on_start_building);
transaction.stop_building.connect (on_stop_building);
transaction.important_details_outpout.connect (on_important_details_output); transaction.important_details_outpout.connect (on_important_details_output);
transaction.finished.connect (populate_updates_list); transaction.finished.connect (populate_updates_list);
transaction.get_updates_finished.connect (on_get_updates_finished); transaction.get_updates_finished.connect (on_get_updates_finished);
@ -262,7 +266,19 @@ namespace Pamac {
transaction.cancel (); transaction.cancel ();
} }
void on_start_transaction () { void on_start_waiting () {
cancel_button.sensitive = true;
}
void on_stop_waiting () {
populate_updates_list ();
}
void on_start_downloading () {
cancel_button.sensitive = true;
}
void on_stop_downloading () {
cancel_button.sensitive = false; cancel_button.sensitive = false;
} }
@ -270,6 +286,10 @@ namespace Pamac {
cancel_button.sensitive = true; cancel_button.sensitive = true;
} }
void on_stop_building () {
cancel_button.sensitive = false;
}
void on_important_details_output (bool must_show) { void on_important_details_output (bool must_show) {
if (must_show) { if (must_show) {
stackswitcher.visible = false; stackswitcher.visible = false;