forked from cromer/pamac-classic
little code improvements
This commit is contained in:
parent
16453a214d
commit
db57dfe8e5
@ -38,10 +38,10 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public struct ErrorInfos {
|
||||
public string str;
|
||||
public string message;
|
||||
public string[] details;
|
||||
public ErrorInfos () {
|
||||
str = "";
|
||||
message = "";
|
||||
details = {};
|
||||
}
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ namespace Pamac {
|
||||
private void refresh_handle () {
|
||||
alpm_config.get_handle ();
|
||||
if (alpm_config.handle == null) {
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
err.str = _("Failed to initialize alpm library");
|
||||
var err = ErrorInfos ();
|
||||
err.message = _("Failed to initialize alpm library");
|
||||
trans_commit_finished (err);
|
||||
} else {
|
||||
alpm_config.handle.eventcb = (EventCallBack) cb_event;
|
||||
@ -256,7 +256,7 @@ namespace Pamac {
|
||||
|
||||
private async ErrorInfos refresh (int force) {
|
||||
SourceFunc callback = refresh.callback;
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
try {
|
||||
new Thread<int>.try ("refresh thread", () => {
|
||||
databases_lock_mutex.lock ();
|
||||
@ -272,7 +272,7 @@ namespace Pamac {
|
||||
// We should always succeed if at least one DB was upgraded - we may possibly
|
||||
// fail later with unresolved deps, but that should be rare, and would be expected
|
||||
if (success == 0) {
|
||||
err.str = _("Failed to synchronize any databases");
|
||||
err.message = _("Failed to synchronize any databases");
|
||||
details += Alpm.strerror (alpm_config.handle.errno ());
|
||||
err.details = details;
|
||||
}
|
||||
@ -387,7 +387,7 @@ namespace Pamac {
|
||||
return Pamac.Package (get_syncpkg (pkgname), null);
|
||||
}
|
||||
|
||||
public async Pamac.Package[] search_pkgs (string search_string, bool search_aur) {
|
||||
public async Pamac.Package[] search_pkgs (string search_string, bool search_from_aur) {
|
||||
Pamac.Package[] result = {};
|
||||
var needles = new Alpm.List<string> ();
|
||||
string[] splitted = search_string.split (" ");
|
||||
@ -398,7 +398,7 @@ namespace Pamac {
|
||||
foreach (var alpm_pkg in alpm_pkgs) {
|
||||
result += Pamac.Package (alpm_pkg, null);
|
||||
}
|
||||
if (search_aur) {
|
||||
if (search_from_aur) {
|
||||
Json.Array aur_pkgs;
|
||||
if (aur_results.contains (search_string)) {
|
||||
aur_pkgs = aur_results.get (search_string);
|
||||
@ -462,9 +462,9 @@ namespace Pamac {
|
||||
return groups_names;
|
||||
}
|
||||
|
||||
public async Pamac.Package[] get_group_pkgs (string group_name) {
|
||||
public async Pamac.Package[] get_group_pkgs (string groupname) {
|
||||
Pamac.Package[] pkgs = {};
|
||||
var alpm_pkgs = group_pkgs (alpm_config.handle, group_name);
|
||||
var alpm_pkgs = group_pkgs (alpm_config.handle, groupname);
|
||||
foreach (var alpm_pkg in alpm_pkgs) {
|
||||
pkgs += Pamac.Package (alpm_pkg, null);
|
||||
}
|
||||
@ -585,8 +585,7 @@ namespace Pamac {
|
||||
return deps;
|
||||
}
|
||||
|
||||
public async Updates get_updates () {
|
||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||
public async Updates get_updates (bool enable_aur) {
|
||||
var infos = UpdateInfos ();
|
||||
UpdateInfos[] updates_infos = {};
|
||||
var updates = Updates ();
|
||||
@ -625,7 +624,7 @@ namespace Pamac {
|
||||
infos.download_size = candidate.download_size;
|
||||
updates_infos += infos;
|
||||
} else {
|
||||
if (pamac_config.enable_aur) {
|
||||
if (enable_aur) {
|
||||
// check if it is a local pkg
|
||||
foreach (var db in alpm_config.handle.syncdbs) {
|
||||
pkg = Alpm.find_satisfier (db.pkgcache, local_pkg.name);
|
||||
@ -642,7 +641,7 @@ namespace Pamac {
|
||||
}
|
||||
updates.is_syncfirst = false;
|
||||
updates.repos_updates = updates_infos;
|
||||
if (pamac_config.enable_aur) {
|
||||
if (enable_aur) {
|
||||
if (aur_updates_checked == false) {
|
||||
// get aur updates
|
||||
updates_infos = {};
|
||||
@ -675,11 +674,11 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public ErrorInfos trans_init (TransFlag transflags) {
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
string[] details = {};
|
||||
int ret = alpm_config.handle.trans_init (transflags);
|
||||
if (ret == -1) {
|
||||
err.str = _("Failed to init transaction");
|
||||
err.message = _("Failed to init transaction");
|
||||
details += Alpm.strerror (alpm_config.handle.errno ());
|
||||
err.details = details;
|
||||
}
|
||||
@ -687,11 +686,11 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public ErrorInfos trans_sysupgrade (int enable_downgrade) {
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
string[] details = {};
|
||||
int ret = alpm_config.handle.trans_sysupgrade (enable_downgrade);
|
||||
if (ret == -1) {;
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
details += Alpm.strerror (alpm_config.handle.errno ());
|
||||
err.details = details;
|
||||
}
|
||||
@ -699,7 +698,7 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
private ErrorInfos trans_add_pkg_real (Alpm.Package pkg) {
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
string[] details = {};
|
||||
int ret = alpm_config.handle.trans_add_pkg (pkg);
|
||||
if (ret == -1) {
|
||||
@ -708,7 +707,7 @@ namespace Pamac {
|
||||
// just skip duplicate or ignored targets
|
||||
return err;
|
||||
} else {
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
details += "%s: %s".printf (pkg.name, Alpm.strerror (errno));
|
||||
err.details = details;
|
||||
return err;
|
||||
@ -718,17 +717,17 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public ErrorInfos trans_add_pkg (string pkgname) {
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
string[] details = {};
|
||||
unowned Alpm.Package? pkg = get_syncpkg (pkgname);
|
||||
if (pkg == null) {
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
details += _("target not found: %s").printf (pkgname);
|
||||
err.details = details;
|
||||
return err;
|
||||
} else {
|
||||
err = trans_add_pkg_real (pkg);
|
||||
if (err.str == "") {
|
||||
if (err.message == "") {
|
||||
if ("linux31" in pkg.name) {
|
||||
string[] installed_kernels = {};
|
||||
string[] installed_modules = {};
|
||||
@ -774,11 +773,11 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public ErrorInfos trans_load_pkg (string pkgpath) {
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
string[] details = {};
|
||||
Alpm.Package* pkg = alpm_config.handle.load_file (pkgpath, 1, alpm_config.handle.localfilesiglevel);
|
||||
if (pkg == null) {
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
details += "%s: %s".printf (pkgpath, Alpm.strerror (alpm_config.handle.errno ()));
|
||||
err.details = details;
|
||||
return err;
|
||||
@ -790,7 +789,7 @@ namespace Pamac {
|
||||
// just skip duplicate or ignored targets
|
||||
return err;
|
||||
} else {
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
details += "%s: %s".printf (pkg->name, Alpm.strerror (errno));
|
||||
err.details = details;
|
||||
// free the package because it will not be used
|
||||
@ -803,18 +802,18 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public ErrorInfos trans_remove_pkg (string pkgname) {
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
string[] details = {};
|
||||
unowned Alpm.Package? pkg = alpm_config.handle.localdb.get_pkg (pkgname);
|
||||
if (pkg == null) {
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
details += _("target not found: %s").printf (pkgname);
|
||||
err.details = details;
|
||||
return err;
|
||||
}
|
||||
int ret = alpm_config.handle.trans_remove_pkg (pkg);
|
||||
if (ret == -1) {
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
details += "%s: %s".printf (pkg.name, Alpm.strerror (alpm_config.handle.errno ()));
|
||||
err.details = details;
|
||||
}
|
||||
@ -823,7 +822,7 @@ namespace Pamac {
|
||||
|
||||
private async ErrorInfos trans_prepare () {
|
||||
SourceFunc callback = trans_prepare.callback;
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
try {
|
||||
new Thread<int>.try ("prepare thread", () => {
|
||||
databases_lock_mutex.lock ();
|
||||
@ -832,7 +831,7 @@ namespace Pamac {
|
||||
int ret = alpm_config.handle.trans_prepare (out err_data);
|
||||
if (ret == -1) {
|
||||
Alpm.Errno errno = alpm_config.handle.errno ();
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
string detail = Alpm.strerror (errno);
|
||||
switch (errno) {
|
||||
case Errno.PKG_INVALID_ARCH:
|
||||
@ -885,7 +884,7 @@ namespace Pamac {
|
||||
}
|
||||
}
|
||||
if (found_locked_pkg) {
|
||||
err.str = _("Failed to prepare transaction");
|
||||
err.message = _("Failed to prepare transaction");
|
||||
err.details = details;
|
||||
trans_release ();
|
||||
}
|
||||
@ -950,7 +949,7 @@ namespace Pamac {
|
||||
|
||||
private async ErrorInfos trans_commit (GLib.BusName sender) {
|
||||
SourceFunc callback = trans_commit.callback;
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
try {
|
||||
Polkit.Authority authority = Polkit.Authority.get_sync (null);
|
||||
Polkit.Subject subject = Polkit.SystemBusName.new (sender);
|
||||
@ -971,7 +970,7 @@ namespace Pamac {
|
||||
int ret = alpm_config.handle.trans_commit (out err_data);
|
||||
if (ret == -1) {
|
||||
Alpm.Errno errno = alpm_config.handle.errno ();
|
||||
err.str = _("Failed to commit transaction");
|
||||
err.message = _("Failed to commit transaction");
|
||||
string detail = Alpm.strerror (errno);
|
||||
switch (errno) {
|
||||
case Alpm.Errno.FILE_CONFLICTS:
|
||||
@ -1018,7 +1017,7 @@ namespace Pamac {
|
||||
return ret;
|
||||
});
|
||||
} else {
|
||||
err.str = _("Authentication failed");
|
||||
err.message = _("Authentication failed");
|
||||
trans_release ();
|
||||
}
|
||||
} catch (GLib.Error e) {
|
||||
|
@ -35,7 +35,7 @@ namespace Pamac {
|
||||
public abstract async Pamac.Package[] get_orphans () throws IOError;
|
||||
public abstract Pamac.Package find_local_pkg (string pkgname) throws IOError;
|
||||
public abstract Pamac.Package find_sync_pkg (string pkgname) throws IOError;
|
||||
public abstract async Pamac.Package[] search_pkgs (string search_string, bool search_aur) throws IOError;
|
||||
public abstract async Pamac.Package[] search_pkgs (string search_string, bool search_from_aur) throws IOError;
|
||||
public abstract string[] get_repos_names () throws IOError;
|
||||
public abstract async Pamac.Package[] get_repo_pkgs (string repo) throws IOError;
|
||||
public abstract string[] get_groups_names () throws IOError;
|
||||
@ -44,7 +44,7 @@ namespace Pamac {
|
||||
public abstract string[] get_pkg_uninstalled_optdeps (string pkgname) throws IOError;
|
||||
public abstract PackageDeps get_pkg_deps (string pkgname) throws IOError;
|
||||
public abstract PackageDetails get_pkg_details (string pkgname) throws IOError;
|
||||
public abstract async Updates get_updates () throws IOError;
|
||||
public abstract async Updates get_updates (bool enable_aur) throws IOError;
|
||||
public abstract ErrorInfos trans_init (Alpm.TransFlag transflags) throws IOError;
|
||||
public abstract ErrorInfos trans_sysupgrade (int enable_downgrade) throws IOError;
|
||||
public abstract ErrorInfos trans_add_pkg (string pkgname) throws IOError;
|
||||
@ -414,8 +414,9 @@ namespace Pamac {
|
||||
|
||||
public async Updates get_updates () {
|
||||
var updates = Updates ();
|
||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||
try {
|
||||
updates = yield daemon.get_updates ();
|
||||
updates = yield daemon.get_updates (pamac_config.enable_aur);
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
@ -425,13 +426,13 @@ namespace Pamac {
|
||||
public void sysupgrade_simple (int enable_downgrade) {
|
||||
progress_dialog.progressbar.set_fraction (0);
|
||||
progress_dialog.cancel_button.set_visible (true);
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
try {
|
||||
err = daemon.trans_init (0);
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
if (err.str != "") {
|
||||
if (err.message != "") {
|
||||
finished (true);
|
||||
handle_error (err);
|
||||
} else {
|
||||
@ -440,7 +441,7 @@ namespace Pamac {
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
if (err.str == "") {
|
||||
if (err.message == "") {
|
||||
progress_dialog.show ();
|
||||
while (Gtk.events_pending ())
|
||||
Gtk.main_iteration ();
|
||||
@ -500,7 +501,7 @@ namespace Pamac {
|
||||
while (Gtk.events_pending ()) {
|
||||
Gtk.main_iteration ();
|
||||
}
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
on_trans_prepare_finished (err);
|
||||
}
|
||||
}
|
||||
@ -525,7 +526,7 @@ namespace Pamac {
|
||||
while (Gtk.events_pending ())
|
||||
Gtk.main_iteration ();
|
||||
// run
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
if (to_add.size () == 0
|
||||
&& to_remove.size () == 0
|
||||
&& to_load.size () == 0
|
||||
@ -538,7 +539,7 @@ namespace Pamac {
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
if (err.str != "") {
|
||||
if (err.message != "") {
|
||||
finished (true);
|
||||
handle_error (err);
|
||||
} else {
|
||||
@ -548,7 +549,7 @@ namespace Pamac {
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
if (err.str != "")
|
||||
if (err.message != "")
|
||||
break;
|
||||
}
|
||||
foreach (string name in to_remove.get_keys ()) {
|
||||
@ -557,7 +558,7 @@ namespace Pamac {
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
if (err.str != "")
|
||||
if (err.message != "")
|
||||
break;
|
||||
}
|
||||
foreach (string path in to_load.get_keys ()) {
|
||||
@ -566,10 +567,10 @@ namespace Pamac {
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
if (err.str != "")
|
||||
if (err.message != "")
|
||||
break;
|
||||
}
|
||||
if (err.str == "") {
|
||||
if (err.message == "") {
|
||||
try {
|
||||
daemon.start_trans_prepare ();
|
||||
} catch (IOError e) {
|
||||
@ -1198,12 +1199,12 @@ namespace Pamac {
|
||||
|
||||
public void handle_error (ErrorInfos error) {
|
||||
progress_dialog.expander.set_expanded (true);
|
||||
spawn_in_term ({"echo", "-n", error.str});
|
||||
spawn_in_term ({"echo", "-n", error.message});
|
||||
Gtk.TextIter start_iter;
|
||||
Gtk.TextIter end_iter;
|
||||
transaction_info_dialog.set_title (dgettext (null, "Error"));
|
||||
transaction_info_dialog.label.set_visible (true);
|
||||
transaction_info_dialog.label.set_markup (error.str);
|
||||
transaction_info_dialog.label.set_markup (error.message);
|
||||
if (error.details.length != 0) {
|
||||
transaction_info_dialog.textbuffer.get_start_iter (out start_iter);
|
||||
transaction_info_dialog.textbuffer.get_end_iter (out end_iter);
|
||||
@ -1231,7 +1232,7 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public void on_refresh_finished (ErrorInfos error) {
|
||||
if (error.str == "") {
|
||||
if (error.message == "") {
|
||||
if (mode == Mode.UPDATER) {
|
||||
progress_dialog.hide ();
|
||||
while (Gtk.events_pending ()) {
|
||||
@ -1250,7 +1251,7 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public void on_trans_prepare_finished (ErrorInfos error) {
|
||||
if (error.str == "") {
|
||||
if (error.message == "") {
|
||||
show_warnings ();
|
||||
TransactionType type = set_transaction_sum ();
|
||||
if (type == TransactionType.UPDATE && mode == Mode.UPDATER) {
|
||||
@ -1264,7 +1265,7 @@ namespace Pamac {
|
||||
Gtk.main_iteration ();
|
||||
if (type == TransactionType.BUILD) {
|
||||
// there only AUR packages to build
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
on_trans_commit_finished (err);
|
||||
} else
|
||||
start_commit ();
|
||||
@ -1281,8 +1282,8 @@ namespace Pamac {
|
||||
finished (true);
|
||||
}
|
||||
} else {
|
||||
//ErrorInfos err = ErrorInfos ();
|
||||
//err.str = dgettext (null, "Nothing to do") + "\n";
|
||||
//var err = ErrorInfos ();
|
||||
//err.message = dgettext (null, "Nothing to do") + "\n";
|
||||
spawn_in_term ({"echo", dgettext (null, "Nothing to do") + ".\n"});
|
||||
progress_dialog.hide ();
|
||||
while (Gtk.events_pending ())
|
||||
@ -1299,7 +1300,7 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
public void on_trans_commit_finished (ErrorInfos error) {
|
||||
if (error.str == "") {
|
||||
if (error.message == "") {
|
||||
if (to_build.size () != 0) {
|
||||
if (to_add.size () != 0
|
||||
|| to_remove.size () != 0
|
||||
@ -1342,7 +1343,7 @@ namespace Pamac {
|
||||
Source.remove (pulse_timeout_id);
|
||||
to_build.steal_all ();
|
||||
build_status = status;
|
||||
ErrorInfos err = ErrorInfos ();
|
||||
var err = ErrorInfos ();
|
||||
on_trans_commit_finished (err);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user