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 \
|
--pkg=gio-2.0 \
|
||||||
refresh.vala
|
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 \
|
valac -o pamac-tray \
|
||||||
|
--pkg=posix \
|
||||||
|
--pkg=libalpm \
|
||||||
--pkg=gio-2.0 \
|
--pkg=gio-2.0 \
|
||||||
--pkg=gtk+-3.0 \
|
--pkg=gtk+-3.0 \
|
||||||
--pkg=libnotify \
|
--pkg=libnotify \
|
||||||
|
--vapidir=../vapi \
|
||||||
|
--Xcc=-I../util \
|
||||||
|
-X -D_FILE_OFFSET_BITS=64 \
|
||||||
-X -DGETTEXT_PACKAGE="pamac" \
|
-X -DGETTEXT_PACKAGE="pamac" \
|
||||||
|
../util/alpm-util.c \
|
||||||
common.vala \
|
common.vala \
|
||||||
|
alpm_config.vala \
|
||||||
pamac_config.vala \
|
pamac_config.vala \
|
||||||
tray.vala
|
tray.vala
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ namespace Pamac {
|
|||||||
private Json.Array aur_updates_results;
|
private Json.Array aur_updates_results;
|
||||||
private bool intern_lock;
|
private bool intern_lock;
|
||||||
private bool extern_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_event (uint primary_event, uint secondary_event, string[] details);
|
||||||
public signal void emit_providers (string depend, string[] providers);
|
public signal void emit_providers (string depend, string[] providers);
|
||||||
@ -64,8 +65,8 @@ namespace Pamac {
|
|||||||
aur_updates_results = new Json.Array ();
|
aur_updates_results = new Json.Array ();
|
||||||
intern_lock = false;
|
intern_lock = false;
|
||||||
extern_lock = false;
|
extern_lock = false;
|
||||||
Timeout.add (500, check_pacman_running);
|
|
||||||
refresh_handle ();
|
refresh_handle ();
|
||||||
|
Timeout.add (500, check_pacman_running);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh_handle () {
|
private void refresh_handle () {
|
||||||
@ -81,12 +82,12 @@ namespace Pamac {
|
|||||||
alpm_config.handle.dlcb = (DownloadCallBack) cb_download;
|
alpm_config.handle.dlcb = (DownloadCallBack) cb_download;
|
||||||
alpm_config.handle.totaldlcb = (TotalDownloadCallBack) cb_totaldownload;
|
alpm_config.handle.totaldlcb = (TotalDownloadCallBack) cb_totaldownload;
|
||||||
alpm_config.handle.logcb = (LogCallBack) cb_log;
|
alpm_config.handle.logcb = (LogCallBack) cb_log;
|
||||||
|
lockfile = GLib.File.new_for_path (alpm_config.handle.lockfile);
|
||||||
}
|
}
|
||||||
previous_percent = 0;
|
previous_percent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool check_pacman_running () {
|
private bool check_pacman_running () {
|
||||||
var lockfile = GLib.File.new_for_path ("/var/lib/pacman/db.lck");
|
|
||||||
if (extern_lock) {
|
if (extern_lock) {
|
||||||
if (lockfile.query_exists () == false) {
|
if (lockfile.query_exists () == false) {
|
||||||
extern_lock = false;
|
extern_lock = false;
|
||||||
@ -1066,8 +1067,6 @@ namespace Pamac {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void trans_cancel () {
|
public void trans_cancel () {
|
||||||
alpm_config.handle.trans_interrupt ();
|
|
||||||
alpm_config.handle.trans_release ();
|
|
||||||
// explicitly quit to avoid a crash
|
// explicitly quit to avoid a crash
|
||||||
// this daemon should be auto-restarted
|
// this daemon should be auto-restarted
|
||||||
quit ();
|
quit ();
|
||||||
@ -1075,7 +1074,9 @@ namespace Pamac {
|
|||||||
|
|
||||||
[DBus (no_reply = true)]
|
[DBus (no_reply = true)]
|
||||||
public void quit () {
|
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) {
|
if (lockfile.query_exists () == false) {
|
||||||
loop.quit ();
|
loop.quit ();
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ namespace Pamac {
|
|||||||
run = app.get_is_remote ();
|
run = app.get_is_remote ();
|
||||||
if (run) {
|
if (run) {
|
||||||
return run;
|
return run;
|
||||||
} else {
|
}
|
||||||
app = new Application ("org.manjaro.pamac.updater", 0);
|
app = new Application ("org.manjaro.pamac.updater", 0);
|
||||||
try {
|
try {
|
||||||
app.register ();
|
app.register ();
|
||||||
@ -91,7 +91,6 @@ namespace Pamac {
|
|||||||
run = app.get_is_remote ();
|
run = app.get_is_remote ();
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void on_emit_trans_finished (bool error) {
|
public void on_emit_trans_finished (bool error) {
|
||||||
transaction.stop_daemon ();
|
transaction.stop_daemon ();
|
||||||
|
@ -78,7 +78,7 @@ namespace Pamac {
|
|||||||
run = app.get_is_remote ();
|
run = app.get_is_remote ();
|
||||||
if (run) {
|
if (run) {
|
||||||
return run;
|
return run;
|
||||||
} else {
|
}
|
||||||
app = new Application ("org.manjaro.pamac.install", 0);
|
app = new Application ("org.manjaro.pamac.install", 0);
|
||||||
try {
|
try {
|
||||||
app.register ();
|
app.register ();
|
||||||
@ -89,7 +89,6 @@ namespace Pamac {
|
|||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static int main (string[] args) {
|
public static int main (string[] args) {
|
||||||
var manager = new Manager ();
|
var manager = new Manager ();
|
||||||
|
@ -40,6 +40,7 @@ namespace Pamac {
|
|||||||
uint refresh_timeout_id;
|
uint refresh_timeout_id;
|
||||||
Gtk.StatusIcon status_icon;
|
Gtk.StatusIcon status_icon;
|
||||||
Gtk.Menu menu;
|
Gtk.Menu menu;
|
||||||
|
GLib.File lockfile;
|
||||||
|
|
||||||
public TrayIcon () {
|
public TrayIcon () {
|
||||||
application_id = "org.manjaro.pamac.tray";
|
application_id = "org.manjaro.pamac.tray";
|
||||||
@ -56,7 +57,7 @@ namespace Pamac {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stop_daemon () {
|
void stop_daemon () {
|
||||||
if (check_pamac_running () == false) {
|
if (check_pamac_running () == false && lockfile.query_exists () == false) {
|
||||||
try {
|
try {
|
||||||
daemon.quit ();
|
daemon.quit ();
|
||||||
} catch (IOError e) {
|
} catch (IOError e) {
|
||||||
@ -178,9 +179,9 @@ namespace Pamac {
|
|||||||
stderr.printf ("%s\n", e.message);
|
stderr.printf ("%s\n", e.message);
|
||||||
}
|
}
|
||||||
run = app.get_is_remote ();
|
run = app.get_is_remote ();
|
||||||
if (run)
|
if (run) {
|
||||||
return run;
|
return run;
|
||||||
else {
|
}
|
||||||
app = new Application ("org.manjaro.pamac.updater", 0);
|
app = new Application ("org.manjaro.pamac.updater", 0);
|
||||||
try {
|
try {
|
||||||
app.register ();
|
app.register ();
|
||||||
@ -188,12 +189,20 @@ namespace Pamac {
|
|||||||
stderr.printf ("%s\n", e.message);
|
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.install", 0);
|
||||||
|
try {
|
||||||
|
app.register ();
|
||||||
|
} catch (GLib.Error e) {
|
||||||
|
stderr.printf ("%s\n", e.message);
|
||||||
|
}
|
||||||
|
run = app.get_is_remote ();
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool check_pacman_running () {
|
bool check_pacman_running () {
|
||||||
GLib.File lockfile = GLib.File.new_for_path ("/var/lib/pacman/db.lck");
|
|
||||||
if (locked) {
|
if (locked) {
|
||||||
if (lockfile.query_exists () == false) {
|
if (lockfile.query_exists () == false) {
|
||||||
locked = false;
|
locked = false;
|
||||||
@ -237,10 +246,12 @@ namespace Pamac {
|
|||||||
|
|
||||||
Notify.init (_("Update Manager"));
|
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 ();
|
refresh ();
|
||||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||||
launch_refresh_timeout ((uint) pamac_config.refresh_period);
|
launch_refresh_timeout ((uint) pamac_config.refresh_period);
|
||||||
Timeout.add (500, check_pacman_running);
|
|
||||||
|
|
||||||
this.hold ();
|
this.hold ();
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ namespace Pamac {
|
|||||||
run = app.get_is_remote ();
|
run = app.get_is_remote ();
|
||||||
if (run) {
|
if (run) {
|
||||||
return run;
|
return run;
|
||||||
} else {
|
}
|
||||||
app = new Application ("org.manjaro.pamac.install", 0);
|
app = new Application ("org.manjaro.pamac.install", 0);
|
||||||
try {
|
try {
|
||||||
app.register ();
|
app.register ();
|
||||||
@ -85,7 +85,6 @@ namespace Pamac {
|
|||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static int main (string[] args) {
|
public static int main (string[] args) {
|
||||||
var updater = new Updater ();
|
var updater = new Updater ();
|
||||||
|
Loading…
Reference in New Issue
Block a user