if db is locked, wait for pacman if running else remove the lock

This commit is contained in:
guinux 2016-08-27 16:24:46 +02:00
parent da52dc8953
commit 6bb6de02a7
4 changed files with 50 additions and 12 deletions

View File

@ -176,6 +176,10 @@ msgstr ""
msgid "Transaction cancelled"
msgstr ""
#: ../src/transaction.vala
msgid "Waiting for another package manager to quit"
msgstr ""
#: ../src/transaction.vala
msgid "Checking dependencies"
msgstr ""

View File

@ -194,12 +194,33 @@ namespace Pamac {
if (!lockfile.query_exists ()) {
extern_lock = false;
refresh_handle ();
databases_lock_mutex.unlock ();
}
} else {
if (lockfile.query_exists ()) {
if (databases_lock_mutex.trylock ()) {
extern_lock = true;
databases_lock_mutex.unlock ();
// Functions trans_prepare, sysupgrade_prepare and refresh threads are blocked until unlock.
// An extern lock appears, check if pacman running.
int exit_status;
try {
Process.spawn_command_line_sync ("pidof pacman",
null,
null,
out exit_status);
} catch (SpawnError e) {
stderr.printf ("Error: %s\n", e.message);
}
if (exit_status == 0) {
extern_lock = true;
} else {
// Pacman is not running: remove the unneeded lock file.
try {
lockfile.delete ();
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
databases_lock_mutex.unlock ();
}
}
}
}
@ -313,14 +334,9 @@ namespace Pamac {
commands += "-u";
}
try {
var process = new Subprocess.newv (
new Subprocess.newv (
commands,
SubprocessFlags.STDOUT_PIPE | SubprocessFlags.STDERR_MERGE);
var dis = new DataInputStream (process.get_stdout_pipe ());
string? line;
while ((line = dis.read_line ()) != null) {
print ("%s\n",line);
}
SubprocessFlags.STDOUT_SILENCE | SubprocessFlags.STDERR_SILENCE);
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
@ -359,7 +375,11 @@ namespace Pamac {
}
private void refresh () {
databases_lock_mutex.lock ();
if (!databases_lock_mutex.trylock ()) {
// Wait for pacman to finish
emit_event (0, 0, {});
databases_lock_mutex.lock ();
}
write_log_file ("synchronizing package lists");
current_error = ErrorInfos ();
int force = (force_refresh) ? 1 : 0;
@ -1292,7 +1312,11 @@ namespace Pamac {
}
private bool trans_init (Alpm.TransFlag flags) {
databases_lock_mutex.lock ();
if (!databases_lock_mutex.trylock ()) {
// Wait for pacman to finish
emit_event (0, 0, {});
databases_lock_mutex.lock ();
}
current_error = ErrorInfos ();
cancellable.reset ();
if (alpm_handle.trans_init (flags) == -1) {

View File

@ -722,6 +722,7 @@ namespace Pamac {
sysupgrade_simple (enable_downgrade);
} else {
finish_transaction ();
stop_progressbar_pulse ();
}
}
}
@ -988,6 +989,10 @@ namespace Pamac {
string? action = null;
string? detailed_action = null;
switch (primary_event) {
case 0: //special case: wait for database lock
action = dgettext (null, "Waiting for another package manager to quit") + "...";
start_progressbar_pulse ();
break;
case 1: //Alpm.Event.Type.CHECKDEPS_START
action = dgettext (null, "Checking dependencies") + "...";
break;
@ -1375,6 +1380,7 @@ namespace Pamac {
}
void on_refresh_finished (bool success) {
stop_progressbar_pulse ();
this.success = success;
clear_lists ();
if (success) {
@ -1389,6 +1395,7 @@ namespace Pamac {
}
void on_trans_prepare_finished (bool success) {
stop_progressbar_pulse ();
this.success = success;
if (success) {
show_warnings ();

View File

@ -98,7 +98,10 @@ namespace Pamac {
stack.add_named (transaction.term_grid, "term");
transaction_infobox.pack_start (transaction.progress_box);
on_refresh_button_clicked ();
Timeout.add (500, () => {
on_refresh_button_clicked ();
return false;
});
stack.notify["visible-child"].connect (on_stack_visible_child_changed);