2014-10-22 13:44:02 -03:00
|
|
|
/*
|
|
|
|
* pamac-vala
|
|
|
|
*
|
2017-01-03 05:43:19 -03:00
|
|
|
* Copyright (C) 2014-2017 Guillaume Benoit <guillaume@manjaro.org>
|
2014-10-22 13:44:02 -03:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// i18n
|
2014-10-26 08:30:04 -03:00
|
|
|
const string GETTEXT_PACKAGE = "pamac";
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
Pamac.SystemDaemon system_daemon;
|
2014-10-22 13:44:02 -03:00
|
|
|
MainLoop loop;
|
|
|
|
|
2015-08-20 10:11:18 -03:00
|
|
|
public delegate void AlpmActionDelegate ();
|
2016-02-02 05:28:07 -03:00
|
|
|
|
|
|
|
[Compact]
|
|
|
|
public class AlpmAction {
|
|
|
|
public unowned AlpmActionDelegate action_delegate;
|
|
|
|
public AlpmAction (AlpmActionDelegate action_delegate) {
|
|
|
|
this.action_delegate = action_delegate;
|
|
|
|
}
|
|
|
|
public void run () {
|
|
|
|
action_delegate ();
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
|
2014-10-30 10:44:09 -03:00
|
|
|
namespace Pamac {
|
2017-07-29 10:35:04 -04:00
|
|
|
[DBus (name = "org.manjaro.pamac.system")]
|
|
|
|
public class SystemDaemon: Object {
|
2016-02-26 06:37:26 -03:00
|
|
|
private AlpmConfig alpm_config;
|
2016-04-14 13:19:20 -03:00
|
|
|
private Alpm.Handle? alpm_handle;
|
2017-03-03 08:21:27 -03:00
|
|
|
private Alpm.Handle? files_handle;
|
2014-10-30 10:44:09 -03:00
|
|
|
public Cond provider_cond;
|
|
|
|
public Mutex provider_mutex;
|
|
|
|
public int? choosen_provider;
|
2017-07-29 10:35:04 -04:00
|
|
|
private bool refreshed;
|
2016-02-02 05:28:07 -03:00
|
|
|
private bool force_refresh;
|
2016-08-27 09:51:34 -03:00
|
|
|
private bool enable_downgrade;
|
2017-03-22 12:32:12 -03:00
|
|
|
private bool check_aur_updates;
|
2017-07-29 10:35:04 -04:00
|
|
|
private bool aur_updates_checked;
|
2017-03-22 12:32:12 -03:00
|
|
|
private HashTable<string,Variant> new_alpm_conf;
|
2016-08-27 09:51:34 -03:00
|
|
|
private Alpm.TransFlag flags;
|
|
|
|
private string[] to_install;
|
|
|
|
private string[] to_remove;
|
|
|
|
private string[] to_load;
|
2017-02-18 13:10:26 -03:00
|
|
|
private string[] to_build;
|
|
|
|
private UpdateInfos[] to_build_infos;
|
|
|
|
private GLib.List<string> aur_pkgbases_to_build;
|
|
|
|
private GenericSet<string?> aur_desc_list;
|
|
|
|
private GenericSet<string?> already_checked_aur_dep;
|
|
|
|
private HashTable<string, string> to_install_as_dep;
|
|
|
|
private string aurdb_path;
|
2016-08-27 09:51:34 -03:00
|
|
|
private string[] temporary_ignorepkgs;
|
2017-02-18 13:10:26 -03:00
|
|
|
private UpdateInfos[] aur_conflicts_to_remove;
|
2015-08-20 10:11:18 -03:00
|
|
|
private ThreadPool<AlpmAction> thread_pool;
|
2017-07-29 10:35:04 -04:00
|
|
|
private BusName lock_id;
|
2015-03-27 12:31:07 -03:00
|
|
|
private Json.Array aur_updates_results;
|
2015-03-28 11:17:14 -03:00
|
|
|
private GLib.File lockfile;
|
2017-04-16 07:40:50 -03:00
|
|
|
public ErrorInfos current_error;
|
2016-02-02 05:28:07 -03:00
|
|
|
public Timer timer;
|
2016-02-22 09:47:40 -03:00
|
|
|
public Cancellable cancellable;
|
2017-03-08 12:22:07 -03:00
|
|
|
public Curl.Easy curl;
|
2017-03-10 06:20:55 -03:00
|
|
|
private bool authorized;
|
2014-10-30 10:44:09 -03:00
|
|
|
|
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);
|
2016-02-02 05:28:07 -03:00
|
|
|
public signal void emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target);
|
2014-10-30 10:44:09 -03:00
|
|
|
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);
|
2015-03-04 11:55:36 -03:00
|
|
|
public signal void set_pkgreason_finished ();
|
2016-02-02 05:28:07 -03:00
|
|
|
public signal void refresh_finished (bool success);
|
|
|
|
public signal void get_updates_finished (Updates updates);
|
|
|
|
public signal void trans_prepare_finished (bool success);
|
|
|
|
public signal void trans_commit_finished (bool success);
|
2015-08-20 10:11:18 -03:00
|
|
|
public signal void get_authorization_finished (bool authorized);
|
2016-02-02 05:28:07 -03:00
|
|
|
public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
|
2017-09-09 12:25:24 -03:00
|
|
|
bool enable_aur, string aur_build_dir, bool check_aur_updates);
|
2015-08-20 10:11:18 -03:00
|
|
|
public signal void write_alpm_config_finished (bool checkspace);
|
|
|
|
public signal void write_mirrors_config_finished (string choosen_country, string choosen_generation_method);
|
|
|
|
public signal void generate_mirrors_list_data (string line);
|
|
|
|
public signal void generate_mirrors_list_finished ();
|
2014-10-30 10:44:09 -03:00
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
public SystemDaemon () {
|
2016-02-26 06:37:26 -03:00
|
|
|
alpm_config = new AlpmConfig ("/etc/pacman.conf");
|
2017-02-18 13:10:26 -03:00
|
|
|
aur_pkgbases_to_build = new GLib.List<string> ();
|
|
|
|
aur_desc_list = new GenericSet<string?> (str_hash, str_equal);
|
|
|
|
already_checked_aur_dep = new GenericSet<string?> (str_hash, str_equal);
|
|
|
|
to_install_as_dep = new HashTable<string, string> (str_hash, str_equal);
|
|
|
|
aurdb_path = "/tmp/pamac-aur";
|
2015-03-27 12:31:07 -03:00
|
|
|
aur_updates_results = new Json.Array ();
|
2016-02-02 05:28:07 -03:00
|
|
|
timer = new Timer ();
|
2017-07-29 10:35:04 -04:00
|
|
|
lock_id = new BusName ("");
|
2015-03-04 11:55:36 -03:00
|
|
|
refresh_handle ();
|
2017-07-31 08:15:36 -04:00
|
|
|
check_old_lock ();
|
|
|
|
check_extern_lock ();
|
2017-05-13 12:33:47 -03:00
|
|
|
Timeout.add (500, check_extern_lock);
|
2015-08-20 10:11:18 -03:00
|
|
|
create_thread_pool ();
|
2016-02-22 09:47:40 -03:00
|
|
|
cancellable = new Cancellable ();
|
2017-03-08 12:07:53 -03:00
|
|
|
curl = new Curl.Easy ();
|
2017-03-10 06:20:55 -03:00
|
|
|
authorized = false;
|
2017-07-29 10:35:04 -04:00
|
|
|
refreshed = false;
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
|
|
|
|
2016-02-02 05:28:07 -03:00
|
|
|
public void set_environment_variables (HashTable<string,string> variables) {
|
|
|
|
string[] keys = { "HTTP_USER_AGENT",
|
|
|
|
"http_proxy",
|
|
|
|
"https_proxy",
|
|
|
|
"ftp_proxy",
|
|
|
|
"socks_proxy",
|
|
|
|
"no_proxy" };
|
|
|
|
foreach (unowned string key in keys) {
|
|
|
|
unowned string val;
|
|
|
|
if (variables.lookup_extended (key, null, out val)) {
|
|
|
|
Environment.set_variable (key, val, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ErrorInfos get_current_error () {
|
|
|
|
return current_error;
|
|
|
|
}
|
|
|
|
|
2015-08-20 10:11:18 -03:00
|
|
|
private void create_thread_pool () {
|
|
|
|
// create a thread pool which will run alpm action one after one
|
|
|
|
try {
|
|
|
|
thread_pool = new ThreadPool<AlpmAction>.with_owned_data (
|
|
|
|
// call alpm_action.run () on thread start
|
|
|
|
(alpm_action) => {
|
|
|
|
alpm_action.run ();
|
|
|
|
},
|
2017-08-22 06:11:31 -03:00
|
|
|
// only one thread created so alpm action will run one after one
|
|
|
|
1,
|
2016-05-05 08:16:38 -03:00
|
|
|
// no exclusive thread
|
|
|
|
false
|
2015-08-20 10:11:18 -03:00
|
|
|
);
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
|
|
|
}
|
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 () {
|
2016-04-14 13:19:20 -03:00
|
|
|
alpm_handle = alpm_config.get_handle ();
|
|
|
|
if (alpm_handle == null) {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error = ErrorInfos () {
|
2016-03-01 11:43:51 -03:00
|
|
|
message = _("Failed to initialize alpm library")
|
2016-02-02 05:28:07 -03:00
|
|
|
};
|
|
|
|
trans_commit_finished (false);
|
2017-06-03 11:55:18 -04:00
|
|
|
return;
|
2014-10-30 10:44:09 -03:00
|
|
|
} else {
|
2016-04-14 13:19:20 -03:00
|
|
|
alpm_handle.eventcb = (Alpm.EventCallBack) cb_event;
|
|
|
|
alpm_handle.progresscb = (Alpm.ProgressCallBack) cb_progress;
|
|
|
|
alpm_handle.questioncb = (Alpm.QuestionCallBack) cb_question;
|
|
|
|
alpm_handle.fetchcb = (Alpm.FetchCallBack) cb_fetch;
|
|
|
|
alpm_handle.totaldlcb = (Alpm.TotalDownloadCallBack) cb_totaldownload;
|
|
|
|
alpm_handle.logcb = (Alpm.LogCallBack) cb_log;
|
|
|
|
lockfile = GLib.File.new_for_path (alpm_handle.lockfile);
|
2017-07-29 10:35:04 -04:00
|
|
|
files_handle = alpm_config.get_handle (true);
|
2017-08-22 06:11:31 -03:00
|
|
|
files_handle.eventcb = (Alpm.EventCallBack) cb_event;
|
|
|
|
files_handle.progresscb = (Alpm.ProgressCallBack) cb_progress;
|
|
|
|
files_handle.questioncb = (Alpm.QuestionCallBack) cb_question;
|
2017-07-29 10:35:04 -04:00
|
|
|
files_handle.fetchcb = (Alpm.FetchCallBack) cb_fetch;
|
2017-08-22 06:11:31 -03:00
|
|
|
files_handle.totaldlcb = (Alpm.TotalDownloadCallBack) cb_totaldownload;
|
|
|
|
files_handle.logcb = (Alpm.LogCallBack) cb_log;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 08:15:36 -04:00
|
|
|
private void check_old_lock () {
|
|
|
|
if (lockfile.query_exists ()) {
|
|
|
|
int exit_status;
|
|
|
|
string output;
|
|
|
|
uint64 lockfile_time;
|
|
|
|
try {
|
|
|
|
// get lockfile modification time since epoch
|
|
|
|
Process.spawn_command_line_sync ("stat -c %Y %s".printf (alpm_handle.lockfile),
|
|
|
|
out output,
|
|
|
|
null,
|
|
|
|
out exit_status);
|
|
|
|
if (exit_status == 0) {
|
|
|
|
string[] splitted = output.split ("\n");
|
|
|
|
if (splitted.length == 2) {
|
|
|
|
if (uint64.try_parse (splitted[0], out lockfile_time)) {
|
|
|
|
uint64 boot_time;
|
|
|
|
// get boot time since epoch
|
|
|
|
Process.spawn_command_line_sync ("cat /proc/stat",
|
|
|
|
out output,
|
|
|
|
null,
|
|
|
|
out exit_status);
|
|
|
|
if (exit_status == 0) {
|
|
|
|
splitted = output.split ("\n");
|
|
|
|
foreach (unowned string line in splitted) {
|
|
|
|
if ("btime" in line) {
|
|
|
|
string[] space_splitted = line.split (" ");
|
|
|
|
if (space_splitted.length == 2) {
|
|
|
|
if (uint64.try_parse (space_splitted[1], out boot_time)) {
|
|
|
|
// check if lock file is older than boot time
|
|
|
|
if (lockfile_time < boot_time) {
|
|
|
|
// remove the unneeded lock file.
|
|
|
|
try {
|
|
|
|
lockfile.delete ();
|
|
|
|
} catch (Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
lock_id = new BusName ("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SpawnError e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-13 12:33:47 -03:00
|
|
|
private bool check_extern_lock () {
|
2017-07-29 10:35:04 -04:00
|
|
|
if (lock_id == "extern") {
|
2016-02-02 05:28:07 -03:00
|
|
|
if (!lockfile.query_exists ()) {
|
2017-07-29 10:35:04 -04:00
|
|
|
lock_id = new BusName ("");
|
2015-03-11 15:42:04 -03:00
|
|
|
refresh_handle ();
|
|
|
|
}
|
|
|
|
} else {
|
2016-02-02 05:28:07 -03:00
|
|
|
if (lockfile.query_exists ()) {
|
2017-07-29 10:35:04 -04:00
|
|
|
if (lock_id == "") {
|
2017-07-31 08:15:36 -04:00
|
|
|
// An extern lock appears
|
2017-07-29 10:35:04 -04:00
|
|
|
lock_id = new BusName ("extern");
|
2015-03-18 10:53:45 -03:00
|
|
|
}
|
2015-03-11 15:42:04 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
public string[] get_mirrors_countries () {
|
|
|
|
string[] countries = {};
|
|
|
|
try {
|
|
|
|
string countries_str;
|
|
|
|
int status;
|
|
|
|
Process.spawn_command_line_sync ("pacman-mirrors -lq",
|
|
|
|
out countries_str,
|
|
|
|
null,
|
|
|
|
out status);
|
|
|
|
if (status == 0) {
|
|
|
|
foreach (unowned string country in countries_str.split ("\n")) {
|
|
|
|
countries += country;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SpawnError e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
return countries;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool get_lock (GLib.BusName sender) {
|
|
|
|
if (lock_id == sender) {
|
|
|
|
return true;
|
|
|
|
} else if (lock_id == "") {
|
|
|
|
lock_id = sender;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool unlock (GLib.BusName sender) {
|
|
|
|
if (lock_id == sender) {
|
|
|
|
lock_id = new BusName ("");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-21 11:01:02 -03:00
|
|
|
private async bool check_authorization (GLib.BusName sender) {
|
2017-07-29 10:35:04 -04:00
|
|
|
if (lock_id != sender) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-10 06:20:55 -03:00
|
|
|
if (authorized) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-21 11:01:02 -03:00
|
|
|
SourceFunc callback = check_authorization.callback;
|
2015-08-20 10:11:18 -03:00
|
|
|
try {
|
|
|
|
Polkit.Authority authority = Polkit.Authority.get_sync ();
|
|
|
|
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
|
|
|
authority.check_authorization.begin (
|
|
|
|
subject,
|
|
|
|
"org.manjaro.pamac.commit",
|
|
|
|
null,
|
|
|
|
Polkit.CheckAuthorizationFlags.ALLOW_USER_INTERACTION,
|
|
|
|
null,
|
|
|
|
(obj, res) => {
|
|
|
|
try {
|
|
|
|
var result = authority.check_authorization.end (res);
|
|
|
|
authorized = result.get_is_authorized ();
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
|
|
|
}
|
2015-08-21 11:01:02 -03:00
|
|
|
Idle.add ((owned) callback);
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
|
|
|
);
|
2016-02-02 05:28:07 -03:00
|
|
|
yield;
|
2015-08-20 10:11:18 -03:00
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("%s\n", e.message);
|
|
|
|
}
|
2017-03-10 06:20:55 -03:00
|
|
|
if (!authorized) {
|
|
|
|
current_error = ErrorInfos () {
|
|
|
|
message = _("Authentication failed")
|
|
|
|
};
|
|
|
|
}
|
2015-08-21 11:01:02 -03:00
|
|
|
return authorized;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void start_get_authorization (GLib.BusName sender) {
|
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
get_authorization_finished (authorized);
|
|
|
|
});
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
|
|
|
|
2015-03-04 11:55:36 -03:00
|
|
|
public void start_write_pamac_config (HashTable<string,Variant> new_pamac_conf, GLib.BusName sender) {
|
2015-08-21 11:01:02 -03:00
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
2016-04-14 13:19:20 -03:00
|
|
|
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
2015-08-21 11:01:02 -03:00
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
if (authorized ) {
|
|
|
|
pamac_config.write (new_pamac_conf);
|
|
|
|
pamac_config.reload ();
|
|
|
|
}
|
2015-08-24 11:13:18 -03:00
|
|
|
write_pamac_config_finished (pamac_config.recurse, pamac_config.refresh_period, pamac_config.no_update_hide_icon,
|
2017-09-09 12:25:24 -03:00
|
|
|
pamac_config.enable_aur, pamac_config.aur_build_dir, pamac_config.check_aur_updates);
|
2015-08-21 11:01:02 -03:00
|
|
|
});
|
2014-12-30 11:04:40 -03:00
|
|
|
}
|
|
|
|
|
2017-03-22 12:32:12 -03:00
|
|
|
private void write_alpm_config () {
|
|
|
|
alpm_config.write (new_alpm_conf);
|
|
|
|
alpm_config.reload ();
|
|
|
|
refresh_handle ();
|
|
|
|
write_alpm_config_finished ((alpm_handle.checkspace == 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void start_write_alpm_config (HashTable<string,Variant> new_alpm_conf_, GLib.BusName sender) {
|
2015-08-21 11:01:02 -03:00
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
if (authorized ) {
|
2017-03-22 12:32:12 -03:00
|
|
|
new_alpm_conf = new_alpm_conf_;
|
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (write_alpm_config));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
write_alpm_config_finished ((alpm_handle.checkspace == 1));
|
2015-08-21 11:01:02 -03:00
|
|
|
}
|
|
|
|
});
|
2014-12-30 11:04:40 -03:00
|
|
|
}
|
|
|
|
|
2016-08-24 09:53:39 -03:00
|
|
|
private void generate_mirrors_list () {
|
2014-12-30 11:04:40 -03:00
|
|
|
try {
|
2016-08-24 09:53:39 -03:00
|
|
|
var process = new Subprocess.newv (
|
|
|
|
{"pacman-mirrors", "-g"},
|
|
|
|
SubprocessFlags.STDOUT_PIPE | SubprocessFlags.STDERR_MERGE);
|
|
|
|
var dis = new DataInputStream (process.get_stdout_pipe ());
|
|
|
|
string? line;
|
|
|
|
while ((line = dis.read_line ()) != null) {
|
|
|
|
generate_mirrors_list_data (line);
|
|
|
|
}
|
|
|
|
} catch (Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
2014-12-30 11:04:40 -03:00
|
|
|
}
|
2017-09-12 13:50:39 -03:00
|
|
|
alpm_config.reload ();
|
2017-09-09 04:43:18 -03:00
|
|
|
refresh_handle ();
|
2016-08-24 10:25:58 -03:00
|
|
|
generate_mirrors_list_finished ();
|
2014-12-30 11:04:40 -03:00
|
|
|
}
|
|
|
|
|
2016-08-25 07:33:16 -03:00
|
|
|
public void start_generate_mirrors_list (GLib.BusName sender) {
|
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
if (authorized) {
|
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (generate_mirrors_list));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-22 06:03:37 -03:00
|
|
|
public void clean_cache (uint64 keep_nb, bool only_uninstalled, GLib.BusName sender) {
|
2016-08-25 07:33:16 -03:00
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
if (authorized) {
|
2017-09-22 06:03:37 -03:00
|
|
|
string[] commands = {"paccache", "--nocolor", "-rq"};
|
|
|
|
commands += "-k%llu".printf (keep_nb);
|
2016-08-25 07:33:16 -03:00
|
|
|
if (only_uninstalled) {
|
|
|
|
commands += "-u";
|
|
|
|
}
|
|
|
|
try {
|
2016-08-27 11:24:46 -03:00
|
|
|
new Subprocess.newv (
|
2016-08-25 07:33:16 -03:00
|
|
|
commands,
|
2016-08-27 11:24:46 -03:00
|
|
|
SubprocessFlags.STDOUT_SILENCE | SubprocessFlags.STDERR_SILENCE);
|
2016-08-25 07:33:16 -03:00
|
|
|
} catch (Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-12-30 11:04:40 -03:00
|
|
|
}
|
|
|
|
|
2015-03-04 11:55:36 -03:00
|
|
|
public void start_write_mirrors_config (HashTable<string,Variant> new_mirrors_conf, GLib.BusName sender) {
|
2015-08-21 11:01:02 -03:00
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
2017-07-29 10:35:04 -04:00
|
|
|
var mirrors_config = new MirrorsConfig ("/etc/pacman-mirrors.conf");
|
2015-08-21 11:01:02 -03:00
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
if (authorized) {
|
|
|
|
mirrors_config.write (new_mirrors_conf);
|
|
|
|
mirrors_config.reload ();
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
write_mirrors_config_finished (mirrors_config.choosen_country, mirrors_config.choosen_generation_method);
|
2015-08-21 11:01:02 -03:00
|
|
|
});
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
|
|
|
|
2015-03-04 11:55:36 -03:00
|
|
|
public void start_set_pkgreason (string pkgname, uint reason, GLib.BusName sender) {
|
2015-08-21 11:01:02 -03:00
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
if (authorized) {
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (pkgname);
|
2015-08-21 11:01:02 -03:00
|
|
|
if (pkg != null) {
|
2017-07-29 10:35:04 -04:00
|
|
|
// lock the database
|
|
|
|
if (alpm_handle.trans_init (0) == 0) {
|
|
|
|
pkg.reason = (Alpm.Package.Reason) reason;
|
|
|
|
alpm_handle.trans_release ();
|
|
|
|
}
|
2015-02-01 14:01:03 -03:00
|
|
|
}
|
2015-08-21 11:01:02 -03:00
|
|
|
}
|
2015-04-11 13:00:49 -03:00
|
|
|
set_pkgreason_finished ();
|
2015-08-21 11:01:02 -03:00
|
|
|
});
|
2014-11-08 13:50:35 -03:00
|
|
|
}
|
|
|
|
|
2017-06-03 08:46:08 -04:00
|
|
|
private bool update_dbs (Alpm.Handle handle, int force) {
|
|
|
|
bool success = false;
|
|
|
|
unowned Alpm.List<unowned Alpm.DB> syncdbs = handle.syncdbs;
|
|
|
|
while (syncdbs != null) {
|
|
|
|
if (cancellable.is_cancelled ()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unowned Alpm.DB db = syncdbs.data;
|
|
|
|
if (db.update (force) >= 0) {
|
2017-08-04 09:57:42 -04: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
|
2017-06-03 08:46:08 -04:00
|
|
|
success = true;
|
|
|
|
} else {
|
|
|
|
Alpm.Errno errno = handle.errno ();
|
|
|
|
current_error.errno = (uint) errno;
|
|
|
|
if (errno != 0) {
|
|
|
|
// download error details are set in cb_fetch
|
|
|
|
if (errno != Alpm.Errno.EXTERNAL_DOWNLOAD) {
|
|
|
|
current_error.details = { Alpm.strerror (errno) };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
syncdbs.next ();
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2015-08-20 10:11:18 -03:00
|
|
|
private void refresh () {
|
2017-03-06 16:58:30 -03:00
|
|
|
current_error = ErrorInfos ();
|
2016-05-13 10:44:10 -03:00
|
|
|
write_log_file ("synchronizing package lists");
|
2016-02-22 09:47:40 -03:00
|
|
|
cancellable.reset ();
|
2017-06-03 08:46:08 -04:00
|
|
|
int force = (force_refresh) ? 1 : 0;
|
2017-08-22 06:11:31 -03:00
|
|
|
// try to copy refresh dbs in tmp
|
|
|
|
string tmp_dbpath = "/tmp/pamac-checkdbs";
|
|
|
|
try {
|
|
|
|
Process.spawn_command_line_sync ("cp -au %s/sync %s".printf (tmp_dbpath, alpm_handle.dbpath));
|
|
|
|
} catch (SpawnError e) {
|
|
|
|
stderr.printf ("SpawnError: %s\n", e.message);
|
|
|
|
}
|
2017-09-07 03:44:43 -03:00
|
|
|
// a new handle is required to use copied databases
|
|
|
|
refresh_handle ();
|
2017-06-03 08:46:08 -04:00
|
|
|
// update ".db"
|
|
|
|
bool success = update_dbs (alpm_handle, force);
|
|
|
|
if (cancellable.is_cancelled ()) {
|
|
|
|
refresh_finished (false);
|
|
|
|
return;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2017-08-22 06:11:31 -03:00
|
|
|
// update ".files", do not need to know if we succeeded
|
|
|
|
update_dbs (files_handle, force);
|
|
|
|
if (cancellable.is_cancelled ()) {
|
|
|
|
refresh_finished (false);
|
|
|
|
} else if (success) {
|
2017-07-29 10:35:04 -04:00
|
|
|
refreshed = true;
|
2016-02-02 05:28:07 -03:00
|
|
|
refresh_finished (true);
|
2017-06-03 08:46:08 -04:00
|
|
|
} else {
|
|
|
|
current_error.message = _("Failed to synchronize any databases");
|
|
|
|
refresh_finished (false);
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
public void start_refresh (bool force, GLib.BusName sender) {
|
|
|
|
if (lock_id != sender) {
|
2017-07-31 08:15:36 -04:00
|
|
|
refresh_finished (false);
|
2017-07-29 10:35:04 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
force_refresh = force;
|
2017-07-29 10:35:04 -04:00
|
|
|
if (force_refresh) {
|
|
|
|
refreshed = false;
|
|
|
|
}
|
|
|
|
if (refreshed) {
|
|
|
|
refresh_finished (true);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (refresh));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private void add_ignorepkgs () {
|
|
|
|
foreach (unowned string pkgname in temporary_ignorepkgs) {
|
|
|
|
alpm_handle.add_ignorepkg (pkgname);
|
|
|
|
}
|
2015-04-11 13:00:49 -03:00
|
|
|
}
|
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private void remove_ignorepkgs () {
|
|
|
|
foreach (unowned string pkgname in temporary_ignorepkgs) {
|
|
|
|
alpm_handle.remove_ignorepkg (pkgname);
|
|
|
|
}
|
|
|
|
temporary_ignorepkgs = {};
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
private AlpmPackage initialise_pkg_struct (Alpm.Package? alpm_pkg) {
|
|
|
|
if (alpm_pkg != null) {
|
|
|
|
string repo_name = "";
|
|
|
|
if (alpm_pkg.origin == Alpm.Package.From.LOCALDB) {
|
|
|
|
unowned Alpm.Package? sync_pkg = get_syncpkg (alpm_pkg.name);
|
|
|
|
if (sync_pkg != null) {
|
|
|
|
repo_name = sync_pkg.db.name;
|
|
|
|
}
|
|
|
|
} else if (alpm_pkg.origin == Alpm.Package.From.SYNCDB) {
|
|
|
|
repo_name = alpm_pkg.db.name;
|
|
|
|
}
|
|
|
|
return AlpmPackage () {
|
|
|
|
name = alpm_pkg.name,
|
2017-09-09 05:23:59 -03:00
|
|
|
app_name = "",
|
2016-04-14 13:19:20 -03:00
|
|
|
version = alpm_pkg.version,
|
|
|
|
// desc can be null
|
2016-04-16 04:43:14 -03:00
|
|
|
desc = alpm_pkg.desc ?? "",
|
2016-04-14 13:19:20 -03:00
|
|
|
repo = (owned) repo_name,
|
|
|
|
size = alpm_pkg.isize,
|
2017-09-09 05:23:59 -03:00
|
|
|
origin = (uint) alpm_pkg.origin,
|
|
|
|
icon = ""
|
2016-04-14 13:19:20 -03:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return AlpmPackage () {
|
|
|
|
name = "",
|
2017-09-09 05:23:59 -03:00
|
|
|
app_name = "",
|
2016-04-14 13:19:20 -03:00
|
|
|
version = "",
|
|
|
|
desc = "",
|
2017-09-09 05:23:59 -03:00
|
|
|
repo = "",
|
|
|
|
icon = ""
|
2016-04-14 13:19:20 -03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private unowned Alpm.Package? get_syncpkg (string name) {
|
|
|
|
unowned Alpm.Package? pkg = null;
|
|
|
|
unowned Alpm.List<unowned Alpm.DB> syncdbs = alpm_handle.syncdbs;
|
|
|
|
while (syncdbs != null) {
|
|
|
|
unowned Alpm.DB db = syncdbs.data;
|
|
|
|
pkg = db.get_pkg (name);
|
|
|
|
if (pkg != null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
syncdbs.next ();
|
|
|
|
}
|
|
|
|
return pkg;
|
|
|
|
}
|
|
|
|
|
2017-02-24 07:20:56 -03:00
|
|
|
private AURPackage initialise_aur_struct (Json.Object json_object) {
|
2017-07-29 10:35:04 -04:00
|
|
|
string installed_version = "";
|
|
|
|
unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (json_object.get_string_member ("Name"));
|
|
|
|
if (pkg != null) {
|
|
|
|
installed_version = pkg.version;
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
return AURPackage () {
|
|
|
|
name = json_object.get_string_member ("Name"),
|
|
|
|
version = json_object.get_string_member ("Version"),
|
2017-07-29 10:35:04 -04:00
|
|
|
installed_version = (owned) installed_version,
|
2016-04-14 13:19:20 -03:00
|
|
|
// desc can be null
|
2016-04-16 04:43:14 -03:00
|
|
|
desc = json_object.get_null_member ("Description") ? "" : json_object.get_string_member ("Description"),
|
2016-04-14 13:19:20 -03:00
|
|
|
popularity = json_object.get_double_member ("Popularity")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-02-18 13:10:26 -03:00
|
|
|
private async void compute_aur_build_list (string[] aur_list) {
|
|
|
|
try {
|
|
|
|
Process.spawn_command_line_sync ("mkdir -p %s".printf (aurdb_path));
|
|
|
|
} catch (SpawnError e) {
|
|
|
|
stderr.printf ("SpawnError: %s\n", e.message);
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
aur_desc_list.remove_all ();
|
|
|
|
already_checked_aur_dep.remove_all ();
|
|
|
|
yield check_aur_dep_list (aur_list);
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
|
|
|
|
2017-02-18 13:10:26 -03:00
|
|
|
private async void check_aur_dep_list (string[] pkgnames) {
|
|
|
|
string[] dep_types = {"Depends", "MakeDepends", "CheckDepends"};
|
|
|
|
string[] dep_to_check = {};
|
|
|
|
Json.Array results = yield AUR.multiinfo (pkgnames);
|
|
|
|
results.foreach_element ((array, index, node) => {
|
|
|
|
unowned Json.Object? pkg_info = node.get_object ();
|
|
|
|
// create fake db desc file
|
|
|
|
if (pkg_info != null) {
|
|
|
|
string name = pkg_info.get_string_member ("Name");
|
|
|
|
string version = pkg_info.get_string_member ("Version");
|
|
|
|
string pkgdir = "%s-%s".printf (name, version);
|
|
|
|
string pkgdir_path = "%s/%s".printf (aurdb_path, pkgdir);
|
|
|
|
aur_desc_list.add (pkgdir);
|
|
|
|
already_checked_aur_dep.add (name);
|
|
|
|
try {
|
|
|
|
var file = GLib.File.new_for_path (pkgdir_path);
|
|
|
|
bool write_desc_file = false;
|
|
|
|
if (!file.query_exists ()) {
|
|
|
|
file.make_directory ();
|
|
|
|
write_desc_file = true;
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
// compute depends, makedepends and checkdepends in DEPENDS
|
|
|
|
var depends = new StringBuilder ();
|
|
|
|
foreach (unowned string dep_type in dep_types) {
|
|
|
|
unowned Json.Node? dep_node = pkg_info.get_member (dep_type);
|
|
|
|
if (dep_node != null) {
|
|
|
|
dep_node.get_array ().foreach_element ((array, index, node) => {
|
|
|
|
if (write_desc_file) {
|
|
|
|
depends.append (node.get_string ());
|
|
|
|
depends.append ("\n");
|
|
|
|
}
|
|
|
|
// check deps
|
|
|
|
unowned string dep_string = node.get_string ();
|
2017-07-29 10:35:04 -04:00
|
|
|
string dep_name = Alpm.Depend.from_string (dep_string).name;
|
2017-02-18 13:10:26 -03:00
|
|
|
unowned Alpm.Package? pkg = null;
|
|
|
|
// search for the name first to avoid provides trouble
|
|
|
|
pkg = alpm_handle.localdb.get_pkg (dep_name);
|
|
|
|
if (pkg == null) {
|
|
|
|
pkg = get_syncpkg (dep_name);
|
|
|
|
}
|
|
|
|
if (pkg == null) {
|
|
|
|
if (!(dep_name in already_checked_aur_dep)) {
|
|
|
|
dep_to_check += (owned) dep_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
if (write_desc_file) {
|
|
|
|
file = GLib.File.new_for_path ("%s/desc".printf (pkgdir_path));
|
|
|
|
// creating a DataOutputStream to the file
|
|
|
|
var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION));
|
|
|
|
// fake filename
|
|
|
|
dos.put_string ("%FILENAME%\n" + "%s-%s-any.pkg.tar.xz\n\n".printf (name, version));
|
|
|
|
// name
|
|
|
|
dos.put_string ("%NAME%\n%s\n\n".printf (name));
|
|
|
|
// version
|
|
|
|
dos.put_string ("%VERSION%\n%s\n\n".printf (version));
|
|
|
|
//base
|
|
|
|
dos.put_string ("%BASE%\n%s\n\n".printf (pkg_info.get_string_member ("PackageBase")));
|
|
|
|
// desc can be null
|
|
|
|
if (!pkg_info.get_null_member ("Description")) {
|
|
|
|
dos.put_string ("%DESC%\n%s\n\n".printf (pkg_info.get_string_member ("Description")));
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
// version
|
|
|
|
dos.put_string ("%VERSION%\n%s\n\n".printf (pkg_info.get_string_member ("Version")));
|
|
|
|
// fake arch
|
|
|
|
dos.put_string ("%ARCH%\nany\n\n");
|
|
|
|
// depends
|
|
|
|
if (depends.len > 0) {
|
|
|
|
dos.put_string ("%DEPENDS%\n%s\n".printf (depends.str));
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
// conflicts
|
|
|
|
unowned Json.Node? info_node = pkg_info.get_member ("Conflicts");
|
|
|
|
if (info_node != null) {
|
|
|
|
try {
|
|
|
|
dos.put_string ("%CONFLICTS%\n");
|
|
|
|
info_node.get_array ().foreach_element ((array, index, _node) => {
|
|
|
|
try {
|
|
|
|
dos.put_string ("%s\n".printf (_node.get_string ()));
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dos.put_string ("\n");
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
// provides
|
|
|
|
info_node = pkg_info.get_member ("Provides");
|
|
|
|
if (info_node != null) {
|
|
|
|
try {
|
|
|
|
dos.put_string ("%PROVIDES%\n");
|
|
|
|
info_node.get_array ().foreach_element ((array, index, _node) => {
|
|
|
|
try {
|
|
|
|
dos.put_string ("%s\n".printf (_node.get_string ()));
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dos.put_string ("\n");
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// replaces
|
|
|
|
info_node = pkg_info.get_member ("Replaces");
|
|
|
|
if (info_node != null) {
|
|
|
|
try {
|
|
|
|
dos.put_string ("%REPLACES%\n");
|
|
|
|
info_node.get_array ().foreach_element ((array, index, _node) => {
|
|
|
|
try {
|
|
|
|
dos.put_string ("%s\n".printf (_node.get_string ()));
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dos.put_string ("\n");
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
} catch (GLib.Error e) {
|
|
|
|
GLib.stderr.printf("%s\n", e.message);
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
});
|
|
|
|
if (dep_to_check.length > 0) {
|
|
|
|
yield check_aur_dep_list (dep_to_check);
|
2016-04-14 13:19:20 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-22 12:32:12 -03:00
|
|
|
private void get_updates () {
|
2017-07-29 10:35:04 -04:00
|
|
|
AlpmPackage[] updates_infos = {};
|
2015-03-04 11:55:36 -03:00
|
|
|
unowned Alpm.Package? pkg = null;
|
|
|
|
unowned Alpm.Package? candidate = null;
|
2016-04-14 13:19:20 -03:00
|
|
|
foreach (unowned string name in alpm_config.get_syncfirsts ()) {
|
|
|
|
pkg = Alpm.find_satisfier (alpm_handle.localdb.pkgcache, name);
|
2015-03-04 11:55:36 -03:00
|
|
|
if (pkg != null) {
|
2016-04-14 13:19:20 -03:00
|
|
|
candidate = pkg.sync_newversion (alpm_handle.syncdbs);
|
2015-03-04 11:55:36 -03:00
|
|
|
if (candidate != null) {
|
2017-07-29 10:35:04 -04:00
|
|
|
var infos = initialise_pkg_struct (candidate);
|
|
|
|
infos.installed_version = pkg.version;
|
2016-02-02 05:28:07 -03:00
|
|
|
updates_infos += (owned) infos;
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updates_infos.length != 0) {
|
2016-02-02 05:28:07 -03:00
|
|
|
var updates = Updates () {
|
|
|
|
is_syncfirst = true,
|
|
|
|
repos_updates = (owned) updates_infos,
|
|
|
|
aur_updates = {}
|
|
|
|
};
|
|
|
|
get_updates_finished (updates);
|
2014-10-30 10:44:09 -03:00
|
|
|
} else {
|
2015-03-04 11:55:36 -03:00
|
|
|
string[] local_pkgs = {};
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<unowned Alpm.Package> pkgcache = alpm_handle.localdb.pkgcache;
|
|
|
|
while (pkgcache != null) {
|
|
|
|
unowned Alpm.Package installed_pkg = pkgcache.data;
|
2015-04-11 13:00:49 -03:00
|
|
|
// check if installed_pkg is in IgnorePkg or IgnoreGroup
|
2016-04-14 13:19:20 -03:00
|
|
|
if (alpm_handle.should_ignore (installed_pkg) == 0) {
|
|
|
|
candidate = installed_pkg.sync_newversion (alpm_handle.syncdbs);
|
2015-03-04 11:55:36 -03:00
|
|
|
if (candidate != null) {
|
2017-07-29 10:35:04 -04:00
|
|
|
var infos = initialise_pkg_struct (candidate);
|
|
|
|
infos.installed_version = installed_pkg.version;
|
2016-02-02 05:28:07 -03:00
|
|
|
updates_infos += (owned) infos;
|
2015-03-04 11:55:36 -03:00
|
|
|
} else {
|
2017-07-29 10:35:04 -04:00
|
|
|
if (check_aur_updates && (!aur_updates_checked)) {
|
2015-04-11 13:00:49 -03:00
|
|
|
// check if installed_pkg is a local pkg
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<unowned Alpm.DB> syncdbs = alpm_handle.syncdbs;
|
|
|
|
while (syncdbs != null) {
|
|
|
|
unowned Alpm.DB db = syncdbs.data;
|
2015-04-11 13:00:49 -03:00
|
|
|
pkg = Alpm.find_satisfier (db.pkgcache, installed_pkg.name);
|
2015-03-04 11:55:36 -03:00
|
|
|
if (pkg != null) {
|
|
|
|
break;
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
syncdbs.next ();
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
|
|
|
if (pkg == null) {
|
2015-04-11 13:00:49 -03:00
|
|
|
local_pkgs += installed_pkg.name;
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
pkgcache.next ();
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
if (check_aur_updates) {
|
2015-03-27 12:31:07 -03:00
|
|
|
// get aur updates
|
2017-07-29 10:35:04 -04:00
|
|
|
if (!aur_updates_checked) {
|
2016-04-14 13:19:20 -03:00
|
|
|
AUR.multiinfo.begin (local_pkgs, (obj, res) => {
|
|
|
|
aur_updates_results = AUR.multiinfo.end (res);
|
2017-07-29 10:35:04 -04:00
|
|
|
aur_updates_checked = true;
|
2016-04-14 13:19:20 -03:00
|
|
|
var updates = Updates () {
|
|
|
|
is_syncfirst = false,
|
|
|
|
repos_updates = (owned) updates_infos,
|
|
|
|
aur_updates = get_aur_updates_infos ()
|
2016-02-02 05:28:07 -03:00
|
|
|
};
|
2016-04-14 13:19:20 -03:00
|
|
|
get_updates_finished (updates);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
var updates = Updates () {
|
|
|
|
is_syncfirst = false,
|
|
|
|
repos_updates = (owned) updates_infos,
|
|
|
|
aur_updates = get_aur_updates_infos ()
|
|
|
|
};
|
|
|
|
get_updates_finished (updates);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var updates = Updates () {
|
|
|
|
is_syncfirst = false,
|
|
|
|
repos_updates = (owned) updates_infos,
|
|
|
|
aur_updates = {}
|
|
|
|
};
|
|
|
|
get_updates_finished (updates);
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
private AURPackage[] get_aur_updates_infos () {
|
|
|
|
AURPackage[] aur_updates_infos = {};
|
2016-04-14 13:19:20 -03:00
|
|
|
aur_updates_results.foreach_element ((array, index, node) => {
|
|
|
|
unowned Json.Object pkg_info = node.get_object ();
|
|
|
|
unowned string name = pkg_info.get_string_member ("Name");
|
|
|
|
unowned string new_version = pkg_info.get_string_member ("Version");
|
|
|
|
unowned string old_version = alpm_handle.localdb.get_pkg (name).version;
|
|
|
|
if (Alpm.pkg_vercmp (new_version, old_version) == 1) {
|
2017-07-29 10:35:04 -04:00
|
|
|
var infos = initialise_aur_struct (pkg_info);
|
|
|
|
infos.installed_version = old_version;
|
2016-04-14 13:19:20 -03:00
|
|
|
aur_updates_infos += (owned) infos;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return aur_updates_infos;
|
|
|
|
}
|
|
|
|
|
2017-03-22 12:32:12 -03:00
|
|
|
public void start_get_updates (bool check_aur_updates_) {
|
|
|
|
check_aur_updates = check_aur_updates_;
|
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (get_updates));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private bool trans_init (Alpm.TransFlag flags) {
|
2017-03-06 16:58:30 -03:00
|
|
|
current_error = ErrorInfos ();
|
2016-02-22 09:47:40 -03:00
|
|
|
cancellable.reset ();
|
2016-08-27 09:51:34 -03:00
|
|
|
if (alpm_handle.trans_init (flags) == -1) {
|
2016-04-14 13:19:20 -03:00
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
2016-03-01 11:43:51 -03:00
|
|
|
current_error.errno = (uint) errno;
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to init transaction");
|
2016-08-24 12:19:14 -03:00
|
|
|
if (errno != 0) {
|
|
|
|
current_error.details = { Alpm.strerror (errno) };
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return false;
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return true;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private void sysupgrade_prepare () {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error = ErrorInfos ();
|
2017-02-18 13:10:26 -03:00
|
|
|
bool success = trans_init (0);
|
|
|
|
if (success) {
|
|
|
|
add_ignorepkgs ();
|
|
|
|
if (alpm_handle.trans_sysupgrade ((enable_downgrade) ? 1 : 0) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
|
|
|
current_error.errno = (uint) errno;
|
|
|
|
current_error.message = _("Failed to prepare transaction");
|
|
|
|
if (errno != 0) {
|
|
|
|
current_error.details = { Alpm.strerror (errno) };
|
|
|
|
}
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2017-02-18 13:10:26 -03:00
|
|
|
success = false;
|
2016-11-02 10:23:52 -03:00
|
|
|
} else {
|
2017-02-18 13:10:26 -03:00
|
|
|
success = trans_prepare_real ();
|
2016-11-02 10:23:52 -03:00
|
|
|
}
|
2016-08-27 09:51:34 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
trans_prepare_finished (success);
|
2016-08-27 09:51:34 -03:00
|
|
|
}
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
public void start_sysupgrade_prepare (bool enable_downgrade_, string[] temporary_ignorepkgs_, GLib.BusName sender) {
|
|
|
|
if (lock_id != sender) {
|
2017-07-31 08:15:36 -04:00
|
|
|
trans_prepare_finished (false);
|
2017-07-29 10:35:04 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-08-27 09:51:34 -03:00
|
|
|
enable_downgrade = enable_downgrade_;
|
|
|
|
temporary_ignorepkgs = temporary_ignorepkgs_;
|
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (sysupgrade_prepare));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
|
2016-02-02 05:28:07 -03:00
|
|
|
private bool trans_add_pkg_real (Alpm.Package pkg) {
|
|
|
|
current_error = ErrorInfos ();
|
2016-04-14 13:19:20 -03:00
|
|
|
if (alpm_handle.trans_add_pkg (pkg) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
2016-02-02 05:28:07 -03:00
|
|
|
if (errno == Alpm.Errno.TRANS_DUP_TARGET || errno == Alpm.Errno.PKG_IGNORED) {
|
2014-10-22 13:44:02 -03:00
|
|
|
// just skip duplicate or ignored targets
|
2016-02-02 05:28:07 -03:00
|
|
|
return true;
|
2015-02-01 14:01:03 -03:00
|
|
|
} else {
|
2016-03-01 11:43:51 -03:00
|
|
|
current_error.errno = (uint) errno;
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to prepare transaction");
|
2016-08-24 12:19:14 -03:00
|
|
|
if (errno != 0) {
|
|
|
|
current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) };
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return false;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return true;
|
2015-01-28 12:37:51 -03:00
|
|
|
}
|
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private bool trans_add_pkg (string pkgname) {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error = ErrorInfos ();
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.Package? pkg = get_syncpkg (pkgname);
|
2015-05-20 09:48:12 -03:00
|
|
|
if (pkg == null) {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to prepare transaction");
|
|
|
|
current_error.details = { _("target not found: %s").printf (pkgname) };
|
|
|
|
return false;
|
2015-01-28 12:37:51 -03:00
|
|
|
} else {
|
2016-02-02 05:28:07 -03:00
|
|
|
bool success = trans_add_pkg_real (pkg);
|
|
|
|
if (success) {
|
2015-06-20 13:28:22 -03:00
|
|
|
if (("linux31" in pkg.name) || ("linux4" in pkg.name)) {
|
2015-01-28 12:37:51 -03:00
|
|
|
string[] installed_kernels = {};
|
|
|
|
string[] installed_modules = {};
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<unowned Alpm.Package> pkgcache = alpm_handle.localdb.pkgcache;
|
|
|
|
while (pkgcache != null) {
|
|
|
|
unowned Alpm.Package local_pkg = pkgcache.data;
|
2015-06-20 13:28:22 -03:00
|
|
|
if (("linux31" in local_pkg.name) || ("linux4" in local_pkg.name)) {
|
2015-01-28 12:37:51 -03:00
|
|
|
string[] local_pkg_splitted = local_pkg.name.split ("-", 2);
|
|
|
|
if ((local_pkg_splitted[0] in installed_kernels) == false) {
|
|
|
|
installed_kernels += local_pkg_splitted[0];
|
|
|
|
}
|
|
|
|
if (local_pkg_splitted.length == 2) {
|
|
|
|
if ((local_pkg_splitted[1] in installed_modules) == false) {
|
|
|
|
installed_modules += local_pkg_splitted[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
pkgcache.next ();
|
2015-01-28 12:37:51 -03:00
|
|
|
}
|
|
|
|
string[] splitted = pkg.name.split ("-", 2);
|
|
|
|
if (splitted.length == 2) {
|
|
|
|
// we are adding a module
|
|
|
|
// add the same module for other installed kernels
|
2016-02-02 05:28:07 -03:00
|
|
|
foreach (unowned string installed_kernel in installed_kernels) {
|
2015-01-28 12:37:51 -03:00
|
|
|
string module = installed_kernel + "-" + splitted[1];
|
2017-08-04 09:10:43 -04:00
|
|
|
unowned Alpm.Package? installed_module_pkg = alpm_handle.localdb.get_pkg (module);
|
|
|
|
if (installed_module_pkg == null) {
|
|
|
|
unowned Alpm.Package? module_pkg = get_syncpkg (module);
|
|
|
|
if (module_pkg != null) {
|
|
|
|
trans_add_pkg_real (module_pkg);
|
|
|
|
}
|
2015-01-28 12:37:51 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (splitted.length == 1) {
|
|
|
|
// we are adding a kernel
|
2015-06-20 13:28:22 -03:00
|
|
|
// add all installed modules for other kernels
|
2016-02-02 05:28:07 -03:00
|
|
|
foreach (unowned string installed_module in installed_modules) {
|
2015-01-28 12:37:51 -03:00
|
|
|
string module = splitted[0] + "-" + installed_module;
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.Package? module_pkg = get_syncpkg (module);
|
2015-01-28 12:37:51 -03:00
|
|
|
if (module_pkg != null) {
|
|
|
|
trans_add_pkg_real (module_pkg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return success;
|
2015-01-28 12:37:51 -03:00
|
|
|
}
|
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private bool trans_load_pkg (string pkgpath) {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error = ErrorInfos ();
|
2016-04-14 13:19:20 -03:00
|
|
|
Alpm.Package* pkg;
|
|
|
|
if (alpm_handle.load_tarball (pkgpath, 1, alpm_handle.localfilesiglevel, out pkg) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
2016-03-01 11:43:51 -03:00
|
|
|
current_error.errno = (uint) errno;
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to prepare transaction");
|
2016-08-24 12:19:14 -03:00
|
|
|
if (errno != 0) {
|
|
|
|
current_error.details = { "%s: %s".printf (pkgpath, Alpm.strerror (errno)) };
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return false;
|
2016-04-14 13:19:20 -03:00
|
|
|
} else if (alpm_handle.trans_add_pkg (pkg) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
2017-03-06 16:58:30 -03:00
|
|
|
if (errno == Alpm.Errno.TRANS_DUP_TARGET || errno == Alpm.Errno.PKG_IGNORED) {
|
|
|
|
// just skip duplicate or ignored targets
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
current_error.errno = (uint) errno;
|
|
|
|
current_error.message = _("Failed to prepare transaction");
|
|
|
|
if (errno != 0) {
|
|
|
|
current_error.details = { "%s: %s".printf (pkg->name, Alpm.strerror (errno)) };
|
|
|
|
}
|
|
|
|
// free the package because it will not be used
|
|
|
|
delete pkg;
|
|
|
|
return false;
|
2016-08-24 12:19:14 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return true;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private bool trans_remove_pkg (string pkgname) {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error = ErrorInfos ();
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (pkgname);
|
2014-10-30 10:44:09 -03:00
|
|
|
if (pkg == null) {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to prepare transaction");
|
|
|
|
current_error.details = { _("target not found: %s").printf (pkgname) };
|
|
|
|
return false;
|
2016-04-14 13:19:20 -03:00
|
|
|
} else if (alpm_handle.trans_remove_pkg (pkg) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
2017-03-06 16:58:30 -03:00
|
|
|
if (errno == Alpm.Errno.TRANS_DUP_TARGET) {
|
|
|
|
// just skip duplicate targets
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
current_error.errno = (uint) errno;
|
|
|
|
current_error.message = _("Failed to prepare transaction");
|
|
|
|
if (errno != 0) {
|
|
|
|
current_error.details = { "%s: %s".printf (pkg.name, Alpm.strerror (errno)) };
|
|
|
|
}
|
|
|
|
return false;
|
2016-08-24 12:19:14 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
return true;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2017-02-18 13:10:26 -03:00
|
|
|
private bool trans_prepare_real () {
|
|
|
|
bool success = true;
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error = ErrorInfos ();
|
2015-08-20 10:11:18 -03:00
|
|
|
string[] details = {};
|
2016-04-14 13:19:20 -03:00
|
|
|
Alpm.List err_data;
|
|
|
|
if (alpm_handle.trans_prepare (out err_data) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
2016-03-01 11:43:51 -03:00
|
|
|
current_error.errno = (uint) errno;
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to prepare transaction");
|
2015-08-20 10:11:18 -03:00
|
|
|
switch (errno) {
|
2016-08-24 12:19:14 -03:00
|
|
|
case 0:
|
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Errno.PKG_INVALID_ARCH:
|
2016-08-24 12:19:14 -03:00
|
|
|
details += Alpm.strerror (errno) + ":";
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<string*> list = err_data;
|
|
|
|
while (list != null) {
|
|
|
|
string* pkgname = list.data;
|
2015-08-20 10:11:18 -03:00
|
|
|
details += _("package %s does not have a valid architecture").printf (pkgname);
|
|
|
|
delete pkgname;
|
2016-04-14 13:19:20 -03:00
|
|
|
list.next ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Errno.UNSATISFIED_DEPS:
|
2016-08-24 12:19:14 -03:00
|
|
|
details += Alpm.strerror (errno) + ":";
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<Alpm.DepMissing*> list = err_data;
|
|
|
|
while (list != null) {
|
|
|
|
Alpm.DepMissing* miss = list.data;
|
2017-02-18 13:10:26 -03:00
|
|
|
string depstring = miss->depend.compute_string ();
|
|
|
|
unowned Alpm.List<unowned Alpm.Package> trans_add = alpm_handle.trans_to_add ();
|
|
|
|
unowned Alpm.Package pkg;
|
|
|
|
string detail;
|
|
|
|
if (miss->causingpkg == null) {
|
|
|
|
/* package being installed/upgraded has unresolved dependency */
|
2017-07-29 10:35:04 -04:00
|
|
|
detail = _("unable to satisfy dependency '%s' required by %s").printf (depstring, miss->target);
|
2017-02-18 13:10:26 -03:00
|
|
|
} else if ((pkg = Alpm.pkg_find (trans_add, miss->causingpkg)) != null) {
|
|
|
|
/* upgrading a package breaks a local dependency */
|
2017-07-29 10:35:04 -04:00
|
|
|
detail = _("installing %s (%s) breaks dependency '%s' required by %s").printf (miss->causingpkg, pkg.version, depstring, miss->target);
|
2017-02-18 13:10:26 -03:00
|
|
|
} else {
|
|
|
|
/* removing a package breaks a local dependency */
|
2017-07-29 10:35:04 -04:00
|
|
|
detail = _("removing %s breaks dependency '%s' required by %s").printf (miss->causingpkg, depstring, miss->target);
|
2017-02-18 13:10:26 -03:00
|
|
|
}
|
|
|
|
if (!(detail in details)) {
|
|
|
|
details += detail;
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
delete miss;
|
2016-04-14 13:19:20 -03:00
|
|
|
list.next ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Errno.CONFLICTING_DEPS:
|
2016-08-24 12:19:14 -03:00
|
|
|
details += Alpm.strerror (errno) + ":";
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<Alpm.Conflict*> list = err_data;
|
|
|
|
while (list != null) {
|
|
|
|
Alpm.Conflict* conflict = list.data;
|
2016-02-02 05:28:07 -03:00
|
|
|
string conflict_detail = _("%s and %s are in conflict").printf (conflict->package1, conflict->package2);
|
2015-08-20 10:11:18 -03:00
|
|
|
// only print reason if it contains new information
|
2016-02-02 05:28:07 -03:00
|
|
|
if (conflict->reason.mod != Alpm.Depend.Mode.ANY) {
|
|
|
|
conflict_detail += " (%s)".printf (conflict->reason.compute_string ());
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
details += (owned) conflict_detail;
|
2015-08-20 10:11:18 -03:00
|
|
|
delete conflict;
|
2016-04-14 13:19:20 -03:00
|
|
|
list.next ();
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
break;
|
|
|
|
default:
|
2016-08-24 12:19:14 -03:00
|
|
|
details += Alpm.strerror (errno);
|
2015-08-20 10:11:18 -03:00
|
|
|
break;
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.details = (owned) details;
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2017-02-18 13:10:26 -03:00
|
|
|
success = false;
|
2015-08-20 10:11:18 -03:00
|
|
|
} else {
|
|
|
|
// Search for holdpkg in target list
|
|
|
|
bool found_locked_pkg = false;
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<unowned Alpm.Package> to_remove = alpm_handle.trans_to_remove ();
|
|
|
|
while (to_remove != null) {
|
|
|
|
unowned Alpm.Package pkg = to_remove.data;
|
|
|
|
if (alpm_config.get_holdpkgs ().find_custom (pkg.name, strcmp) != null) {
|
2015-08-20 10:11:18 -03:00
|
|
|
details += _("%s needs to be removed but it is a locked package").printf (pkg.name);
|
|
|
|
found_locked_pkg = true;
|
|
|
|
break;
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
to_remove.next ();
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
|
|
|
if (found_locked_pkg) {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to prepare transaction");
|
|
|
|
current_error.details = (owned) details;
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2017-02-18 13:10:26 -03:00
|
|
|
success = false;
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
return success;
|
2015-03-04 11:55:36 -03:00
|
|
|
}
|
|
|
|
|
2016-08-27 09:51:34 -03:00
|
|
|
private void trans_prepare () {
|
|
|
|
bool success = trans_init (flags);
|
|
|
|
if (success) {
|
|
|
|
foreach (unowned string name in to_install) {
|
|
|
|
success = trans_add_pkg (name);
|
|
|
|
if (!success) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
foreach (unowned string name in to_remove) {
|
|
|
|
success = trans_remove_pkg (name);
|
|
|
|
if (!success) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
foreach (unowned string path in to_load) {
|
|
|
|
success = trans_load_pkg (path);
|
|
|
|
if (!success) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
2017-02-18 13:10:26 -03:00
|
|
|
success = trans_prepare_real ();
|
2016-08-27 09:51:34 -03:00
|
|
|
} else {
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2016-08-27 09:51:34 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
}
|
|
|
|
trans_prepare_finished (success);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void build_prepare () {
|
|
|
|
// create a fake aur db
|
|
|
|
try {
|
|
|
|
var list = new StringBuilder ();
|
|
|
|
foreach (unowned string name_version in aur_desc_list) {
|
|
|
|
list.append (name_version);
|
|
|
|
list.append (" ");
|
|
|
|
}
|
|
|
|
Process.spawn_command_line_sync ("rm -f %ssync/aur.db".printf (alpm_handle.dbpath));
|
|
|
|
Process.spawn_command_line_sync ("bsdtar -cf %ssync/aur.db -C %s %s".printf (alpm_handle.dbpath, aurdb_path, list.str));
|
|
|
|
} catch (SpawnError e) {
|
|
|
|
stderr.printf ("SpawnError: %s\n", e.message);
|
|
|
|
}
|
|
|
|
// get an handle without emit signal callbacks AND fake aur db
|
|
|
|
alpm_handle = alpm_config.get_handle ();
|
|
|
|
if (alpm_handle == null) {
|
|
|
|
current_error = ErrorInfos () {
|
|
|
|
message = _("Failed to initialize alpm library")
|
|
|
|
};
|
|
|
|
trans_commit_finished (false);
|
|
|
|
} else {
|
|
|
|
alpm_handle.questioncb = (Alpm.QuestionCallBack) cb_question;
|
|
|
|
lockfile = GLib.File.new_for_path (alpm_handle.lockfile);
|
|
|
|
// fake aur db
|
2017-03-06 16:58:30 -03:00
|
|
|
alpm_handle.register_syncdb ("aur", 0);
|
2017-02-18 13:10:26 -03:00
|
|
|
// add to_build in to_install for the fake trans prpeapre
|
|
|
|
foreach (unowned string name in to_build) {
|
|
|
|
to_install += name;
|
2017-07-29 10:35:04 -04:00
|
|
|
// check if we need to remove debug package to avoid dep problem
|
|
|
|
string debug_pkg_name = "%s-debug".printf (name);
|
|
|
|
if (alpm_handle.localdb.get_pkg (debug_pkg_name) != null) {
|
|
|
|
to_remove += debug_pkg_name;
|
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
}
|
|
|
|
// check base-devel group needed to build pkgs
|
|
|
|
var backup_to_remove = new GenericSet<string?> (str_hash, str_equal);
|
|
|
|
foreach (unowned string name in to_remove) {
|
|
|
|
backup_to_remove.add (name);
|
|
|
|
}
|
|
|
|
unowned Alpm.List<unowned Alpm.DB> syncdbs = alpm_handle.syncdbs;
|
|
|
|
while (syncdbs != null) {
|
|
|
|
unowned Alpm.DB db = syncdbs.data;
|
|
|
|
unowned Alpm.Group? grp = db.get_group ("base-devel");
|
|
|
|
if (grp != null) {
|
|
|
|
unowned Alpm.List<unowned Alpm.Package> packages = grp.packages;
|
|
|
|
while (packages != null) {
|
|
|
|
unowned Alpm.Package pkg = packages.data;
|
2017-03-01 11:56:33 -03:00
|
|
|
if (Alpm.find_satisfier (alpm_handle.localdb.pkgcache, pkg.name) == null) {
|
2017-02-18 13:10:26 -03:00
|
|
|
to_install += pkg.name;
|
|
|
|
} else {
|
|
|
|
// remove the needed pkg from to_remove
|
|
|
|
backup_to_remove.remove (pkg.name);
|
|
|
|
}
|
|
|
|
packages.next ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
syncdbs.next ();
|
|
|
|
}
|
|
|
|
// check git needed to build pkgs
|
2017-03-01 11:56:33 -03:00
|
|
|
if (Alpm.find_satisfier (alpm_handle.localdb.pkgcache, "git") == null) {
|
2017-02-18 13:10:26 -03:00
|
|
|
to_install += "git";
|
2016-11-02 10:23:52 -03:00
|
|
|
} else {
|
2017-02-18 13:10:26 -03:00
|
|
|
// remove the needed pkg from to_remove
|
|
|
|
backup_to_remove.remove ("git");
|
|
|
|
}
|
|
|
|
to_remove = {};
|
|
|
|
foreach (unowned string name in backup_to_remove) {
|
|
|
|
to_remove += name;
|
|
|
|
}
|
|
|
|
// fake trans prepare
|
2017-03-22 12:32:12 -03:00
|
|
|
current_error = ErrorInfos ();
|
|
|
|
bool success = true;
|
|
|
|
if (alpm_handle.trans_init (flags | Alpm.TransFlag.NOLOCK) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
|
|
|
current_error.errno = (uint) errno;
|
|
|
|
current_error.message = _("Failed to init transaction");
|
|
|
|
if (errno != 0) {
|
|
|
|
current_error.details = { Alpm.strerror (errno) };
|
|
|
|
}
|
|
|
|
success = false;
|
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
if (success) {
|
|
|
|
foreach (unowned string name in to_install) {
|
|
|
|
success = trans_add_pkg (name);
|
|
|
|
if (!success) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
foreach (unowned string name in to_remove) {
|
|
|
|
success = trans_remove_pkg (name);
|
|
|
|
if (!success) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
foreach (unowned string path in to_load) {
|
|
|
|
success = trans_load_pkg (path);
|
|
|
|
if (!success) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success) {
|
|
|
|
success = trans_prepare_real ();
|
|
|
|
if (success) {
|
|
|
|
// check trans preparation result
|
|
|
|
string[] real_to_install = {};
|
|
|
|
unowned Alpm.List<unowned Alpm.Package> pkgs_to_add = alpm_handle.trans_to_add ();
|
|
|
|
while (pkgs_to_add != null) {
|
|
|
|
unowned Alpm.Package trans_pkg = pkgs_to_add.data;
|
|
|
|
unowned Alpm.DB? db = trans_pkg.db;
|
|
|
|
if (db != null) {
|
|
|
|
if (db.name == "aur") {
|
|
|
|
// it is a aur pkg to build
|
|
|
|
aur_pkgbases_to_build.append (trans_pkg.pkgbase);
|
|
|
|
var infos = UpdateInfos () {
|
|
|
|
name = trans_pkg.name,
|
|
|
|
old_version = "",
|
|
|
|
new_version = trans_pkg.version,
|
|
|
|
repo = "",
|
|
|
|
download_size = 0
|
|
|
|
};
|
|
|
|
to_build_infos += (owned) infos;
|
|
|
|
if (!(trans_pkg.name in to_build)) {
|
|
|
|
to_install_as_dep.insert (trans_pkg.name, trans_pkg.name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// it is a pkg to install
|
|
|
|
real_to_install += trans_pkg.name;
|
|
|
|
if (!(trans_pkg.name in to_install)) {
|
|
|
|
to_install_as_dep.insert (trans_pkg.name, trans_pkg.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pkgs_to_add.next ();
|
|
|
|
}
|
|
|
|
aur_conflicts_to_remove = {};
|
|
|
|
unowned Alpm.List<unowned Alpm.Package> pkgs_to_remove = alpm_handle.trans_to_remove ();
|
|
|
|
while (pkgs_to_remove != null) {
|
|
|
|
unowned Alpm.Package trans_pkg = pkgs_to_remove.data;
|
|
|
|
// it is a pkg to remove
|
|
|
|
if (!(trans_pkg.name in to_remove)) {
|
|
|
|
var infos = UpdateInfos () {
|
|
|
|
name = trans_pkg.name,
|
|
|
|
old_version = trans_pkg.version,
|
|
|
|
new_version = "",
|
|
|
|
repo = "",
|
|
|
|
download_size = 0
|
|
|
|
};
|
|
|
|
aur_conflicts_to_remove += (owned) infos;
|
|
|
|
}
|
|
|
|
pkgs_to_remove.next ();
|
|
|
|
}
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2017-02-18 13:10:26 -03:00
|
|
|
try {
|
|
|
|
Process.spawn_command_line_sync ("rm -f %ssync/aur.db".printf (alpm_handle.dbpath));
|
|
|
|
} catch (SpawnError e) {
|
|
|
|
stderr.printf ("SpawnError: %s\n", e.message);
|
|
|
|
}
|
|
|
|
// get standard handle
|
|
|
|
refresh_handle ();
|
|
|
|
// launch standard prepare
|
|
|
|
to_install = real_to_install;
|
|
|
|
trans_prepare ();
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2017-02-18 13:10:26 -03:00
|
|
|
}
|
2017-03-22 12:32:12 -03:00
|
|
|
}
|
|
|
|
if (!success) {
|
2017-02-18 13:10:26 -03:00
|
|
|
// get standard handle
|
|
|
|
refresh_handle ();
|
2017-03-22 12:32:12 -03:00
|
|
|
trans_prepare_finished (false);
|
2016-11-02 10:23:52 -03:00
|
|
|
}
|
2016-08-27 09:51:34 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void start_trans_prepare (Alpm.TransFlag flags_,
|
|
|
|
string[] to_install_,
|
|
|
|
string[] to_remove_,
|
2017-02-18 13:10:26 -03:00
|
|
|
string[] to_load_,
|
2017-07-29 10:35:04 -04:00
|
|
|
string[] to_build_,
|
|
|
|
GLib.BusName sender) {
|
|
|
|
if (lock_id != sender) {
|
2017-07-31 08:15:36 -04:00
|
|
|
trans_prepare_finished (false);
|
2017-07-29 10:35:04 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-08-27 09:51:34 -03:00
|
|
|
flags = flags_;
|
|
|
|
to_install = to_install_;
|
|
|
|
to_remove = to_remove_;
|
|
|
|
to_load = to_load_;
|
2017-02-18 13:10:26 -03:00
|
|
|
to_build = to_build_;
|
|
|
|
to_build_infos = {};
|
|
|
|
aur_pkgbases_to_build = new GLib.List<string> ();
|
|
|
|
if (to_build.length != 0) {
|
|
|
|
compute_aur_build_list.begin (to_build, (obj, res) => {
|
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (build_prepare));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (trans_prepare));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
|
|
|
}
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
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
|
|
|
|
2016-04-14 13:19:20 -03:00
|
|
|
public TransactionSummary get_transaction_summary () {
|
|
|
|
UpdateInfos[] to_install = {};
|
|
|
|
UpdateInfos[] to_upgrade = {};
|
|
|
|
UpdateInfos[] to_downgrade = {};
|
|
|
|
UpdateInfos[] to_reinstall = {};
|
|
|
|
UpdateInfos[] to_remove = {};
|
|
|
|
unowned Alpm.List<unowned Alpm.Package> pkgs_to_add = alpm_handle.trans_to_add ();
|
|
|
|
while (pkgs_to_add != null) {
|
|
|
|
unowned Alpm.Package trans_pkg = pkgs_to_add.data;
|
|
|
|
unowned Alpm.Package? local_pkg = alpm_handle.localdb.get_pkg (trans_pkg.name);
|
|
|
|
var infos = UpdateInfos () {
|
|
|
|
name = trans_pkg.name,
|
|
|
|
old_version = local_pkg != null ? local_pkg.version : "",
|
|
|
|
new_version = trans_pkg.version,
|
2016-02-02 05:28:07 -03:00
|
|
|
// if pkg was load from a file, pkg.db is null
|
2016-04-14 13:19:20 -03:00
|
|
|
repo =trans_pkg.db != null ? trans_pkg.db.name : "",
|
|
|
|
download_size = trans_pkg.download_size
|
2016-02-02 05:28:07 -03:00
|
|
|
};
|
2016-04-14 13:19:20 -03:00
|
|
|
if (local_pkg == null) {
|
|
|
|
to_install += (owned) infos;
|
|
|
|
} else {
|
|
|
|
int cmp = Alpm.pkg_vercmp (trans_pkg.version, local_pkg.version);
|
|
|
|
if (cmp == 1) {
|
|
|
|
to_upgrade += (owned) infos;
|
|
|
|
} else if (cmp == 0) {
|
|
|
|
to_reinstall += (owned) infos;
|
|
|
|
} else {
|
|
|
|
to_downgrade += (owned) infos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pkgs_to_add.next ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<unowned Alpm.Package> pkgs_to_remove = alpm_handle.trans_to_remove ();
|
|
|
|
while (pkgs_to_remove != null) {
|
|
|
|
unowned Alpm.Package trans_pkg = pkgs_to_remove.data;
|
|
|
|
var infos = UpdateInfos () {
|
|
|
|
name = trans_pkg.name,
|
|
|
|
old_version = trans_pkg.version,
|
|
|
|
new_version = "",
|
|
|
|
repo = trans_pkg.db.name
|
2016-02-02 05:28:07 -03:00
|
|
|
};
|
|
|
|
to_remove += (owned) infos;
|
2016-04-14 13:19:20 -03:00
|
|
|
pkgs_to_remove.next ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2017-02-18 13:10:26 -03:00
|
|
|
UpdateInfos[] conflicts_to_remove = {};
|
|
|
|
foreach (unowned UpdateInfos infos in aur_conflicts_to_remove){
|
|
|
|
conflicts_to_remove += infos;
|
|
|
|
}
|
|
|
|
aur_conflicts_to_remove = {};
|
|
|
|
string[] pkgbases_to_build = {};
|
|
|
|
foreach (unowned string name in aur_pkgbases_to_build) {
|
|
|
|
pkgbases_to_build += name;
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
var summary = TransactionSummary () {
|
|
|
|
to_install = (owned) to_install,
|
|
|
|
to_upgrade = (owned) to_upgrade,
|
|
|
|
to_downgrade = (owned) to_downgrade,
|
|
|
|
to_reinstall = (owned) to_reinstall,
|
2017-02-18 13:10:26 -03:00
|
|
|
to_remove = (owned) to_remove,
|
|
|
|
to_build = to_build_infos,
|
|
|
|
aur_conflicts_to_remove = conflicts_to_remove,
|
|
|
|
aur_pkgbases_to_build = pkgbases_to_build
|
2016-04-14 13:19:20 -03:00
|
|
|
};
|
|
|
|
return summary;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2015-08-20 10:11:18 -03:00
|
|
|
private void trans_commit () {
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error = ErrorInfos ();
|
|
|
|
bool success = true;
|
2016-04-14 13:19:20 -03:00
|
|
|
Alpm.List err_data;
|
|
|
|
if (alpm_handle.trans_commit (out err_data) == -1) {
|
|
|
|
Alpm.Errno errno = alpm_handle.errno ();
|
|
|
|
current_error.errno = (uint) errno;
|
2016-02-22 09:47:40 -03:00
|
|
|
// cancel the download return an EXTERNAL_DOWNLOAD error
|
|
|
|
if (errno == Alpm.Errno.EXTERNAL_DOWNLOAD && cancellable.is_cancelled ()) {
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2016-02-22 09:47:40 -03:00
|
|
|
trans_commit_finished (false);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
current_error.message = _("Failed to commit transaction");
|
2015-08-20 10:11:18 -03:00
|
|
|
switch (errno) {
|
2016-08-24 12:19:14 -03:00
|
|
|
case 0:
|
|
|
|
break;
|
2015-08-20 10:11:18 -03:00
|
|
|
case Alpm.Errno.FILE_CONFLICTS:
|
2017-04-16 07:40:50 -03:00
|
|
|
string[] details = {};
|
2016-08-24 12:19:14 -03:00
|
|
|
details += Alpm.strerror (errno) + ":";
|
2016-04-14 13:19:20 -03:00
|
|
|
//TransFlag flags = alpm_handle.trans_get_flags ();
|
2015-08-20 10:11:18 -03:00
|
|
|
//if ((flags & TransFlag.FORCE) != 0) {
|
|
|
|
//details += _("unable to %s directory-file conflicts").printf ("--force");
|
|
|
|
//}
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<Alpm.FileConflict*> list = err_data;
|
|
|
|
while (list != null) {
|
|
|
|
Alpm.FileConflict* conflict = list.data;
|
2015-08-20 10:11:18 -03:00
|
|
|
switch (conflict->type) {
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.FileConflict.Type.TARGET:
|
2015-08-20 10:11:18 -03:00
|
|
|
details += _("%s exists in both %s and %s").printf (conflict->file, conflict->target, conflict->ctarget);
|
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.FileConflict.Type.FILESYSTEM:
|
2015-08-20 10:11:18 -03:00
|
|
|
details += _("%s: %s already exists in filesystem").printf (conflict->target, conflict->file);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delete conflict;
|
2016-04-14 13:19:20 -03:00
|
|
|
list.next ();
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
2017-04-16 07:40:50 -03:00
|
|
|
current_error.details = (owned) details;
|
2015-08-20 10:11:18 -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:
|
2017-04-16 07:40:50 -03:00
|
|
|
string[] details = {};
|
2016-08-24 12:19:14 -03:00
|
|
|
details += Alpm.strerror (errno) + ":";
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<string*> list = err_data;
|
|
|
|
while (list != null) {
|
|
|
|
string* filename = list.data;
|
2015-08-20 10:11:18 -03:00
|
|
|
details += _("%s is invalid or corrupted").printf (filename);
|
|
|
|
delete filename;
|
2016-04-14 13:19:20 -03:00
|
|
|
list.next ();
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
2017-04-16 07:40:50 -03:00
|
|
|
current_error.details = (owned) details;
|
|
|
|
break;
|
|
|
|
case Alpm.Errno.EXTERNAL_DOWNLOAD:
|
|
|
|
// details are set in cb_fetch
|
2015-08-20 10:11:18 -03:00
|
|
|
break;
|
|
|
|
default:
|
2017-04-16 07:40:50 -03:00
|
|
|
current_error.details = {Alpm.strerror (errno)};
|
2015-08-20 10:11:18 -03:00
|
|
|
break;
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
success = false;
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2017-02-18 13:10:26 -03:00
|
|
|
to_install_as_dep.foreach_remove ((pkgname, val) => {
|
|
|
|
unowned Alpm.Package? pkg = alpm_handle.localdb.get_pkg (pkgname);
|
|
|
|
if (pkg != null) {
|
|
|
|
pkg.reason = Alpm.Package.Reason.DEPEND;
|
|
|
|
return true; // remove current pkgname
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2016-02-02 05:28:07 -03:00
|
|
|
trans_commit_finished (success);
|
2015-08-20 10:11:18 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void start_trans_commit (GLib.BusName sender) {
|
2015-08-21 11:01:02 -03:00
|
|
|
check_authorization.begin (sender, (obj, res) => {
|
|
|
|
bool authorized = check_authorization.end (res);
|
|
|
|
if (authorized) {
|
|
|
|
try {
|
|
|
|
thread_pool.add (new AlpmAction (trans_commit));
|
|
|
|
} catch (ThreadError e) {
|
|
|
|
stderr.printf ("Thread Error %s\n", e.message);
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2015-08-21 11:01:02 -03:00
|
|
|
} else {
|
2017-07-29 10:35:04 -04:00
|
|
|
trans_release (lock_id);
|
2016-02-02 05:28:07 -03:00
|
|
|
trans_commit_finished (false);
|
2015-08-21 11:01:02 -03:00
|
|
|
}
|
|
|
|
});
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
public void trans_release (GLib.BusName sender) {
|
|
|
|
if (lock_id != sender) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
alpm_handle.trans_release ();
|
2016-08-27 09:51:34 -03:00
|
|
|
remove_ignorepkgs ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
public void trans_cancel (GLib.BusName sender) {
|
|
|
|
if (lock_id != sender) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-14 13:19:20 -03:00
|
|
|
if (alpm_handle.trans_interrupt () == 0) {
|
2015-04-11 13:00:49 -03:00
|
|
|
// a transaction is being interrupted
|
2015-08-21 11:01:02 -03:00
|
|
|
// it will end the normal way
|
2015-04-11 13:00:49 -03:00
|
|
|
return;
|
|
|
|
}
|
2016-02-22 09:47:40 -03:00
|
|
|
cancellable.cancel ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2015-01-05 17:06:18 -03:00
|
|
|
[DBus (no_reply = true)]
|
2014-10-30 10:44:09 -03:00
|
|
|
public void quit () {
|
2017-05-14 09:43:08 -04:00
|
|
|
// wait for all tasks to be processed
|
|
|
|
ThreadPool.free ((owned) thread_pool, false, true);
|
|
|
|
loop.quit ();
|
2014-10-30 10:44:09 -03:00
|
|
|
}
|
|
|
|
// 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 ();
|
2016-05-17 13:11:49 -04:00
|
|
|
string log = "%s [PAMAC] %s\n".printf (now.format ("[%Y-%m-%d %H:%M]"), event);
|
2016-05-13 10:44:10 -03:00
|
|
|
var file = GLib.File.new_for_path ("/var/log/pacman.log");
|
2014-10-22 13:44:02 -03:00
|
|
|
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) {
|
2015-02-01 14:01:03 -03:00
|
|
|
stderr.printf ("%s\n", e.message);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 05:28:07 -03:00
|
|
|
private void cb_event (Alpm.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) {
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.HOOK_START:
|
|
|
|
switch (data.hook_when) {
|
|
|
|
case Alpm.HookWhen.PRE_TRANSACTION:
|
|
|
|
secondary_type = (uint) Alpm.HookWhen.PRE_TRANSACTION;
|
|
|
|
break;
|
|
|
|
case Alpm.HookWhen.POST_TRANSACTION:
|
|
|
|
secondary_type = (uint) Alpm.HookWhen.POST_TRANSACTION;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Alpm.Event.Type.HOOK_RUN_START:
|
|
|
|
details += data.hook_run_name;
|
2016-02-06 05:33:07 -03:00
|
|
|
details += data.hook_run_desc ?? "";
|
2016-02-02 05:28:07 -03:00
|
|
|
details += data.hook_run_position.to_string ();
|
|
|
|
details += data.hook_run_total.to_string ();
|
2016-07-02 04:25:07 -04:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.PACKAGE_OPERATION_START:
|
2014-12-03 12:02:14 -03:00
|
|
|
switch (data.package_operation_operation) {
|
2015-03-04 11:55:36 -03:00
|
|
|
case Alpm.Package.Operation.REMOVE:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.package_operation_oldpkg.name;
|
|
|
|
details += data.package_operation_oldpkg.version;
|
2015-03-04 11:55:36 -03:00
|
|
|
secondary_type = (uint) Alpm.Package.Operation.REMOVE;
|
2014-12-03 12:02:14 -03:00
|
|
|
break;
|
2015-03-04 11:55:36 -03:00
|
|
|
case Alpm.Package.Operation.INSTALL:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.package_operation_newpkg.name;
|
|
|
|
details += data.package_operation_newpkg.version;
|
2015-03-04 11:55:36 -03:00
|
|
|
secondary_type = (uint) Alpm.Package.Operation.INSTALL;
|
2014-12-03 12:02:14 -03:00
|
|
|
break;
|
2015-03-04 11:55:36 -03:00
|
|
|
case Alpm.Package.Operation.REINSTALL:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.package_operation_newpkg.name;
|
|
|
|
details += data.package_operation_newpkg.version;
|
2015-03-04 11:55:36 -03:00
|
|
|
secondary_type = (uint) Alpm.Package.Operation.REINSTALL;
|
2014-12-03 12:02:14 -03:00
|
|
|
break;
|
2015-03-04 11:55:36 -03:00
|
|
|
case Alpm.Package.Operation.UPGRADE:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.package_operation_oldpkg.name;
|
|
|
|
details += data.package_operation_oldpkg.version;
|
|
|
|
details += data.package_operation_newpkg.version;
|
2015-03-04 11:55:36 -03:00
|
|
|
secondary_type = (uint) Alpm.Package.Operation.UPGRADE;
|
2014-12-03 12:02:14 -03:00
|
|
|
break;
|
2015-03-04 11:55:36 -03:00
|
|
|
case Alpm.Package.Operation.DOWNGRADE:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.package_operation_oldpkg.name;
|
|
|
|
details += data.package_operation_oldpkg.version;
|
|
|
|
details += data.package_operation_newpkg.version;
|
2015-03-04 11:55:36 -03:00
|
|
|
secondary_type = (uint) Alpm.Package.Operation.DOWNGRADE;
|
2014-12-03 12:02:14 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
default:
|
|
|
|
break;
|
2014-12-03 12:02:14 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.DELTA_PATCH_START:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.delta_patch_delta.to;
|
|
|
|
details += data.delta_patch_delta.delta;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.SCRIPTLET_INFO:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.scriptlet_info_line;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.PKGDOWNLOAD_START:
|
2016-08-06 08:33:34 -04:00
|
|
|
// do not emit event when download is cancelled
|
2017-07-29 10:35:04 -04:00
|
|
|
if (system_daemon.cancellable.is_cancelled ()) {
|
2016-08-06 08:33:34 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.pkgdownload_file;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.OPTDEP_REMOVAL:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.optdep_removal_pkg.name;
|
|
|
|
details += data.optdep_removal_optdep.compute_string ();
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.DATABASE_MISSING:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.database_missing_dbname;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.PACNEW_CREATED:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.pacnew_created_file;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Event.Type.PACSAVE_CREATED:
|
2014-12-03 12:02:14 -03:00
|
|
|
details += data.pacsave_created_file;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_event ((uint) data.type, secondary_type, details);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2016-02-02 05:28:07 -03:00
|
|
|
private void cb_question (Alpm.Question.Data data) {
|
2014-12-03 12:02:14 -03:00
|
|
|
switch (data.type) {
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.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;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.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;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.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;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Question.Type.REMOVE_PKGS:
|
2017-02-18 13:10:26 -03:00
|
|
|
// Return an error if there are top-level packages which have unresolvable dependencies
|
|
|
|
data.remove_pkgs_skip = 0;
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Question.Type.SELECT_PROVIDER:
|
2014-12-03 12:02:14 -03:00
|
|
|
string depend_str = data.select_provider_depend.compute_string ();
|
2014-10-22 13:44:02 -03:00
|
|
|
string[] providers_str = {};
|
2016-04-14 13:19:20 -03:00
|
|
|
unowned Alpm.List<unowned Alpm.Package> list = data.select_provider_providers;
|
|
|
|
while (list != null) {
|
|
|
|
unowned Alpm.Package pkg = list.data;
|
2014-10-22 13:44:02 -03:00
|
|
|
providers_str += pkg.name;
|
2016-04-14 13:19:20 -03:00
|
|
|
list.next ();
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.provider_cond = Cond ();
|
|
|
|
system_daemon.provider_mutex = Mutex ();
|
|
|
|
system_daemon.choosen_provider = null;
|
|
|
|
system_daemon.emit_providers (depend_str, providers_str);
|
|
|
|
system_daemon.provider_mutex.lock ();
|
|
|
|
while (system_daemon.choosen_provider == null) {
|
|
|
|
system_daemon.provider_cond.wait (system_daemon.provider_mutex);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2017-07-29 10:35:04 -04:00
|
|
|
data.select_provider_use_index = system_daemon.choosen_provider;
|
|
|
|
system_daemon.provider_mutex.unlock ();
|
2014-10-22 13:44:02 -03:00
|
|
|
break;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.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;
|
2016-02-02 05:28:07 -03:00
|
|
|
case Alpm.Question.Type.IMPORT_KEY:
|
2015-02-01 14:01:03 -03:00
|
|
|
if (data.import_key_key.revoked == 1) {
|
|
|
|
// Do not get revoked key
|
2014-12-03 12:02:14 -03:00
|
|
|
data.import_key_import = 0;
|
2015-02-01 14:01:03 -03:00
|
|
|
} else {
|
|
|
|
// Auto get not revoked key
|
2014-12-03 12:02:14 -03:00
|
|
|
data.import_key_import = 1;
|
2015-02-01 14:01:03 -03:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 05:28:07 -03:00
|
|
|
private void cb_progress (Alpm.Progress progress, string pkgname, int percent, uint n_targets, uint current_target) {
|
|
|
|
if (percent == 0) {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_progress ((uint) progress, pkgname, (uint) percent, n_targets, current_target);
|
|
|
|
system_daemon.timer.start ();
|
2016-02-02 05:28:07 -03:00
|
|
|
} else if (percent == 100) {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_progress ((uint) progress, pkgname, (uint) percent, n_targets, current_target);
|
|
|
|
system_daemon.timer.stop ();
|
|
|
|
}else if (system_daemon.timer.elapsed () < 0.5) {
|
2016-02-02 05:28:07 -03:00
|
|
|
return;
|
|
|
|
} else {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_progress ((uint) progress, pkgname, (uint) percent, n_targets, current_target);
|
|
|
|
system_daemon.timer.start ();
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-22 09:47:40 -03:00
|
|
|
private uint64 prevprogress;
|
|
|
|
|
|
|
|
private int cb_download (void* data, uint64 dltotal, uint64 dlnow, uint64 ultotal, uint64 ulnow) {
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
if (unlikely (system_daemon.cancellable.is_cancelled ())) {
|
2016-02-22 09:47:40 -03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
string filename = (string) data;
|
|
|
|
|
2016-08-06 08:33:34 -04:00
|
|
|
if (unlikely (dlnow == 0 || dltotal == 0 || prevprogress == dltotal)) {
|
2016-02-22 09:47:40 -03:00
|
|
|
return 0;
|
2016-04-14 13:19:20 -03:00
|
|
|
} else if (unlikely (prevprogress == 0)) {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_download (filename, 0, dltotal);
|
|
|
|
system_daemon.emit_download (filename, dlnow, dltotal);
|
|
|
|
system_daemon.timer.start ();
|
2016-02-22 09:47:40 -03:00
|
|
|
} else if (unlikely (dlnow == dltotal)) {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_download (filename, dlnow, dltotal);
|
|
|
|
system_daemon.timer.stop ();
|
|
|
|
} else if (likely (system_daemon.timer.elapsed () < 0.5)) {
|
2016-02-22 09:47:40 -03:00
|
|
|
return 0;
|
2016-02-02 05:28:07 -03:00
|
|
|
} else {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_download (filename, dlnow, dltotal);
|
|
|
|
system_daemon.timer.start ();
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
2016-02-22 09:47:40 -03:00
|
|
|
|
|
|
|
prevprogress = dlnow;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int cb_fetch (string fileurl, string localpath, int force) {
|
2017-07-29 10:35:04 -04:00
|
|
|
if (system_daemon.cancellable.is_cancelled ()) {
|
2016-02-22 09:47:40 -03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
char error_buffer[Curl.ERROR_SIZE];
|
|
|
|
var url = GLib.File.new_for_uri (fileurl);
|
|
|
|
var destfile = GLib.File.new_for_path (localpath + url.get_basename ());
|
|
|
|
var tempfile = GLib.File.new_for_path (destfile.get_path () + ".part");
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.curl.reset ();
|
|
|
|
system_daemon.curl.setopt (Curl.Option.FAILONERROR, 1L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.CONNECTTIMEOUT, 30L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.FILETIME, 1L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.FOLLOWLOCATION, 1L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.XFERINFOFUNCTION, cb_download);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.LOW_SPEED_LIMIT, 1L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.LOW_SPEED_TIME, 30L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.NETRC, Curl.NetRCOption.OPTIONAL);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.HTTPAUTH, Curl.CURLAUTH_ANY);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.URL, fileurl);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.ERRORBUFFER, error_buffer);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.NOPROGRESS, 0L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.XFERINFODATA, (void*) url.get_basename ());
|
2016-02-22 09:47:40 -03:00
|
|
|
|
|
|
|
bool remove_partial_download = true;
|
|
|
|
if (fileurl.contains (".pkg.tar.") && !fileurl.has_suffix (".sig")) {
|
|
|
|
remove_partial_download = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string open_mode = "wb";
|
|
|
|
prevprogress = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (force == 0) {
|
|
|
|
if (destfile.query_exists ()) {
|
|
|
|
// start from scratch only download if our local is out of date.
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.curl.setopt (Curl.Option.TIMECONDITION, Curl.TimeCond.IFMODSINCE);
|
2016-02-22 09:47:40 -03:00
|
|
|
FileInfo info = destfile.query_info ("time::modified", 0);
|
|
|
|
TimeVal time = info.get_modification_time ();
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.curl.setopt (Curl.Option.TIMEVALUE, time.tv_sec);
|
2016-02-22 09:47:40 -03:00
|
|
|
} else if (tempfile.query_exists ()) {
|
|
|
|
// a previous partial download exists, resume from end of file.
|
|
|
|
FileInfo info = tempfile.query_info ("standard::size", 0);
|
|
|
|
int64 size = info.get_size ();
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.curl.setopt (Curl.Option.RESUME_FROM_LARGE, size);
|
2016-02-22 09:47:40 -03:00
|
|
|
open_mode = "ab";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tempfile.query_exists ()) {
|
|
|
|
tempfile.delete ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
Posix.FILE localf = Posix.FILE.open (tempfile.get_path (), open_mode);
|
|
|
|
if (localf == null) {
|
2017-02-18 13:10:26 -03:00
|
|
|
stderr.printf ("could not open file %s\n", tempfile.get_path ());
|
2016-02-22 09:47:40 -03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.curl.setopt (Curl.Option.WRITEDATA, localf);
|
2016-02-22 09:47:40 -03:00
|
|
|
|
|
|
|
// perform transfer
|
2017-07-29 10:35:04 -04:00
|
|
|
Curl.Code err = system_daemon.curl.perform ();
|
2016-02-22 09:47:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
// disconnect relationships from the curl handle for things that might go out
|
|
|
|
// of scope, but could still be touched on connection teardown. This really
|
|
|
|
// only applies to FTP transfers.
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.curl.setopt (Curl.Option.NOPROGRESS, 1L);
|
|
|
|
system_daemon.curl.setopt (Curl.Option.ERRORBUFFER, null);
|
2016-02-22 09:47:40 -03:00
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
// was it a success?
|
|
|
|
switch (err) {
|
|
|
|
case Curl.Code.OK:
|
|
|
|
long timecond, remote_time = -1;
|
|
|
|
double remote_size, bytes_dl;
|
|
|
|
unowned string effective_url;
|
|
|
|
|
|
|
|
// retrieve info about the state of the transfer
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.curl.getinfo (Curl.Info.FILETIME, out remote_time);
|
|
|
|
system_daemon.curl.getinfo (Curl.Info.CONTENT_LENGTH_DOWNLOAD, out remote_size);
|
|
|
|
system_daemon.curl.getinfo (Curl.Info.SIZE_DOWNLOAD, out bytes_dl);
|
|
|
|
system_daemon.curl.getinfo (Curl.Info.CONDITION_UNMET, out timecond);
|
|
|
|
system_daemon.curl.getinfo (Curl.Info.EFFECTIVE_URL, out effective_url);
|
2016-02-22 09:47:40 -03:00
|
|
|
|
|
|
|
if (timecond == 1 && bytes_dl == 0) {
|
|
|
|
// time condition was met and we didn't download anything. we need to
|
|
|
|
// clean up the 0 byte .part file that's left behind.
|
|
|
|
try {
|
|
|
|
if (tempfile.query_exists ()) {
|
|
|
|
tempfile.delete ();
|
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
// remote_size isn't necessarily the full size of the file, just what the
|
|
|
|
// server reported as remaining to download. compare it to what curl reported
|
|
|
|
// as actually being transferred during curl_easy_perform ()
|
|
|
|
else if (remote_size != -1 && bytes_dl != -1 && bytes_dl != remote_size) {
|
2017-04-16 07:40:50 -03:00
|
|
|
string error = _("%s appears to be truncated: %jd/%jd bytes\n").printf (
|
|
|
|
fileurl, bytes_dl, remote_size);
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_log ((uint) Alpm.LogLevel.ERROR, error);
|
|
|
|
system_daemon.current_error.details = {error};
|
2016-02-22 09:47:40 -03:00
|
|
|
if (remove_partial_download) {
|
|
|
|
try {
|
|
|
|
if (tempfile.query_exists ()) {
|
|
|
|
tempfile.delete ();
|
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = -1;
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
tempfile.move (destfile, FileCopyFlags.OVERWRITE);
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Curl.Code.ABORTED_BY_CALLBACK:
|
|
|
|
if (remove_partial_download) {
|
|
|
|
try {
|
|
|
|
if (tempfile.query_exists ()) {
|
|
|
|
tempfile.delete ();
|
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// other cases are errors
|
|
|
|
try {
|
|
|
|
if (tempfile.query_exists ()) {
|
|
|
|
if (remove_partial_download) {
|
|
|
|
tempfile.delete ();
|
|
|
|
} else {
|
|
|
|
// delete zero length downloads
|
|
|
|
FileInfo info = tempfile.query_info ("standard::size", 0);
|
|
|
|
int64 size = info.get_size ();
|
|
|
|
if (size == 0) {
|
|
|
|
tempfile.delete ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (GLib.Error e) {
|
|
|
|
stderr.printf ("Error: %s\n", e.message);
|
|
|
|
}
|
2017-03-03 08:21:27 -03:00
|
|
|
// do not report error for missing sig
|
|
|
|
if (!fileurl.has_suffix (".sig")) {
|
2016-02-22 09:47:40 -03:00
|
|
|
string hostname = url.get_uri ().split("/")[2];
|
2017-04-16 07:40:50 -03:00
|
|
|
string error = _("failed retrieving file '%s' from %s : %s\n").printf (
|
|
|
|
url.get_basename (), hostname, (string) error_buffer);
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_log ((uint) Alpm.LogLevel.ERROR, error);
|
|
|
|
system_daemon.current_error.details = {error};
|
2016-02-22 09:47:40 -03:00
|
|
|
}
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
private void cb_totaldownload (uint64 total) {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_totaldownload (total);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
2016-02-02 05:28:07 -03:00
|
|
|
private void cb_log (Alpm.LogLevel level, string fmt, va_list args) {
|
2016-02-22 09:47:40 -03:00
|
|
|
// do not log errors when download is cancelled
|
2017-07-29 10:35:04 -04:00
|
|
|
if (system_daemon.cancellable.is_cancelled ()) {
|
2016-02-22 09:47:40 -03:00
|
|
|
return;
|
|
|
|
}
|
2016-02-02 05:28:07 -03:00
|
|
|
Alpm.LogLevel logmask = Alpm.LogLevel.ERROR | Alpm.LogLevel.WARNING;
|
2015-05-20 09:48:12 -03:00
|
|
|
if ((level & logmask) == 0) {
|
2014-10-22 13:44:02 -03:00
|
|
|
return;
|
2015-05-20 09:48:12 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
string? log = null;
|
|
|
|
log = fmt.vprintf (args);
|
2015-05-20 09:48:12 -03:00
|
|
|
if (log != null) {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon.emit_log ((uint) level, log);
|
2015-05-20 09:48:12 -03:00
|
|
|
}
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_bus_acquired (DBusConnection conn) {
|
2017-07-29 10:35:04 -04:00
|
|
|
system_daemon = new Pamac.SystemDaemon ();
|
2014-10-22 13:44:02 -03:00
|
|
|
try {
|
2017-07-29 10:35:04 -04:00
|
|
|
conn.register_object ("/org/manjaro/pamac/system", system_daemon);
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
catch (IOError e) {
|
|
|
|
stderr.printf ("Could not register service\n");
|
2015-04-11 13:00:49 -03:00
|
|
|
loop.quit ();
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-02-02 05:28:07 -03:00
|
|
|
Bus.own_name (BusType.SYSTEM,
|
2017-07-29 10:35:04 -04:00
|
|
|
"org.manjaro.pamac.system",
|
2016-02-02 05:28:07 -03:00
|
|
|
BusNameOwnerFlags.NONE,
|
2014-10-22 13:44:02 -03:00
|
|
|
on_bus_acquired,
|
2015-04-11 13:00:49 -03:00
|
|
|
null,
|
|
|
|
() => {
|
|
|
|
stderr.printf ("Could not acquire name\n");
|
|
|
|
loop.quit ();
|
|
|
|
});
|
2014-10-22 13:44:02 -03:00
|
|
|
|
2016-08-06 08:33:34 -04:00
|
|
|
Curl.global_init (Curl.GLOBAL_SSL);
|
2014-10-22 13:44:02 -03:00
|
|
|
loop = new MainLoop ();
|
|
|
|
loop.run ();
|
2016-08-06 08:33:34 -04:00
|
|
|
Curl.global_cleanup ();
|
2014-10-22 13:44:02 -03:00
|
|
|
}
|