forked from cromer/pamac-classic
improve code to ensure to not leave with locked databases
This commit is contained in:
parent
aea37c9ea7
commit
1058576cce
@ -43,13 +43,20 @@ pamac-refresh: refresh.vala
|
||||
--pkg=gio-2.0 \
|
||||
refresh.vala
|
||||
|
||||
pamac-tray: common.vala pamac_config.vala tray.vala
|
||||
pamac-tray: ../util/alpm-util.c common.vala alpm_config.vala pamac_config.vala tray.vala
|
||||
valac -o pamac-tray \
|
||||
--pkg=posix \
|
||||
--pkg=libalpm \
|
||||
--pkg=gio-2.0 \
|
||||
--pkg=gtk+-3.0 \
|
||||
--pkg=libnotify \
|
||||
--vapidir=../vapi \
|
||||
--Xcc=-I../util \
|
||||
-X -D_FILE_OFFSET_BITS=64 \
|
||||
-X -DGETTEXT_PACKAGE="pamac" \
|
||||
../util/alpm-util.c \
|
||||
common.vala \
|
||||
alpm_config.vala \
|
||||
pamac_config.vala \
|
||||
tray.vala
|
||||
|
||||
|
@ -39,6 +39,7 @@ namespace Pamac {
|
||||
private Json.Array aur_updates_results;
|
||||
private bool intern_lock;
|
||||
private bool extern_lock;
|
||||
private GLib.File lockfile;
|
||||
|
||||
public signal void emit_event (uint primary_event, uint secondary_event, string[] details);
|
||||
public signal void emit_providers (string depend, string[] providers);
|
||||
@ -64,8 +65,8 @@ namespace Pamac {
|
||||
aur_updates_results = new Json.Array ();
|
||||
intern_lock = false;
|
||||
extern_lock = false;
|
||||
Timeout.add (500, check_pacman_running);
|
||||
refresh_handle ();
|
||||
Timeout.add (500, check_pacman_running);
|
||||
}
|
||||
|
||||
private void refresh_handle () {
|
||||
@ -81,12 +82,12 @@ namespace Pamac {
|
||||
alpm_config.handle.dlcb = (DownloadCallBack) cb_download;
|
||||
alpm_config.handle.totaldlcb = (TotalDownloadCallBack) cb_totaldownload;
|
||||
alpm_config.handle.logcb = (LogCallBack) cb_log;
|
||||
lockfile = GLib.File.new_for_path (alpm_config.handle.lockfile);
|
||||
}
|
||||
previous_percent = 0;
|
||||
}
|
||||
|
||||
private bool check_pacman_running () {
|
||||
var lockfile = GLib.File.new_for_path ("/var/lib/pacman/db.lck");
|
||||
if (extern_lock) {
|
||||
if (lockfile.query_exists () == false) {
|
||||
extern_lock = false;
|
||||
@ -1066,8 +1067,6 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public void trans_cancel () {
|
||||
alpm_config.handle.trans_interrupt ();
|
||||
alpm_config.handle.trans_release ();
|
||||
// explicitly quit to avoid a crash
|
||||
// this daemon should be auto-restarted
|
||||
quit ();
|
||||
@ -1075,7 +1074,9 @@ namespace Pamac {
|
||||
|
||||
[DBus (no_reply = true)]
|
||||
public void quit () {
|
||||
GLib.File lockfile = GLib.File.new_for_path ("/var/lib/pacman/db.lck");
|
||||
// be sure to not quit with locked databases
|
||||
alpm_config.handle.trans_interrupt ();
|
||||
alpm_config.handle.trans_release ();
|
||||
if (lockfile.query_exists () == false) {
|
||||
loop.quit ();
|
||||
}
|
||||
|
@ -78,19 +78,18 @@ namespace Pamac {
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
run = app.get_is_remote ();
|
||||
if (run) {
|
||||
return run;
|
||||
} else {
|
||||
app = new Application ("org.manjaro.pamac.updater", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
return run;
|
||||
}
|
||||
app = new Application ("org.manjaro.pamac.updater", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
return run;
|
||||
}
|
||||
|
||||
public void on_emit_trans_finished (bool error) {
|
||||
|
@ -75,19 +75,18 @@ namespace Pamac {
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
run = app.get_is_remote ();
|
||||
if (run) {
|
||||
return run;
|
||||
} else {
|
||||
app = new Application ("org.manjaro.pamac.install", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
return run;
|
||||
}
|
||||
app = new Application ("org.manjaro.pamac.install", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
return run;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ namespace Pamac {
|
||||
uint refresh_timeout_id;
|
||||
Gtk.StatusIcon status_icon;
|
||||
Gtk.Menu menu;
|
||||
GLib.File lockfile;
|
||||
|
||||
public TrayIcon () {
|
||||
application_id = "org.manjaro.pamac.tray";
|
||||
@ -56,7 +57,7 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
void stop_daemon () {
|
||||
if (check_pamac_running () == false) {
|
||||
if (check_pamac_running () == false && lockfile.query_exists () == false) {
|
||||
try {
|
||||
daemon.quit ();
|
||||
} catch (IOError e) {
|
||||
@ -177,23 +178,31 @@ namespace Pamac {
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
if (run)
|
||||
return run;
|
||||
else {
|
||||
app = new Application ("org.manjaro.pamac.updater", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
run = app.get_is_remote ();
|
||||
if (run) {
|
||||
return run;
|
||||
}
|
||||
app = new Application ("org.manjaro.pamac.updater", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
if (run) {
|
||||
return run;
|
||||
}
|
||||
app = new Application ("org.manjaro.pamac.install", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
return run;
|
||||
}
|
||||
|
||||
bool check_pacman_running () {
|
||||
GLib.File lockfile = GLib.File.new_for_path ("/var/lib/pacman/db.lck");
|
||||
if (locked) {
|
||||
if (lockfile.query_exists () == false) {
|
||||
locked = false;
|
||||
@ -237,10 +246,12 @@ namespace Pamac {
|
||||
|
||||
Notify.init (_("Update Manager"));
|
||||
|
||||
var alpm_config = new Alpm.Config ("/etc/pacman.conf");
|
||||
lockfile = GLib.File.new_for_path (alpm_config.handle.lockfile);
|
||||
Timeout.add (500, check_pacman_running);
|
||||
refresh ();
|
||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||
launch_refresh_timeout ((uint) pamac_config.refresh_period);
|
||||
Timeout.add (500, check_pacman_running);
|
||||
|
||||
this.hold ();
|
||||
}
|
||||
|
@ -71,19 +71,18 @@ namespace Pamac {
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
run = app.get_is_remote ();
|
||||
if (run) {
|
||||
return run;
|
||||
} else {
|
||||
app = new Application ("org.manjaro.pamac.install", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
return run;
|
||||
}
|
||||
app = new Application ("org.manjaro.pamac.install", 0);
|
||||
try {
|
||||
app.register ();
|
||||
} catch (GLib.Error e) {
|
||||
stderr.printf ("%s\n", e.message);
|
||||
}
|
||||
run = app.get_is_remote ();
|
||||
return run;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user