2014-10-22 13:44:02 -03:00
|
|
|
/*
|
|
|
|
* pamac-vala
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Guillaume Benoit <guillaume@manjaro.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a get of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using Alpm;
|
|
|
|
using Polkit;
|
|
|
|
|
|
|
|
// i18n
|
2014-10-26 08:30:04 -03:00
|
|
|
const string GETTEXT_PACKAGE = "pamac";
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
Pamac.Daemon pamac_daemon;
|
2014-10-22 13:44:02 -03:00
|
|
|
MainLoop loop;
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
namespace Pamac {
|
|
|
|
[DBus (name = "org.manjaro.pamac")]
|
|
|
|
public class Daemon : Object {
|
2014-12-03 12:02:14 -03:00
|
|
|
Alpm.Config alpm_config;
|
2014-10-30 10:44:09 -03:00
|
|
|
public uint64 previous_percent;
|
|
|
|
int force_refresh;
|
|
|
|
bool emit_refreshed_signal;
|
|
|
|
public Cond provider_cond;
|
|
|
|
public Mutex provider_mutex;
|
|
|
|
public int? choosen_provider;
|
|
|
|
|
2014-12-03 12:02:14 -03:00
|
|
|
public signal void emit_event (uint primary_event, uint secondary_event, string[] details);
|
2014-10-30 10:44:09 -03:00
|
|
|
public signal void emit_providers (string depend, string[] providers);
|
|
|
|
public signal void emit_progress (uint progress, string pkgname, int percent, uint n_targets, uint current_target);
|
|
|
|
public signal void emit_download (string filename, uint64 xfered, uint64 total);
|
|
|
|
public signal void emit_totaldownload (uint64 total);
|
|
|
|
public signal void emit_log (uint level, string msg);
|
|
|
|
public signal void emit_refreshed (ErrorInfos error);
|
|
|
|
public signal void emit_trans_prepared (ErrorInfos error);
|
|
|
|
public signal void emit_trans_committed (ErrorInfos error);
|
|
|
|
|
|
|
|
public Daemon () {
|
2014-12-03 12:02:14 -03:00
|
|
|
alpm_config = new Alpm.Config ("/etc/pacman.conf");
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2014-12-03 12:02:14 -03:00
|
|
|
private void refresh_handle () {
|
|
|
|
alpm_config.get_handle ();
|
|
|
|
if (alpm_config.handle == null) {
|
2014-10-30 10:44:09 -03:00
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
err.str = _("Failed to initialize alpm library");
|
|
|
|
emit_trans_committed (err);
|
|
|
|
} else {
|
2014-12-03 12:02:14 -03:00
|
|
|
alpm_config.handle.eventcb = (EventCallBack) cb_event;
|
|
|
|
alpm_config.handle.progresscb = (ProgressCallBack) cb_progress;
|
|
|
|
alpm_config.handle.questioncb = (QuestionCallBack) cb_question;
|
|
|
|
alpm_config.handle.dlcb = (DownloadCallBack) cb_download;
|
|
|
|
alpm_config.handle.totaldlcb = (TotalDownloadCallBack) cb_totaldownload;
|
|
|
|
alpm_config.handle.logcb = (LogCallBack) cb_log;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
previous_percent = 0;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-11-16 07:31:44 -03:00
|
|
|
public void write_config (HashTable<string,string> new_conf, GLib.BusName sender) {
|
2014-10-30 10:44:09 -03:00
|
|
|
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
|
|
|
try {
|
|
|
|
Polkit.Authority authority = Polkit.Authority.get_sync (null);
|
|
|
|
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
2014-11-16 07:31:44 -03:00
|
|
|
Polkit.AuthorizationResult result = authority.check_authorization_sync (
|
2014-11-08 13:50:35 -03:00
|
|
|
subject,
|
|
|
|
"org.manjaro.pamac.commit",
|
|
|
|
null,
|
|
|
|
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
|
|
null
|
|
|
|
);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (result.get_is_authorized ()) {
|
|
|
|
pamac_config.write (new_conf);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
|
|
|
|
2014-11-16 07:31:44 -03:00
|
|
|
public void set_pkgreason (string pkgname, uint reason, GLib.BusName sender) {
|
2014-11-08 13:50:35 -03:00
|
|
|
try {
|
|
|
|
Polkit.Authority authority = Polkit.Authority.get_sync (null);
|
|
|
|
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
2014-11-16 07:31:44 -03:00
|
|
|
Polkit.AuthorizationResult result = authority.check_authorization_sync (
|
2014-11-08 13:50:35 -03:00
|
|
|
subject,
|
|
|
|
"org.manjaro.pamac.commit",
|
|
|
|
null,
|
|
|
|
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
if (result.get_is_authorized ()) {
|
2014-12-03 12:02:14 -03:00
|
|
|
refresh_handle ();
|
|
|
|
unowned Package? pkg = alpm_config.handle.localdb.get_pkg (pkgname);
|
2014-11-08 13:50:35 -03:00
|
|
|
if (pkg != null)
|
2014-12-03 12:02:14 -03:00
|
|
|
pkg.reason = (Package.Reason) reason;
|
2014-11-08 13:50:35 -03:00
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
private int refresh_real () {
|
2014-12-03 12:02:14 -03:00
|
|
|
refresh_handle ();
|
2014-10-30 10:44:09 -03:00
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
|
|
|
int success = 0;
|
2014-11-24 17:34:23 -03:00
|
|
|
int ret;
|
2014-12-03 12:02:14 -03:00
|
|
|
foreach (var db in alpm_config.handle.syncdbs) {
|
2014-11-24 17:34:23 -03:00
|
|
|
ret = db.update (force_refresh);
|
|
|
|
if (ret >= 0) {
|
|
|
|
success++;
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2014-11-24 17:34:23 -03:00
|
|
|
}
|
|
|
|
// 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
|
|
|
|
if (success == 0) {
|
2014-10-26 08:30:04 -03:00
|
|
|
err.str = _("Failed to synchronize any databases");
|
2014-12-03 12:02:14 -03:00
|
|
|
details += Alpm.strerror (alpm_config.handle.errno ());
|
2014-10-22 13:44:02 -03:00
|
|
|
err.details = details;
|
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
if (emit_refreshed_signal)
|
|
|
|
emit_refreshed (err);
|
|
|
|
return success;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public void refresh (int force, bool emit_signal) {
|
|
|
|
force_refresh = force;
|
|
|
|
emit_refreshed_signal = emit_signal;
|
|
|
|
try {
|
|
|
|
new Thread<int>.try ("refresh thread", (ThreadFunc) refresh_real);
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public UpdatesInfos[] get_updates () {
|
2014-12-03 12:02:14 -03:00
|
|
|
refresh_handle ();
|
2014-10-30 10:44:09 -03:00
|
|
|
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
|
|
|
UpdatesInfos[] updates = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
updates = get_syncfirst_updates (alpm_config.handle, alpm_config.syncfirst);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (updates.length != 0) {
|
|
|
|
return updates;
|
|
|
|
} else {
|
2014-12-03 12:02:14 -03:00
|
|
|
updates = get_repos_updates (alpm_config.handle, alpm_config.ignore_pkgs);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (pamac_config.enable_aur) {
|
2014-12-03 12:02:14 -03:00
|
|
|
UpdatesInfos[] aur_updates = get_aur_updates (alpm_config.handle, alpm_config.ignore_pkgs);
|
2014-10-30 10:44:09 -03:00
|
|
|
foreach (var infos in aur_updates)
|
|
|
|
updates += infos;
|
|
|
|
}
|
|
|
|
return updates;
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public ErrorInfos trans_init (TransFlag transflags) {
|
2014-12-03 12:02:14 -03:00
|
|
|
refresh_handle ();
|
2014-10-30 10:44:09 -03:00
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
int ret = alpm_config.handle.trans_init (transflags);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (ret == -1) {
|
|
|
|
err.str = _("Failed to init transaction");
|
2014-12-03 12:02:14 -03:00
|
|
|
details += Alpm.strerror (alpm_config.handle.errno ());
|
2014-10-30 10:44:09 -03:00
|
|
|
err.details = details;
|
|
|
|
}
|
|
|
|
return err;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public ErrorInfos trans_sysupgrade (int enable_downgrade) {
|
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
int ret = alpm_config.handle.trans_sysupgrade (enable_downgrade);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (ret == -1) {;
|
|
|
|
err.str = _("Failed to prepare transaction");
|
2014-12-03 12:02:14 -03:00
|
|
|
details += Alpm.strerror (alpm_config.handle.errno ());
|
2014-10-30 10:44:09 -03:00
|
|
|
err.details = details;
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
return err;
|
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
|
|
|
|
public ErrorInfos trans_add_pkg (string pkgname) {
|
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
|
|
|
unowned Package? pkg = null;
|
2014-12-03 12:02:14 -03:00
|
|
|
pkg = alpm_config.handle.find_dbs_satisfier (alpm_config.handle.syncdbs, pkgname);
|
|
|
|
//foreach (var db in alpm_config.handle.syncdbs) {
|
2014-11-08 13:50:35 -03:00
|
|
|
//pkg = find_satisfier (db.pkgcache, pkgname);
|
|
|
|
//if (pkg != null)
|
|
|
|
//break;
|
|
|
|
//}
|
2014-10-30 10:44:09 -03:00
|
|
|
if (pkg == null) {
|
2014-10-26 08:30:04 -03:00
|
|
|
err.str = _("Failed to prepare transaction");
|
2014-10-30 10:44:09 -03:00
|
|
|
details += _("target not found: %s").printf (pkgname);
|
2014-10-26 08:30:04 -03:00
|
|
|
err.details = details;
|
2014-10-22 13:44:02 -03:00
|
|
|
return err;
|
|
|
|
}
|
2014-12-03 12:02:14 -03:00
|
|
|
int ret = alpm_config.handle.trans_add_pkg (pkg);
|
2014-10-22 13:44:02 -03:00
|
|
|
if (ret == -1) {
|
2014-12-03 12:02:14 -03:00
|
|
|
Alpm.Errno errno = alpm_config.handle.errno ();
|
2014-10-26 08:30:04 -03:00
|
|
|
if (errno == Errno.TRANS_DUP_TARGET || errno == Errno.PKG_IGNORED)
|
2014-10-22 13:44:02 -03:00
|
|
|
// just skip duplicate or ignored targets
|
|
|
|
return err;
|
2014-10-26 08:30:04 -03:00
|
|
|
else {
|
|
|
|
err.str = _("Failed to prepare transaction");
|
|
|
|
details += "%s: %s".printf (pkg.name, Alpm.strerror (errno));
|
|
|
|
err.details = details;
|
2014-10-22 13:44:02 -03:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
return err;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public ErrorInfos trans_load_pkg (string pkgpath) {
|
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
Package* pkg = alpm_config.handle.load_file (pkgpath, 1, alpm_config.handle.localfilesiglevel);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (pkg == null) {
|
|
|
|
err.str = _("Failed to prepare transaction");
|
2014-12-03 12:02:14 -03:00
|
|
|
details += "%s: %s".printf (pkgpath, Alpm.strerror (alpm_config.handle.errno ()));
|
2014-10-30 10:44:09 -03:00
|
|
|
err.details = details;
|
|
|
|
return err;
|
|
|
|
} else {
|
2014-12-03 12:02:14 -03:00
|
|
|
int ret = alpm_config.handle.trans_add_pkg (pkg);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (ret == -1) {
|
2014-12-03 12:02:14 -03:00
|
|
|
Alpm.Errno errno = alpm_config.handle.errno ();
|
2014-10-30 10:44:09 -03:00
|
|
|
if (errno == Errno.TRANS_DUP_TARGET || errno == Errno.PKG_IGNORED)
|
|
|
|
// just skip duplicate or ignored targets
|
|
|
|
return err;
|
|
|
|
else {
|
|
|
|
err.str = _("Failed to prepare transaction");
|
|
|
|
details += "%s: %s".printf (pkg->name, Alpm.strerror (errno));
|
|
|
|
err.details = details;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
// free the package because it will not be used
|
|
|
|
delete pkg;
|
|
|
|
}
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
return err;
|
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
|
|
|
|
public ErrorInfos trans_remove_pkg (string pkgname) {
|
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
unowned Package? pkg = alpm_config.handle.localdb.get_pkg (pkgname);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (pkg == null) {
|
|
|
|
err.str = _("Failed to prepare transaction");
|
|
|
|
details += _("target not found: %s").printf (pkgname);
|
|
|
|
err.details = details;
|
|
|
|
return err;
|
|
|
|
}
|
2014-12-03 12:02:14 -03:00
|
|
|
int ret = alpm_config.handle.trans_remove_pkg (pkg);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (ret == -1) {
|
|
|
|
err.str = _("Failed to prepare transaction");
|
2014-12-03 12:02:14 -03:00
|
|
|
details += "%s: %s".printf (pkg.name, Alpm.strerror (alpm_config.handle.errno ()));
|
2014-10-30 10:44:09 -03:00
|
|
|
err.details = details;
|
|
|
|
}
|
|
|
|
return err;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public int trans_prepare_real () {
|
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
|
|
|
Alpm.List<void*> err_data = null;
|
2014-12-03 12:02:14 -03:00
|
|
|
int ret = alpm_config.handle.trans_prepare (out err_data);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (ret == -1) {
|
2014-12-03 12:02:14 -03:00
|
|
|
Alpm.Errno errno = alpm_config.handle.errno ();
|
2014-10-30 10:44:09 -03:00
|
|
|
err.str = _("Failed to prepare transaction");
|
|
|
|
string detail = Alpm.strerror (errno);
|
|
|
|
switch (errno) {
|
|
|
|
case Errno.PKG_INVALID_ARCH:
|
|
|
|
detail += ":";
|
|
|
|
details += detail;
|
|
|
|
foreach (void *i in err_data) {
|
|
|
|
char *pkgname = i;
|
|
|
|
details += _("package %s does not have a valid architecture").printf (pkgname);
|
2014-12-03 12:02:14 -03:00
|
|
|
delete pkgname;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
break;
|
|
|
|
case Errno.UNSATISFIED_DEPS:
|
|
|
|
detail += ":";
|
2014-10-26 08:30:04 -03:00
|
|
|
details += detail;
|
2014-10-30 10:44:09 -03:00
|
|
|
foreach (void *i in err_data) {
|
|
|
|
DepMissing *miss = i;
|
|
|
|
string depstring = miss->depend.compute_string ();
|
|
|
|
details += _("%s: requires %s").printf (miss->target, depstring);
|
2014-12-03 12:02:14 -03:00
|
|
|
delete miss;
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Errno.CONFLICTING_DEPS:
|
|
|
|
detail += ":";
|
|
|
|
details += detail;
|
|
|
|
foreach (void *i in err_data) {
|
|
|
|
Conflict *conflict = i;
|
|
|
|
detail = _("%s and %s are in conflict").printf (conflict->package1, conflict->package2);
|
|
|
|
// only print reason if it contains new information
|
2014-12-03 12:02:14 -03:00
|
|
|
if (conflict->reason.mod != Depend.Mode.ANY) {
|
2014-10-30 10:44:09 -03:00
|
|
|
detail += " (%s)".printf (conflict->reason.compute_string ());
|
|
|
|
}
|
|
|
|
details += detail;
|
2014-12-03 12:02:14 -03:00
|
|
|
delete conflict;
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
details += detail;
|
|
|
|
break;
|
2014-10-26 08:30:04 -03:00
|
|
|
}
|
|
|
|
err.details = details;
|
|
|
|
trans_release ();
|
2014-10-30 10:44:09 -03:00
|
|
|
} else {
|
|
|
|
// Search for holdpkg in target list
|
|
|
|
bool found_locked_pkg = false;
|
2014-12-03 12:02:14 -03:00
|
|
|
foreach (var pkg in alpm_config.handle.trans_to_remove ()) {
|
|
|
|
if (pkg.name in alpm_config.holdpkg) {
|
2014-10-30 10:44:09 -03:00
|
|
|
details += _("%s needs to be removed but it is a locked package").printf (pkg.name);
|
|
|
|
found_locked_pkg = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found_locked_pkg) {
|
|
|
|
err.str = _("Failed to prepare transaction");
|
|
|
|
err.details = details;
|
|
|
|
trans_release ();
|
|
|
|
}
|
2014-10-26 08:30:04 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
emit_trans_prepared (err);
|
|
|
|
return ret;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public void trans_prepare () {
|
|
|
|
try {
|
|
|
|
new Thread<int>.try ("prepare thread", (ThreadFunc) trans_prepare_real);
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public void choose_provider (int provider) {
|
|
|
|
provider_mutex.lock ();
|
|
|
|
choosen_provider = provider;
|
|
|
|
provider_cond.signal ();
|
|
|
|
provider_mutex.unlock ();
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public UpdatesInfos[] trans_to_add () {
|
|
|
|
UpdatesInfos info = UpdatesInfos ();
|
|
|
|
UpdatesInfos[] infos = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
foreach (var pkg in alpm_config.handle.trans_to_add ()) {
|
2014-10-30 10:44:09 -03:00
|
|
|
info.name = pkg.name;
|
|
|
|
info.version = pkg.version;
|
|
|
|
// if pkg was load from a file, pkg.db is null
|
|
|
|
if (pkg.db != null)
|
|
|
|
info.db_name = pkg.db.name;
|
|
|
|
else
|
|
|
|
info.db_name = "";
|
|
|
|
info.tarpath = "";
|
|
|
|
info.download_size = pkg.download_size;
|
|
|
|
infos += info;
|
|
|
|
}
|
|
|
|
return infos;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public UpdatesInfos[] trans_to_remove () {
|
|
|
|
UpdatesInfos info = UpdatesInfos ();
|
|
|
|
UpdatesInfos[] infos = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
foreach (var pkg in alpm_config.handle.trans_to_remove ()) {
|
2014-10-30 10:44:09 -03:00
|
|
|
info.name = pkg.name;
|
|
|
|
info.version = pkg.version;
|
|
|
|
info.db_name = pkg.db.name;
|
|
|
|
info.tarpath = "";
|
|
|
|
info.download_size = pkg.download_size;
|
|
|
|
infos += info;
|
|
|
|
}
|
|
|
|
return infos;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
private int trans_commit_real () {
|
|
|
|
ErrorInfos err = ErrorInfos ();
|
|
|
|
string[] details = {};
|
|
|
|
Alpm.List<void*> err_data = null;
|
2014-12-03 12:02:14 -03:00
|
|
|
int ret = alpm_config.handle.trans_commit (out err_data);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (ret == -1) {
|
2014-12-03 12:02:14 -03:00
|
|
|
Alpm.Errno errno = alpm_config.handle.errno ();
|
2014-10-30 10:44:09 -03:00
|
|
|
err.str = _("Failed to commit transaction");
|
|
|
|
string detail = Alpm.strerror (errno);
|
|
|
|
switch (errno) {
|
|
|
|
case Alpm.Errno.FILE_CONFLICTS:
|
|
|
|
detail += ":";
|
|
|
|
details += detail;
|
2014-12-03 12:02:14 -03:00
|
|
|
//TransFlag flags = alpm_config.handle.trans_get_flags ();
|
2014-10-30 10:44:09 -03:00
|
|
|
//if ((flags & TransFlag.FORCE) != 0) {
|
|
|
|
//details += _("unable to %s directory-file conflicts").printf ("--force");
|
|
|
|
//}
|
|
|
|
foreach (void *i in err_data) {
|
|
|
|
FileConflict *conflict = i;
|
|
|
|
switch (conflict->type) {
|
2014-12-03 12:02:14 -03:00
|
|
|
case FileConflict.Type.TARGET:
|
2014-10-30 10:44:09 -03:00
|
|
|
details += _("%s exists in both %s and %s").printf (conflict->file, conflict->target, conflict->ctarget);
|
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case FileConflict.Type.FILESYSTEM:
|
2014-10-30 10:44:09 -03:00
|
|
|
details += _("%s: %s already exists in filesystem").printf (conflict->target, conflict->file);
|
|
|
|
break;
|
|
|
|
}
|
2014-12-03 12:02:14 -03:00
|
|
|
delete conflict;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
break;
|
|
|
|
case Alpm.Errno.PKG_INVALID:
|
|
|
|
case Alpm.Errno.PKG_INVALID_CHECKSUM:
|
|
|
|
case Alpm.Errno.PKG_INVALID_SIG:
|
|
|
|
case Alpm.Errno.DLT_INVALID:
|
|
|
|
detail += ":";
|
|
|
|
details += detail;
|
|
|
|
foreach (void *i in err_data) {
|
|
|
|
char *filename = i;
|
|
|
|
details += _("%s is invalid or corrupted").printf (filename);
|
2014-12-03 12:02:14 -03:00
|
|
|
delete filename;
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
details += detail;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err.details = details;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
trans_release ();
|
|
|
|
emit_trans_committed (err);
|
|
|
|
return ret;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public void trans_commit (GLib.BusName sender) {
|
|
|
|
try {
|
|
|
|
Polkit.Authority authority = Polkit.Authority.get_sync (null);
|
|
|
|
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
|
|
|
var result = new Polkit.AuthorizationResult (false, false, null);
|
|
|
|
authority.check_authorization.begin (
|
|
|
|
subject,
|
|
|
|
"org.manjaro.pamac.commit",
|
|
|
|
null,
|
|
|
|
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
|
|
null,
|
|
|
|
(obj, res) => {
|
|
|
|
try {
|
|
|
|
result = authority.check_authorization.end (res);
|
|
|
|
if (result.get_is_authorized ()) {
|
|
|
|
new Thread<int>.try ("commit thread", (ThreadFunc) trans_commit_real);
|
|
|
|
} else {
|
|
|
|
ErrorInfos err = ErrorInfos ();
|
2014-11-22 07:53:14 -03:00
|
|
|
err.str = _("Authentication failed");
|
2014-10-30 10:44:09 -03:00
|
|
|
emit_trans_committed (err);
|
|
|
|
trans_release ();
|
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Polkit Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Polkit Error: %s\n", e.message);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public int trans_release () {
|
2014-12-03 12:02:14 -03:00
|
|
|
return alpm_config.handle.trans_release ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public void trans_cancel () {
|
2014-12-03 12:02:14 -03:00
|
|
|
alpm_config.handle.trans_interrupt ();
|
|
|
|
alpm_config.handle.trans_release ();
|
|
|
|
refresh_handle ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
public void quit () {
|
|
|
|
GLib.File lockfile = GLib.File.new_for_path ("/var/lib/pacman/db.lck");
|
|
|
|
if (lockfile.query_exists () == false)
|
|
|
|
loop.quit ();
|
|
|
|
}
|
|
|
|
// End of Daemon Object
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void write_log_file (string event) {
|
|
|
|
var now = new DateTime.now_local ();
|
|
|
|
string log = "%s %s".printf (now.format ("[%Y-%m-%d %H:%M]"), event);
|
|
|
|
var file = GLib.File.new_for_path ("/var/log/pamac.log");
|
|
|
|
try {
|
|
|
|
// creating a DataOutputStream to the file
|
|
|
|
var dos = new DataOutputStream (file.append_to (FileCreateFlags.NONE));
|
|
|
|
// writing a short string to the stream
|
|
|
|
dos.put_string (log);
|
|
|
|
} catch (GLib.Error e) {
|
2014-10-26 08:30:04 -03:00
|
|
|
stderr.printf("%s\n", e.message);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 12:02:14 -03:00
|
|
|
private void cb_event (Event.Data data) {
|
2014-10-26 08:30:04 -03:00
|
|
|
string[] details = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
uint secondary_type = 0;
|
|
|
|
switch (data.type) {
|
|
|
|
case Event.Type.PACKAGE_OPERATION_START:
|
|
|
|
switch (data.package_operation_operation) {
|
|
|
|
case Package.Operation.REMOVE:
|
|
|
|
details += data.package_operation_oldpkg.name;
|
|
|
|
details += data.package_operation_oldpkg.version;
|
|
|
|
secondary_type = (uint) Package.Operation.REMOVE;
|
|
|
|
break;
|
|
|
|
case Package.Operation.INSTALL:
|
|
|
|
details += data.package_operation_newpkg.name;
|
|
|
|
details += data.package_operation_newpkg.version;
|
|
|
|
secondary_type = (uint) Package.Operation.INSTALL;
|
|
|
|
break;
|
|
|
|
case Package.Operation.REINSTALL:
|
|
|
|
details += data.package_operation_newpkg.name;
|
|
|
|
details += data.package_operation_newpkg.version;
|
|
|
|
secondary_type = (uint) Package.Operation.REINSTALL;
|
|
|
|
break;
|
|
|
|
case Package.Operation.UPGRADE:
|
|
|
|
details += data.package_operation_oldpkg.name;
|
|
|
|
details += data.package_operation_oldpkg.version;
|
|
|
|
details += data.package_operation_newpkg.version;
|
|
|
|
secondary_type = (uint) Package.Operation.UPGRADE;
|
|
|
|
break;
|
|
|
|
case Package.Operation.DOWNGRADE:
|
|
|
|
details += data.package_operation_oldpkg.name;
|
|
|
|
details += data.package_operation_oldpkg.version;
|
|
|
|
details += data.package_operation_newpkg.version;
|
|
|
|
secondary_type = (uint) Package.Operation.DOWNGRADE;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.PACKAGE_OPERATION_DONE:
|
|
|
|
switch (data.package_operation_operation) {
|
|
|
|
case Package.Operation.INSTALL:
|
|
|
|
string log = "Installed %s (%s)\n".printf (data.package_operation_newpkg.name, data.package_operation_newpkg.version);
|
|
|
|
write_log_file (log);
|
|
|
|
break;
|
|
|
|
case Package.Operation.REMOVE:
|
|
|
|
string log = "Removed %s (%s)\n".printf (data.package_operation_oldpkg.name, data.package_operation_oldpkg.version);
|
|
|
|
write_log_file (log);
|
|
|
|
break;
|
|
|
|
case Package.Operation.REINSTALL:
|
|
|
|
string log = "Reinstalled %s (%s)\n".printf (data.package_operation_newpkg.name, data.package_operation_newpkg.version);
|
|
|
|
write_log_file (log);
|
|
|
|
break;
|
|
|
|
case Package.Operation.UPGRADE:
|
|
|
|
string log = "Upgraded %s (%s -> %s)\n".printf (data.package_operation_oldpkg.name, data.package_operation_oldpkg.version, data.package_operation_newpkg.version);
|
|
|
|
write_log_file (log);
|
|
|
|
break;
|
|
|
|
case Package.Operation.DOWNGRADE:
|
|
|
|
string log = "Downgraded %s (%s -> %s)\n".printf (data.package_operation_oldpkg.name, data.package_operation_oldpkg.version, data.package_operation_newpkg.version);
|
|
|
|
write_log_file (log);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.DELTA_PATCH_START:
|
|
|
|
details += data.delta_patch_delta.to;
|
|
|
|
details += data.delta_patch_delta.delta;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.SCRIPTLET_INFO:
|
|
|
|
details += data.scriptlet_info_line;
|
|
|
|
write_log_file (data.scriptlet_info_line);
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.PKGDOWNLOAD_START:
|
|
|
|
details += data.pkgdownload_file;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.OPTDEP_REMOVAL:
|
|
|
|
details += data.optdep_removal_pkg.name;
|
|
|
|
details += data.optdep_removal_optdep.compute_string ();
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.DATABASE_MISSING:
|
|
|
|
details += data.database_missing_dbname;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.PACNEW_CREATED:
|
|
|
|
details += data.pacnew_created_file;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.PACSAVE_CREATED:
|
|
|
|
details += data.pacsave_created_file;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Event.Type.PACORIG_CREATED:
|
|
|
|
details += data.pacorig_created_file;
|
2014-10-26 08:30:04 -03:00
|
|
|
break;
|
2014-10-22 13:44:02 -03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-12-03 12:02:14 -03:00
|
|
|
pamac_daemon.emit_event ((uint) data.type, secondary_type, details);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2014-12-03 12:02:14 -03:00
|
|
|
private void cb_question (Question.Data data) {
|
|
|
|
switch (data.type) {
|
|
|
|
case Question.Type.INSTALL_IGNOREPKG:
|
2014-10-22 13:44:02 -03:00
|
|
|
// Do not install package in IgnorePkg/IgnoreGroup
|
2014-12-03 12:02:14 -03:00
|
|
|
data.install_ignorepkg_install = 0;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Question.Type.REPLACE_PKG:
|
2014-10-22 13:44:02 -03:00
|
|
|
// Auto-remove conflicts in case of replaces
|
2014-12-03 12:02:14 -03:00
|
|
|
data.replace_replace = 1;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Question.Type.CONFLICT_PKG:
|
2014-10-22 13:44:02 -03:00
|
|
|
// Auto-remove conflicts
|
2014-12-03 12:02:14 -03:00
|
|
|
data.conflict_remove = 1;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Question.Type.REMOVE_PKGS:
|
2014-10-22 13:44:02 -03:00
|
|
|
// Do not upgrade packages which have unresolvable dependencies
|
2014-12-03 12:02:14 -03:00
|
|
|
data.remove_pkgs_skip = 1;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Question.Type.SELECT_PROVIDER:
|
|
|
|
string depend_str = data.select_provider_depend.compute_string ();
|
2014-10-22 13:44:02 -03:00
|
|
|
string[] providers_str = {};
|
2014-12-03 12:02:14 -03:00
|
|
|
foreach (unowned Package pkg in data.select_provider_providers) {
|
2014-10-22 13:44:02 -03:00
|
|
|
providers_str += pkg.name;
|
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
pamac_daemon.provider_cond = Cond ();
|
|
|
|
pamac_daemon.provider_mutex = Mutex ();
|
|
|
|
pamac_daemon.choosen_provider = null;
|
|
|
|
pamac_daemon.emit_providers (depend_str, providers_str);
|
|
|
|
pamac_daemon.provider_mutex.lock ();
|
|
|
|
while (pamac_daemon.choosen_provider == null) {
|
|
|
|
pamac_daemon.provider_cond.wait (pamac_daemon.provider_mutex);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-12-03 12:02:14 -03:00
|
|
|
data.select_provider_use_index = pamac_daemon.choosen_provider;
|
2014-10-30 10:44:09 -03:00
|
|
|
pamac_daemon.provider_mutex.unlock ();
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Question.Type.CORRUPTED_PKG:
|
2014-10-22 13:44:02 -03:00
|
|
|
// Auto-remove corrupted pkgs in cache
|
2014-12-03 12:02:14 -03:00
|
|
|
data.corrupted_remove = 1;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
case Question.Type.IMPORT_KEY:
|
2014-10-22 13:44:02 -03:00
|
|
|
// Do not get revoked key
|
2014-12-03 12:02:14 -03:00
|
|
|
if (data.import_key_key.revoked == 1)
|
|
|
|
data.import_key_import = 0;
|
2014-10-22 13:44:02 -03:00
|
|
|
// Auto get not revoked key
|
2014-12-03 12:02:14 -03:00
|
|
|
else
|
|
|
|
data.import_key_import = 1;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
|
|
|
default:
|
2014-12-03 12:02:14 -03:00
|
|
|
data.any_answer = 0;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void cb_progress (Progress progress, string pkgname, int percent, uint n_targets, uint current_target) {
|
2014-10-30 10:44:09 -03:00
|
|
|
if ((uint64) percent != pamac_daemon.previous_percent) {
|
|
|
|
pamac_daemon.previous_percent = (uint64) percent;
|
|
|
|
pamac_daemon.emit_progress ((uint) progress, pkgname, percent, n_targets, current_target);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void cb_download (string filename, uint64 xfered, uint64 total) {
|
2014-10-30 10:44:09 -03:00
|
|
|
if (xfered != pamac_daemon.previous_percent) {
|
|
|
|
pamac_daemon.previous_percent = xfered;
|
|
|
|
pamac_daemon.emit_download (filename, xfered, total);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void cb_totaldownload (uint64 total) {
|
2014-10-30 10:44:09 -03:00
|
|
|
pamac_daemon.emit_totaldownload (total);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void cb_log (LogLevel level, string fmt, va_list args) {
|
|
|
|
LogLevel logmask = LogLevel.ERROR | LogLevel.WARNING;
|
|
|
|
if ((level & logmask) == 0)
|
|
|
|
return;
|
|
|
|
string? log = null;
|
|
|
|
log = fmt.vprintf (args);
|
|
|
|
if (log != null)
|
2014-10-30 10:44:09 -03:00
|
|
|
pamac_daemon.emit_log ((uint) level, log);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_bus_acquired (DBusConnection conn) {
|
2014-10-30 10:44:09 -03:00
|
|
|
pamac_daemon = new Pamac.Daemon ();
|
2014-10-22 13:44:02 -03:00
|
|
|
try {
|
2014-10-30 10:44:09 -03:00
|
|
|
conn.register_object ("/org/manjaro/pamac", pamac_daemon);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
catch (IOError e) {
|
|
|
|
stderr.printf ("Could not register service\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void main () {
|
|
|
|
// i18n
|
2014-10-30 10:44:09 -03:00
|
|
|
Intl.setlocale (LocaleCategory.ALL, "");
|
|
|
|
Intl.textdomain (GETTEXT_PACKAGE);
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
Bus.own_name (BusType.SYSTEM, "org.manjaro.pamac", BusNameOwnerFlags.NONE,
|
2014-10-22 13:44:02 -03:00
|
|
|
on_bus_acquired,
|
|
|
|
() => {},
|
|
|
|
() => stderr.printf("Could not acquire name\n"));
|
|
|
|
|
|
|
|
loop = new MainLoop ();
|
|
|
|
loop.run ();
|
|
|
|
}
|