fix possible conflict between tray and updater

This commit is contained in:
guinux 2015-02-01 18:01:03 +01:00
parent 80d588b5e4
commit ef579ecfa5
2 changed files with 76 additions and 65 deletions

View File

@ -29,13 +29,12 @@ MainLoop loop;
namespace Pamac { namespace Pamac {
[DBus (name = "org.manjaro.pamac")] [DBus (name = "org.manjaro.pamac")]
public class Daemon : Object { public class Daemon : Object {
Alpm.Config alpm_config; private Alpm.Config alpm_config;
public uint64 previous_percent; public uint64 previous_percent;
int force_refresh;
bool emit_refreshed_signal;
public Cond provider_cond; public Cond provider_cond;
public Mutex provider_mutex; public Mutex provider_mutex;
public int? choosen_provider; public int? choosen_provider;
private Mutex databases_lock_mutex;
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);
@ -52,6 +51,7 @@ namespace Pamac {
public Daemon () { public Daemon () {
alpm_config = new Alpm.Config ("/etc/pacman.conf"); alpm_config = new Alpm.Config ("/etc/pacman.conf");
databases_lock_mutex = Mutex ();
} }
private void refresh_handle () { private void refresh_handle () {
@ -206,22 +206,26 @@ namespace Pamac {
if (result.get_is_authorized ()) { if (result.get_is_authorized ()) {
refresh_handle (); refresh_handle ();
unowned Package? pkg = alpm_config.handle.localdb.get_pkg (pkgname); unowned Package? pkg = alpm_config.handle.localdb.get_pkg (pkgname);
if (pkg != null) if (pkg != null) {
pkg.reason = (Package.Reason) reason; pkg.reason = (Package.Reason) reason;
} }
}
} catch (GLib.Error e) { } catch (GLib.Error e) {
stderr.printf ("%s\n", e.message); stderr.printf ("%s\n", e.message);
} }
} }
private int refresh_real () { public void refresh (int force, bool emit_signal) {
refresh_handle (); try {
new Thread<int>.try ("refresh thread", () => {
databases_lock_mutex.lock ();
ErrorInfos err = ErrorInfos (); ErrorInfos err = ErrorInfos ();
string[] details = {}; string[] details = {};
int success = 0; int success = 0;
int ret; int ret;
refresh_handle ();
foreach (var db in alpm_config.handle.syncdbs) { foreach (var db in alpm_config.handle.syncdbs) {
ret = db.update (force_refresh); ret = db.update (force);
if (ret >= 0) { if (ret >= 0) {
success++; success++;
} }
@ -233,16 +237,13 @@ namespace Pamac {
details += Alpm.strerror (alpm_config.handle.errno ()); details += Alpm.strerror (alpm_config.handle.errno ());
err.details = details; err.details = details;
} }
if (emit_refreshed_signal) if (emit_signal) {
emit_refreshed (err); emit_refreshed (err);
return success;
} }
print("done\n");
public void refresh (int force, bool emit_signal) { databases_lock_mutex.unlock ();
force_refresh = force; return success;
emit_refreshed_signal = emit_signal; });
try {
new Thread<int>.try ("refresh thread", (ThreadFunc) refresh_real);
} catch (GLib.Error e) { } catch (GLib.Error e) {
stderr.printf ("%s\n", e.message); stderr.printf ("%s\n", e.message);
} }
@ -259,9 +260,10 @@ namespace Pamac {
updates = get_repos_updates (alpm_config.handle); updates = get_repos_updates (alpm_config.handle);
if (pamac_config.enable_aur) { if (pamac_config.enable_aur) {
UpdatesInfos[] aur_updates = get_aur_updates (alpm_config.handle); UpdatesInfos[] aur_updates = get_aur_updates (alpm_config.handle);
foreach (var infos in aur_updates) foreach (var infos in aur_updates) {
updates += infos; updates += infos;
} }
}
return updates; return updates;
} }
} }
@ -297,10 +299,10 @@ namespace Pamac {
int ret = alpm_config.handle.trans_add_pkg (pkg); int ret = alpm_config.handle.trans_add_pkg (pkg);
if (ret == -1) { if (ret == -1) {
Alpm.Errno errno = alpm_config.handle.errno (); Alpm.Errno errno = alpm_config.handle.errno ();
if (errno == Errno.TRANS_DUP_TARGET || errno == Errno.PKG_IGNORED) if (errno == Errno.TRANS_DUP_TARGET || errno == Errno.PKG_IGNORED) {
// just skip duplicate or ignored targets // just skip duplicate or ignored targets
return err; return err;
else { } else {
err.str = _("Failed to prepare transaction"); err.str = _("Failed to prepare transaction");
details += "%s: %s".printf (pkg.name, Alpm.strerror (errno)); details += "%s: %s".printf (pkg.name, Alpm.strerror (errno));
err.details = details; err.details = details;
@ -344,7 +346,6 @@ namespace Pamac {
// add the same module for other installed kernels // add the same module for other installed kernels
foreach (var installed_kernel in installed_kernels) { foreach (var installed_kernel in installed_kernels) {
string module = installed_kernel + "-" + splitted[1]; string module = installed_kernel + "-" + splitted[1];
stdout.printf("%s: adding module %s\n", installed_kernel, module);
unowned Package? module_pkg = alpm_config.handle.find_dbs_satisfier (alpm_config.handle.syncdbs, module); unowned Package? module_pkg = alpm_config.handle.find_dbs_satisfier (alpm_config.handle.syncdbs, module);
if (module_pkg != null) { if (module_pkg != null) {
trans_add_pkg_real (module_pkg); trans_add_pkg_real (module_pkg);
@ -380,10 +381,10 @@ namespace Pamac {
int ret = alpm_config.handle.trans_add_pkg (pkg); int ret = alpm_config.handle.trans_add_pkg (pkg);
if (ret == -1) { if (ret == -1) {
Alpm.Errno errno = alpm_config.handle.errno (); Alpm.Errno errno = alpm_config.handle.errno ();
if (errno == Errno.TRANS_DUP_TARGET || errno == Errno.PKG_IGNORED) if (errno == Errno.TRANS_DUP_TARGET || errno == Errno.PKG_IGNORED) {
// just skip duplicate or ignored targets // just skip duplicate or ignored targets
return err; return err;
else { } else {
err.str = _("Failed to prepare transaction"); err.str = _("Failed to prepare transaction");
details += "%s: %s".printf (pkg->name, Alpm.strerror (errno)); details += "%s: %s".printf (pkg->name, Alpm.strerror (errno));
err.details = details; err.details = details;
@ -416,6 +417,7 @@ namespace Pamac {
} }
private int trans_prepare_real () { private int trans_prepare_real () {
databases_lock_mutex.lock ();
ErrorInfos err = ErrorInfos (); ErrorInfos err = ErrorInfos ();
string[] details = {}; string[] details = {};
Alpm.List<void*> err_data = null; Alpm.List<void*> err_data = null;
@ -481,6 +483,7 @@ namespace Pamac {
} }
} }
emit_trans_prepared (err); emit_trans_prepared (err);
databases_lock_mutex.unlock ();
return ret; return ret;
} }
@ -506,10 +509,11 @@ namespace Pamac {
info.name = pkg.name; info.name = pkg.name;
info.version = pkg.version; info.version = pkg.version;
// if pkg was load from a file, pkg.db is null // if pkg was load from a file, pkg.db is null
if (pkg.db != null) if (pkg.db != null) {
info.db_name = pkg.db.name; info.db_name = pkg.db.name;
else } else {
info.db_name = ""; info.db_name = "";
}
info.tarpath = ""; info.tarpath = "";
info.download_size = pkg.download_size; info.download_size = pkg.download_size;
infos += info; infos += info;
@ -532,6 +536,7 @@ namespace Pamac {
} }
private int trans_commit_real () { private int trans_commit_real () {
databases_lock_mutex.lock ();
ErrorInfos err = ErrorInfos (); ErrorInfos err = ErrorInfos ();
string[] details = {}; string[] details = {};
Alpm.List<void*> err_data = null; Alpm.List<void*> err_data = null;
@ -581,6 +586,7 @@ namespace Pamac {
} }
trans_release (); trans_release ();
emit_trans_committed (err); emit_trans_committed (err);
databases_lock_mutex.unlock ();
return ret; return ret;
} }
@ -631,9 +637,10 @@ 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"); GLib.File lockfile = GLib.File.new_for_path ("/var/lib/pacman/db.lck");
if (lockfile.query_exists () == false) if (lockfile.query_exists () == false) {
loop.quit (); loop.quit ();
} }
}
// End of Daemon Object // End of Daemon Object
} }
} }
@ -784,12 +791,13 @@ private void cb_question (Question.Data data) {
data.corrupted_remove = 1; data.corrupted_remove = 1;
break; break;
case Question.Type.IMPORT_KEY: case Question.Type.IMPORT_KEY:
if (data.import_key_key.revoked == 1) {
// Do not get revoked key // Do not get revoked key
if (data.import_key_key.revoked == 1)
data.import_key_import = 0; data.import_key_import = 0;
} else {
// Auto get not revoked key // Auto get not revoked key
else
data.import_key_import = 1; data.import_key_import = 1;
}
break; break;
default: default:
data.any_answer = 0; data.any_answer = 0;

View File

@ -29,8 +29,8 @@ namespace Pamac {
public interface Daemon : Object { public interface Daemon : Object {
public abstract void refresh (int force, bool emit_signal) throws IOError; public abstract void refresh (int force, bool emit_signal) throws IOError;
public abstract UpdatesInfos[] get_updates () throws IOError; public abstract UpdatesInfos[] get_updates () throws IOError;
//~ [DBus (no_reply = true)] [DBus (no_reply = true)]
//~ public abstract void quit () throws IOError; public abstract void quit () throws IOError;
} }
public class TrayIcon: Gtk.Application { public class TrayIcon: Gtk.Application {
@ -56,13 +56,15 @@ namespace Pamac {
} }
} }
//~ void stop_daemon () { void stop_daemon () {
//~ try { if (check_pamac_running () == false) {
//~ daemon.quit (); try {
//~ } catch (IOError e) { daemon.quit ();
//~ stderr.printf ("IOError: %s\n", e.message); } catch (IOError e) {
//~ } stderr.printf ("IOError: %s\n", e.message);
//~ } }
}
}
// Create menu for right button // Create menu for right button
void create_menu () { void create_menu () {
@ -112,18 +114,19 @@ namespace Pamac {
} }
bool refresh () { bool refresh () {
if (check_pamac_running () == false) {
start_daemon (); start_daemon ();
try { try {
daemon.refresh (0, false); daemon.refresh (0, false);
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
} }
}
return true; return true;
} }
void check_updates () { void check_updates () {
UpdatesInfos[] updates = {}; UpdatesInfos[] updates = {};
bool pamac_run = check_pamac_running ();
try { try {
updates = daemon.get_updates (); updates = daemon.get_updates ();
} catch (IOError e) { } catch (IOError e) {
@ -135,11 +138,11 @@ namespace Pamac {
} else { } else {
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb); string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
this.update_icon (update_icon_name, info); this.update_icon (update_icon_name, info);
if (pamac_run == false) if (check_pamac_running () == false) {
show_notification (info); show_notification (info);
} }
//~ if (pamac_run == false) }
//~ stop_daemon (); stop_daemon ();
} }
void show_notification (string info) { void show_notification (string info) {
@ -201,7 +204,7 @@ namespace Pamac {
return true; return true;
} }
void launch_refresh_timeout (string? msg = null) { void launch_refresh_timeout () {
if (refresh_timeout_id != 0) { if (refresh_timeout_id != 0) {
pamac_config.reload (); pamac_config.reload ();
Source.remove (refresh_timeout_id); Source.remove (refresh_timeout_id);