move alpm functions in a separate file, all handled by Transaction

This commit is contained in:
guinux 2016-03-01 15:04:02 +01:00
parent 7234a4925b
commit 07ee57015b
11 changed files with 705 additions and 632 deletions

View File

@ -23,6 +23,7 @@ COMMON_SOURCES = ../util/alpm-util.c \
alpm_config.vala \ alpm_config.vala \
TRANSACTION_SOURCES = transaction.vala \ TRANSACTION_SOURCES = transaction.vala \
alpm_utils.vala \
aur.vala \ aur.vala \
choose_provider_dialog.vala \ choose_provider_dialog.vala \
transaction_sum_dialog.vala \ transaction_sum_dialog.vala \
@ -90,7 +91,7 @@ libpamac.so: ../vapi/libalpm.vapi $(COMMON_SOURCES) $(TRANSACTION_SOURCES) $(PRE
$(TRANSACTION_SOURCES) \ $(TRANSACTION_SOURCES) \
$(PREFERENCES_SOURCES) $(PREFERENCES_SOURCES)
pamac-manager: libpamac.so choose_dep_dialog.vala history_dialog.vala transaction_info_dialog.vala ../resources/manager_resources.c ../util/alpm-util.c alpm_utils.vala packages_model.vala aur_model.vala manager_window.vala manager.vala pamac-manager: libpamac.so choose_dep_dialog.vala history_dialog.vala transaction_info_dialog.vala ../resources/manager_resources.c ../util/alpm-util.c packages_model.vala aur_model.vala manager_window.vala manager.vala
valac -o pamac-manager \ valac -o pamac-manager \
$(COMMON_VALA_FLAGS) \ $(COMMON_VALA_FLAGS) \
-X -I. \ -X -I. \
@ -105,7 +106,6 @@ pamac-manager: libpamac.so choose_dep_dialog.vala history_dialog.vala transactio
../util/alpm-util.c \ ../util/alpm-util.c \
choose_dep_dialog.vala \ choose_dep_dialog.vala \
history_dialog.vala \ history_dialog.vala \
alpm_utils.vala \
packages_model.vala \ packages_model.vala \
aur_model.vala \ aur_model.vala \
manager_window.vala \ manager_window.vala \

View File

@ -17,450 +17,448 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Pamac { [Compact]
[Compact] public class AlpmRepo {
public class Repo { public string name;
public string name; public Alpm.Signature.Level siglevel;
public Alpm.Signature.Level siglevel; public Alpm.Signature.Level siglevel_mask;
public Alpm.Signature.Level siglevel_mask; public Alpm.DB.Usage usage;
public Alpm.DB.Usage usage; public GLib.List<string> urls;
public GLib.List<string> urls;
public Repo (string name) {
this.name = name;
siglevel = Alpm.Signature.Level.USE_DEFAULT;
usage = 0;
urls = new GLib.List<string> ();
}
public static int compare_name (Repo a, Repo b) {
return strcmp (a.name, b.name);
}
public static int search_name (Repo a, string name) {
return strcmp (a.name, name);
}
public AlpmRepo (string name) {
this.name = name;
siglevel = Alpm.Signature.Level.USE_DEFAULT;
usage = 0;
urls = new GLib.List<string> ();
} }
[Compact] public static int compare_name (AlpmRepo a, AlpmRepo b) {
public class AlpmConfig { return strcmp (a.name, b.name);
public string conf_path; }
public string? rootdir;
public string? dbpath;
public string? logfile;
public string? gpgdir;
public string? arch;
public double deltaratio;
public int usesyslog;
public int checkspace;
public Alpm.List<string>? cachedirs;
public Alpm.List<string?>? hookdirs;
public Alpm.List<string>? ignoregroups;
public Alpm.List<string>? ignorepkgs;
public Alpm.List<string>? noextracts;
public Alpm.List<string>? noupgrades;
public GLib.List<string>? holdpkgs;
public GLib.List<string>? syncfirsts;
public Alpm.Signature.Level siglevel;
public Alpm.Signature.Level localfilesiglevel;
public Alpm.Signature.Level remotefilesiglevel;
public Alpm.Signature.Level siglevel_mask;
public Alpm.Signature.Level localfilesiglevel_mask;
public Alpm.Signature.Level remotefilesiglevel_mask;
public GLib.List<Repo> repo_order;
public Alpm.Handle? handle;
public AlpmConfig (string path) { public static int search_name (AlpmRepo a, string name) {
conf_path = path; return strcmp (a.name, name);
reload (); }
}
[Compact]
public class AlpmConfig {
public string conf_path;
public string? rootdir;
public string? dbpath;
public string? logfile;
public string? gpgdir;
public string? arch;
public double deltaratio;
public int usesyslog;
public int checkspace;
public Alpm.List<string?>? cachedirs;
public Alpm.List<string?>? hookdirs;
public Alpm.List<string?>? ignoregroups;
public Alpm.List<string?>? ignorepkgs;
public Alpm.List<string?>? noextracts;
public Alpm.List<string?>? noupgrades;
public GLib.List<string>? holdpkgs;
public GLib.List<string>? syncfirsts;
public Alpm.Signature.Level siglevel;
public Alpm.Signature.Level localfilesiglevel;
public Alpm.Signature.Level remotefilesiglevel;
public Alpm.Signature.Level siglevel_mask;
public Alpm.Signature.Level localfilesiglevel_mask;
public Alpm.Signature.Level remotefilesiglevel_mask;
public GLib.List<AlpmRepo> repo_order;
public Alpm.Handle? handle;
public AlpmConfig (string path) {
conf_path = path;
reload ();
}
public void reload () {
// set default options
holdpkgs = new GLib.List<string> ();
syncfirsts = new GLib.List<string> ();
// free internal data of alpm lists
if (cachedirs != null) {
cachedirs.free_data ();
cachedirs = new Alpm.List<string> ();
} }
if (hookdirs != null) {
hookdirs.free_data ();
hookdirs = new Alpm.List<string?> ();
}
if (ignoregroups != null) {
ignoregroups.free_data ();
ignoregroups = new Alpm.List<string> ();
}
if (ignorepkgs != null) {
ignorepkgs.free_data ();
ignorepkgs = new Alpm.List<string> ();
}
if (noextracts != null) {
noextracts.free_data ();
noextracts = new Alpm.List<string> ();
}
if (noupgrades != null) {
noupgrades.free_data ();
noupgrades = new Alpm.List<string> ();
}
usesyslog = 0;
checkspace = 0;
deltaratio = 0.7;
siglevel = Alpm.Signature.Level.PACKAGE | Alpm.Signature.Level.PACKAGE_OPTIONAL | Alpm.Signature.Level.DATABASE | Alpm.Signature.Level.DATABASE_OPTIONAL;
localfilesiglevel = Alpm.Signature.Level.USE_DEFAULT;
remotefilesiglevel = Alpm.Signature.Level.USE_DEFAULT;
repo_order = new GLib.List<AlpmRepo> ();
// parse conf file
parse_file (conf_path);
// if rootdir is set and dbpath/logfile are not
// set, then set those as well to reside under the root.
if (rootdir != null) {
if (dbpath == null) {
dbpath = Path.build_path ("/", rootdir, "var/lib/pacman/");
}
if (logfile == null) {
logfile = Path.build_path ("/", rootdir, "var/log/pacman.log");
}
} else {
rootdir = "/";
if (dbpath == null) {
dbpath = "/var/lib/pacman/";
}
if (logfile == null) {
logfile = "/var/log/pacman.log";
}
}
if (cachedirs.length == 0) {
cachedirs.add ("/var/cache/pacman/pkg/");
}
if (hookdirs.length == 0) {
hookdirs.add ("/etc/pacman.d/hooks/");
}
if (gpgdir == null) {
// gpgdir it is not relative to rootdir, even if
// rootdir is defined because it contains configuration data.
gpgdir = "/etc/pacman.d/gnupg/";
}
if (arch == null) {
arch = Posix.utsname().machine;
}
}
public void reload () { public void set_handle () {
// set default options Alpm.Errno error;
holdpkgs = new GLib.List<string> (); handle = Alpm.Handle.new (rootdir, dbpath, out error);
syncfirsts = new GLib.List<string> (); if (handle == null) {
// free internal data of alpm lists stderr.printf ("Failed to initialize alpm library" + " (%s)\n".printf(Alpm.strerror (error)));
if (cachedirs != null) { return;
cachedirs.free_data (); }
cachedirs = new Alpm.List<string> (); // define options
handle.logfile = logfile;
handle.gpgdir = gpgdir;
handle.arch = arch;
handle.deltaratio = deltaratio;
handle.usesyslog = usesyslog;
handle.checkspace = checkspace;
handle.defaultsiglevel = siglevel;
localfilesiglevel = merge_siglevel (siglevel, localfilesiglevel, localfilesiglevel_mask);
remotefilesiglevel = merge_siglevel (siglevel, remotefilesiglevel, remotefilesiglevel_mask);
handle.localfilesiglevel = localfilesiglevel;
handle.remotefilesiglevel = remotefilesiglevel;
handle.cachedirs = cachedirs;
// add hook directories 1-by-1 to avoid overwriting the system directory
foreach (unowned string hookdir in hookdirs) {
handle.add_hookdir (hookdir);
}
handle.ignoregroups = ignoregroups;
handle.ignorepkgs = ignorepkgs;
handle.noextracts = noextracts;
handle.noupgrades = noupgrades;
// register dbs
foreach (unowned AlpmRepo repo in repo_order) {
repo.siglevel = merge_siglevel (siglevel, repo.siglevel, repo.siglevel_mask);
unowned Alpm.DB db = handle.register_syncdb (repo.name, repo.siglevel);
foreach (unowned string url in repo.urls) {
db.add_server (url.replace ("$repo", repo.name).replace ("$arch", handle.arch));
} }
if (hookdirs != null) { if (repo.usage == 0) {
hookdirs.free_data (); db.usage = Alpm.DB.Usage.ALL;
hookdirs = new Alpm.List<string?> ();
}
if (ignoregroups != null) {
ignoregroups.free_data ();
ignoregroups = new Alpm.List<string> ();
}
if (ignorepkgs != null) {
ignorepkgs.free_data ();
ignorepkgs = new Alpm.List<string> ();
}
if (noextracts != null) {
noextracts.free_data ();
noextracts = new Alpm.List<string> ();
}
if (noupgrades != null) {
noupgrades.free_data ();
noupgrades = new Alpm.List<string> ();
}
usesyslog = 0;
checkspace = 0;
deltaratio = 0.7;
siglevel = Alpm.Signature.Level.PACKAGE | Alpm.Signature.Level.PACKAGE_OPTIONAL | Alpm.Signature.Level.DATABASE | Alpm.Signature.Level.DATABASE_OPTIONAL;
localfilesiglevel = Alpm.Signature.Level.USE_DEFAULT;
remotefilesiglevel = Alpm.Signature.Level.USE_DEFAULT;
repo_order = new GLib.List<Repo> ();
// parse conf file
parse_file (conf_path);
// if rootdir is set and dbpath/logfile are not
// set, then set those as well to reside under the root.
if (rootdir != null) {
if (dbpath == null) {
dbpath = Path.build_path ("/", rootdir, "var/lib/pacman/");
}
if (logfile == null) {
logfile = Path.build_path ("/", rootdir, "var/log/pacman.log");
}
} else { } else {
rootdir = "/"; db.usage = repo.usage;
if (dbpath == null) {
dbpath = "/var/lib/pacman/";
}
if (logfile == null) {
logfile = "/var/log/pacman.log";
}
}
if (cachedirs.length == 0) {
cachedirs.add ("/var/cache/pacman/pkg/");
}
if (hookdirs.length == 0) {
hookdirs.add ("/etc/pacman.d/hooks/");
}
if (gpgdir == null) {
// gpgdir it is not relative to rootdir, even if
// rootdir is defined because it contains configuration data.
gpgdir = "/etc/pacman.d/gnupg/";
}
if (arch == null) {
arch = Posix.utsname().machine;
} }
} }
}
public void get_handle () { public void parse_file (string path, string? section = null) {
Alpm.Errno error; string? current_section = section;
handle = Alpm.Handle.new (rootdir, dbpath, out error); var file = GLib.File.new_for_path (path);
if (handle == null) { if (file.query_exists ()) {
stderr.printf ("Failed to initialize alpm library" + " (%s)\n".printf(Alpm.strerror (error))); try {
return; // Open file for reading and wrap returned FileInputStream into a
} // DataInputStream, so we can read line by line
// define options var dis = new DataInputStream (file.read ());
handle.logfile = logfile; string? line;
handle.gpgdir = gpgdir; // Read lines until end of file (null) is reached
handle.arch = arch; while ((line = dis.read_line ()) != null) {
handle.deltaratio = deltaratio; if (line.length == 0) {
handle.usesyslog = usesyslog; continue;
handle.checkspace = checkspace; }
handle.defaultsiglevel = siglevel; // ignore whole line and end of line comments
localfilesiglevel = merge_siglevel (siglevel, localfilesiglevel, localfilesiglevel_mask); string[] splitted = line.split ("#", 2);
remotefilesiglevel = merge_siglevel (siglevel, remotefilesiglevel, remotefilesiglevel_mask); line = splitted[0].strip ();
handle.localfilesiglevel = localfilesiglevel; if (line.length == 0) {
handle.remotefilesiglevel = remotefilesiglevel; continue;
handle.cachedirs = cachedirs; }
// add hook directories 1-by-1 to avoid overwriting the system directory if (line[0] == '[' && line[line.length-1] == ']') {
foreach (unowned string hookdir in hookdirs) { current_section = line[1:-1];
handle.add_hookdir (hookdir); if (current_section != "options") {
} var repo = new AlpmRepo (current_section);
handle.ignoregroups = ignoregroups; if (repo_order.find_custom (repo, AlpmRepo.compare_name) == null) {
handle.ignorepkgs = ignorepkgs; repo_order.append ((owned) repo);
handle.noextracts = noextracts;
handle.noupgrades = noupgrades;
// register dbs
foreach (unowned Repo repo in repo_order) {
repo.siglevel = merge_siglevel (siglevel, repo.siglevel, repo.siglevel_mask);
unowned Alpm.DB db = handle.register_syncdb (repo.name, repo.siglevel);
foreach (unowned string url in repo.urls) {
db.add_server (url.replace ("$repo", repo.name).replace ("$arch", handle.arch));
}
if (repo.usage == 0) {
db.usage = Alpm.DB.Usage.ALL;
} else {
db.usage = repo.usage;
}
}
}
public void parse_file (string path, string? section = null) {
string? current_section = section;
var file = GLib.File.new_for_path (path);
if (file.query_exists ()) {
try {
// Open file for reading and wrap returned FileInputStream into a
// DataInputStream, so we can read line by line
var dis = new DataInputStream (file.read ());
string? line;
// Read lines until end of file (null) is reached
while ((line = dis.read_line ()) != null) {
if (line.length == 0) {
continue;
}
// ignore whole line and end of line comments
string[] splitted = line.split ("#", 2);
line = splitted[0].strip ();
if (line.length == 0) {
continue;
}
if (line[0] == '[' && line[line.length-1] == ']') {
current_section = line[1:-1];
if (current_section != "options") {
var repo = new Repo (current_section);
if (repo_order.find_custom (repo, Repo.compare_name) == null) {
repo_order.append ((owned) repo);
}
} }
continue;
} }
splitted = line.split ("=", 2); continue;
unowned string key = splitted[0]._strip (); }
unowned string? val = null; splitted = line.split ("=", 2);
if (splitted.length == 2) { unowned string key = splitted[0]._strip ();
val = splitted[1]._strip (); unowned string? val = null;
if (splitted.length == 2) {
val = splitted[1]._strip ();
}
if (key == "Include") {
parse_file (val, current_section);
}
if (current_section == "options") {
if (key == "RootDir") {
rootdir = val;
} else if (key == "DBPath") {
dbpath = val;
} else if (key == "CacheDir") {
foreach (unowned string dir in val.split (" ")) {
cachedirs.add (dir);
}
} else if (key == "HookDir") {
foreach (unowned string dir in val.split (" ")) {
hookdirs.add (dir);
}
} else if (key == "LogFile") {
logfile = val;
} else if (key == "GPGDir") {
gpgdir = val;
} else if (key == "LogFile") {
logfile = val;
} else if (key == "Architecture") {
if (val == "auto") {
arch = Posix.utsname ().machine;
} else {
arch = val;
}
} else if (key == "UseDelta") {
deltaratio = double.parse (val);
} else if (key == "UseSysLog") {
usesyslog = 1;
} else if (key == "CheckSpace") {
checkspace = 1;
} else if (key == "SigLevel") {
process_siglevel (val, ref siglevel, ref siglevel_mask);
} else if (key == "LocalFileSigLevel") {
process_siglevel (val, ref localfilesiglevel, ref localfilesiglevel_mask);
} else if (key == "RemoteFileSigLevel") {
process_siglevel (val, ref remotefilesiglevel, ref remotefilesiglevel_mask);
} else if (key == "HoldPkg") {
foreach (unowned string name in val.split (" ")) {
holdpkgs.append (name);
}
} else if (key == "SyncFirst") {
foreach (unowned string name in val.split (" ")) {
syncfirsts.append (name);
}
} else if (key == "IgnoreGroup") {
foreach (unowned string name in val.split (" ")) {
ignoregroups.add (name);
}
} else if (key == "IgnorePkg") {
foreach (unowned string name in val.split (" ")) {
ignorepkgs.add (name);
}
} else if (key == "Noextract") {
foreach (unowned string name in val.split (" ")) {
noextracts.add (name);
}
} else if (key == "NoUpgrade") {
foreach (unowned string name in val.split (" ")) {
noupgrades.add (name);
}
} }
if (key == "Include") { } else {
parse_file (val, current_section); unowned GLib.List<AlpmRepo>? found = repo_order.search (current_section, (SearchFunc) AlpmRepo.search_name);
} if (found != null) {
if (current_section == "options") { unowned AlpmRepo repo = found.data;
if (key == "RootDir") { if (key == "Server") {
rootdir = val; repo.urls.append (val);
} else if (key == "DBPath") {
dbpath = val;
} else if (key == "CacheDir") {
foreach (unowned string dir in val.split (" ")) {
cachedirs.add (dir);
}
} else if (key == "HookDir") {
foreach (unowned string dir in val.split (" ")) {
hookdirs.add (dir);
}
} else if (key == "LogFile") {
logfile = val;
} else if (key == "GPGDir") {
gpgdir = val;
} else if (key == "LogFile") {
logfile = val;
} else if (key == "Architecture") {
if (val == "auto") {
arch = Posix.utsname ().machine;
} else {
arch = val;
}
} else if (key == "UseDelta") {
deltaratio = double.parse (val);
} else if (key == "UseSysLog") {
usesyslog = 1;
} else if (key == "CheckSpace") {
checkspace = 1;
} else if (key == "SigLevel") { } else if (key == "SigLevel") {
process_siglevel (val, ref siglevel, ref siglevel_mask); process_siglevel (val, ref repo.siglevel, ref repo.siglevel_mask);
} else if (key == "LocalFileSigLevel") { } else if (key == "Usage") {
process_siglevel (val, ref localfilesiglevel, ref localfilesiglevel_mask); repo.usage = define_usage (val);
} else if (key == "RemoteFileSigLevel") {
process_siglevel (val, ref remotefilesiglevel, ref remotefilesiglevel_mask);
} else if (key == "HoldPkg") {
foreach (unowned string name in val.split (" ")) {
holdpkgs.append (name);
}
} else if (key == "SyncFirst") {
foreach (unowned string name in val.split (" ")) {
syncfirsts.append (name);
}
} else if (key == "IgnoreGroup") {
foreach (unowned string name in val.split (" ")) {
ignoregroups.add (name);
}
} else if (key == "IgnorePkg") {
foreach (unowned string name in val.split (" ")) {
ignorepkgs.add (name);
}
} else if (key == "Noextract") {
foreach (unowned string name in val.split (" ")) {
noextracts.add (name);
}
} else if (key == "NoUpgrade") {
foreach (unowned string name in val.split (" ")) {
noupgrades.add (name);
}
}
} else {
unowned GLib.List<Repo>? found = repo_order.search (current_section, (SearchFunc) Repo.search_name);
if (found != null) {
unowned Repo repo = found.data;
if (key == "Server") {
repo.urls.append (val);
} else if (key == "SigLevel") {
process_siglevel (val, ref repo.siglevel, ref repo.siglevel_mask);
} else if (key == "Usage") {
repo.usage = define_usage (val);
}
} }
} }
} }
} catch (GLib.Error e) {
GLib.stderr.printf("%s\n", e.message);
} }
} else { } catch (GLib.Error e) {
GLib.stderr.printf ("File '%s' doesn't exist.\n", path); GLib.stderr.printf("%s\n", e.message);
} }
} else {
GLib.stderr.printf ("File '%s' doesn't exist.\n", path);
} }
}
public void write (HashTable<string,Variant> new_conf) { public void write (HashTable<string,Variant> new_conf) {
var file = GLib.File.new_for_path (conf_path); var file = GLib.File.new_for_path (conf_path);
if (file.query_exists ()) { if (file.query_exists ()) {
try { try {
// Open file for reading and wrap returned FileInputStream into a // Open file for reading and wrap returned FileInputStream into a
// DataInputStream, so we can read line by line // DataInputStream, so we can read line by line
var dis = new DataInputStream (file.read ()); var dis = new DataInputStream (file.read ());
string? line; string? line;
string[] data = {}; string[] data = {};
// Read lines until end of file (null) is reached // Read lines until end of file (null) is reached
while ((line = dis.read_line ()) != null) { while ((line = dis.read_line ()) != null) {
if (line.length == 0) { if (line.length == 0) {
data += "\n"; data += "\n";
continue; continue;
} }
if (line.contains ("IgnorePkg")) { if (line.contains ("IgnorePkg")) {
if (new_conf.contains ("IgnorePkg")) { if (new_conf.contains ("IgnorePkg")) {
string val = new_conf.get ("IgnorePkg").get_string (); string val = new_conf.get ("IgnorePkg").get_string ();
if (val == "") { if (val == "") {
data += "#IgnorePkg =\n"; data += "#IgnorePkg =\n";
} else {
data += "IgnorePkg = %s\n".printf (val);
}
new_conf.remove ("IgnorePkg");
} else { } else {
data += line + "\n"; data += "IgnorePkg = %s\n".printf (val);
}
} else if (line.contains ("CheckSpace")) {
if (new_conf.contains ("CheckSpace")) {
bool val = new_conf.get ("CheckSpace").get_boolean ();
if (val) {
data += "CheckSpace\n";
} else {
data += "#CheckSpace\n";
}
new_conf.remove ("CheckSpace");
} else {
data += line + "\n";
} }
new_conf.remove ("IgnorePkg");
} else { } else {
data += line + "\n"; data += line + "\n";
} }
} else if (line.contains ("CheckSpace")) {
if (new_conf.contains ("CheckSpace")) {
bool val = new_conf.get ("CheckSpace").get_boolean ();
if (val) {
data += "CheckSpace\n";
} else {
data += "#CheckSpace\n";
}
new_conf.remove ("CheckSpace");
} else {
data += line + "\n";
}
} else {
data += line + "\n";
} }
// delete the file before rewrite it
file.delete ();
// creating a DataOutputStream to the file
var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION));
foreach (unowned string new_line in data) {
// writing a short string to the stream
dos.put_string (new_line);
}
} catch (GLib.Error e) {
GLib.stderr.printf("%s\n", e.message);
} }
} else { // delete the file before rewrite it
GLib.stderr.printf ("File '%s' doesn't exist.\n", conf_path); file.delete ();
// creating a DataOutputStream to the file
var dos = new DataOutputStream (file.create (FileCreateFlags.REPLACE_DESTINATION));
foreach (unowned string new_line in data) {
// writing a short string to the stream
dos.put_string (new_line);
}
} catch (GLib.Error e) {
GLib.stderr.printf("%s\n", e.message);
} }
} } else {
GLib.stderr.printf ("File '%s' doesn't exist.\n", conf_path);
public Alpm.DB.Usage define_usage (string conf_string) {
Alpm.DB.Usage usage = 0;
foreach (unowned string directive in conf_string.split(" ")) {
if (directive == "Sync") {
usage |= Alpm.DB.Usage.SYNC;
} else if (directive == "Search") {
usage |= Alpm.DB.Usage.SEARCH;
} else if (directive == "Install") {
usage |= Alpm.DB.Usage.INSTALL;
} else if (directive == "Upgrade") {
usage |= Alpm.DB.Usage.UPGRADE;
} else if (directive == "All") {
usage |= Alpm.DB.Usage.ALL;
}
}
return usage;
}
public void process_siglevel (string conf_string, ref Alpm.Signature.Level siglevel, ref Alpm.Signature.Level siglevel_mask) {
foreach (unowned string directive in conf_string.split(" ")) {
bool affect_package = false;
bool affect_database = false;
if ("Package" in directive) {
affect_package = true;
} else if ("Database" in directive) {
affect_database = true;
} else {
affect_package = true;
affect_database = true;
}
if ("Never" in directive) {
if (affect_package) {
siglevel &= ~Alpm.Signature.Level.PACKAGE;
siglevel_mask |= Alpm.Signature.Level.PACKAGE;
}
if (affect_database) {
siglevel &= ~Alpm.Signature.Level.DATABASE;
siglevel_mask |= Alpm.Signature.Level.DATABASE;
}
} else if ("Optional" in directive) {
if (affect_package) {
siglevel |= (Alpm.Signature.Level.PACKAGE | Alpm.Signature.Level.PACKAGE_OPTIONAL);
siglevel_mask |= (Alpm.Signature.Level.PACKAGE | Alpm.Signature.Level.PACKAGE_OPTIONAL);
}
if (affect_database) {
siglevel |= (Alpm.Signature.Level.DATABASE | Alpm.Signature.Level.DATABASE_OPTIONAL);
siglevel_mask |= (Alpm.Signature.Level.DATABASE | Alpm.Signature.Level.DATABASE_OPTIONAL);
}
} else if ("Required" in directive) {
if (affect_package) {
siglevel |= Alpm.Signature.Level.PACKAGE;
siglevel_mask |= Alpm.Signature.Level.PACKAGE;
siglevel &= ~Alpm.Signature.Level.PACKAGE_OPTIONAL;
siglevel_mask |= Alpm.Signature.Level.PACKAGE_OPTIONAL;
}
if (affect_database) {
siglevel |= Alpm.Signature.Level.DATABASE;
siglevel_mask |= Alpm.Signature.Level.DATABASE;
siglevel &= ~Alpm.Signature.Level.DATABASE_OPTIONAL;
siglevel_mask |= Alpm.Signature.Level.DATABASE_OPTIONAL;
}
} else if ("TrustedOnly" in directive) {
if (affect_package) {
siglevel &= ~(Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
}
if (affect_database) {
siglevel &= ~(Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
}
} else if ("TrustAll" in directive) {
if (affect_package) {
siglevel |= (Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
}
if (affect_database) {
siglevel |= (Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
}
} else {
GLib.stderr.printf("unrecognized siglevel: %s\n", conf_string);
}
}
siglevel &= ~Alpm.Signature.Level.USE_DEFAULT;
}
public Alpm.Signature.Level merge_siglevel(Alpm.Signature.Level sigbase, Alpm.Signature.Level sigover, Alpm.Signature.Level sigmask) {
return (sigmask != 0) ? (sigover & sigmask) | (sigbase & ~sigmask) : sigover;
} }
} }
public Alpm.DB.Usage define_usage (string conf_string) {
Alpm.DB.Usage usage = 0;
foreach (unowned string directive in conf_string.split(" ")) {
if (directive == "Sync") {
usage |= Alpm.DB.Usage.SYNC;
} else if (directive == "Search") {
usage |= Alpm.DB.Usage.SEARCH;
} else if (directive == "Install") {
usage |= Alpm.DB.Usage.INSTALL;
} else if (directive == "Upgrade") {
usage |= Alpm.DB.Usage.UPGRADE;
} else if (directive == "All") {
usage |= Alpm.DB.Usage.ALL;
}
}
return usage;
}
public void process_siglevel (string conf_string, ref Alpm.Signature.Level siglevel, ref Alpm.Signature.Level siglevel_mask) {
foreach (unowned string directive in conf_string.split(" ")) {
bool affect_package = false;
bool affect_database = false;
if ("Package" in directive) {
affect_package = true;
} else if ("Database" in directive) {
affect_database = true;
} else {
affect_package = true;
affect_database = true;
}
if ("Never" in directive) {
if (affect_package) {
siglevel &= ~Alpm.Signature.Level.PACKAGE;
siglevel_mask |= Alpm.Signature.Level.PACKAGE;
}
if (affect_database) {
siglevel &= ~Alpm.Signature.Level.DATABASE;
siglevel_mask |= Alpm.Signature.Level.DATABASE;
}
} else if ("Optional" in directive) {
if (affect_package) {
siglevel |= (Alpm.Signature.Level.PACKAGE | Alpm.Signature.Level.PACKAGE_OPTIONAL);
siglevel_mask |= (Alpm.Signature.Level.PACKAGE | Alpm.Signature.Level.PACKAGE_OPTIONAL);
}
if (affect_database) {
siglevel |= (Alpm.Signature.Level.DATABASE | Alpm.Signature.Level.DATABASE_OPTIONAL);
siglevel_mask |= (Alpm.Signature.Level.DATABASE | Alpm.Signature.Level.DATABASE_OPTIONAL);
}
} else if ("Required" in directive) {
if (affect_package) {
siglevel |= Alpm.Signature.Level.PACKAGE;
siglevel_mask |= Alpm.Signature.Level.PACKAGE;
siglevel &= ~Alpm.Signature.Level.PACKAGE_OPTIONAL;
siglevel_mask |= Alpm.Signature.Level.PACKAGE_OPTIONAL;
}
if (affect_database) {
siglevel |= Alpm.Signature.Level.DATABASE;
siglevel_mask |= Alpm.Signature.Level.DATABASE;
siglevel &= ~Alpm.Signature.Level.DATABASE_OPTIONAL;
siglevel_mask |= Alpm.Signature.Level.DATABASE_OPTIONAL;
}
} else if ("TrustedOnly" in directive) {
if (affect_package) {
siglevel &= ~(Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
}
if (affect_database) {
siglevel &= ~(Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
}
} else if ("TrustAll" in directive) {
if (affect_package) {
siglevel |= (Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.PACKAGE_MARGINAL_OK | Alpm.Signature.Level.PACKAGE_UNKNOWN_OK);
}
if (affect_database) {
siglevel |= (Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
siglevel_mask |= (Alpm.Signature.Level.DATABASE_MARGINAL_OK | Alpm.Signature.Level.DATABASE_UNKNOWN_OK);
}
} else {
GLib.stderr.printf("unrecognized siglevel: %s\n", conf_string);
}
}
siglevel &= ~Alpm.Signature.Level.USE_DEFAULT;
}
public Alpm.Signature.Level merge_siglevel(Alpm.Signature.Level sigbase, Alpm.Signature.Level sigover, Alpm.Signature.Level sigmask) {
return (sigmask != 0) ? (sigover & sigmask) | (sigbase & ~sigmask) : sigover;
}
} }

View File

@ -1,7 +1,7 @@
/* /*
* pamac-vala * pamac-vala
* *
* Copyright (C) 2015-2016 Guillaume Benoit <guillaume@manjaro.org> * Copyright (C) 2014-2016 Guillaume Benoit <guillaume@manjaro.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -17,22 +17,174 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
int compare_name (Alpm.Package pkg_a, Alpm.Package pkg_b) { public int alpm_pkg_compare_name (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return strcmp (pkg_a.name, pkg_b.name); return strcmp (pkg_a.name, pkg_b.name);
} }
int compare_state (Alpm.Package pkg_a, Alpm.Package pkg_b) { public int alpm_pkg_compare_origin (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return (int) (pkg_a.origin > pkg_b.origin) - (int) (pkg_a.origin < pkg_b.origin); return (int) (pkg_a.origin > pkg_b.origin) - (int) (pkg_a.origin < pkg_b.origin);
} }
int compare_version (Alpm.Package pkg_a, Alpm.Package pkg_b) { public int alpm_pkg_compare_version (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return Alpm.pkg_vercmp (pkg_a.version, pkg_b.version); return Alpm.pkg_vercmp (pkg_a.version, pkg_b.version);
} }
int compare_repo (Alpm.Package pkg_a, Alpm.Package pkg_b) { public int alpm_pkg_compare_db_name (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return strcmp (pkg_a.db.name, pkg_b.db.name); return strcmp (pkg_a.db.name, pkg_b.db.name);
} }
int compare_size (Alpm.Package pkg_a, Alpm.Package pkg_b) { public int alpm_pkg_compare_installed_size (Alpm.Package pkg_a, Alpm.Package pkg_b) {
return (int) (pkg_a.isize > pkg_b.isize) - (int) (pkg_a.isize < pkg_b.isize); return (int) (pkg_a.isize > pkg_b.isize) - (int) (pkg_a.isize < pkg_b.isize);
} }
public class AlpmUtils {
AlpmConfig alpm_config;
public AlpmUtils (string conf_file_path) {
alpm_config = new AlpmConfig (conf_file_path);
alpm_config.set_handle ();
}
public bool reload () {
alpm_config.reload ();
alpm_config.set_handle ();
if (alpm_config.handle != null) {
return true;
}
return false;
}
public int get_checkspace () {
return alpm_config.checkspace;
}
public unowned GLib.List<string> get_holdpkgs () {
return alpm_config.holdpkgs;
}
public unowned Alpm.List<unowned string?> get_ignorepkgs () {
return alpm_config.ignorepkgs;
}
public unowned Alpm.Package? get_installed_pkg (string pkg_name) {
return alpm_config.handle.localdb.get_pkg (pkg_name);
}
public unowned Alpm.Package? get_sync_pkg (string pkg_name) {
unowned Alpm.Package? pkg = null;
foreach (var db in alpm_config.handle.syncdbs) {
pkg = db.get_pkg (pkg_name);
if (pkg != null) {
break;
}
}
return pkg;
}
public unowned Alpm.DB? get_localdb () {
return alpm_config.handle.localdb;
}
public unowned Alpm.List<unowned Alpm.DB?> get_syncdbs () {
return alpm_config.handle.syncdbs;
}
public Alpm.List<unowned Alpm.Package?> search_all_dbs (string search_string) {
var syncpkgs = new Alpm.List<unowned Alpm.Package?> ();
var needles = new Alpm.List<unowned string> ();
string[] splitted = search_string.split (" ");
foreach (unowned string part in splitted) {
needles.add (part);
}
var result = alpm_config.handle.localdb.search (needles);
foreach (var db in alpm_config.handle.syncdbs) {
if (syncpkgs.length == 0) {
syncpkgs = db.search (needles);
} else {
syncpkgs.join (db.search (needles).diff (syncpkgs, (Alpm.List.CompareFunc) alpm_pkg_compare_name));
}
}
result.join (syncpkgs.diff (result, (Alpm.List.CompareFunc) alpm_pkg_compare_name));
//result.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_name);
return result;
}
public Alpm.List<unowned Alpm.Package?> get_group_pkgs (string group_name) {
var result = new Alpm.List<unowned Alpm.Package?> ();
unowned Alpm.Group? grp = alpm_config.handle.localdb.get_group (group_name);
if (grp != null) {
foreach (var pkg in grp.packages) {
result.add (pkg);
}
}
result.join (Alpm.find_group_pkgs (alpm_config.handle.syncdbs, group_name).diff (result, (Alpm.List.CompareFunc) alpm_pkg_compare_name));
//result.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_name);
return result;
}
public Alpm.List<unowned Alpm.Package?> get_installed_pkgs () {
return alpm_config.handle.localdb.pkgcache.copy ();
}
public Alpm.List<unowned Alpm.Package?> get_orphans () {
var result = new Alpm.List<unowned Alpm.Package?> ();
foreach (var pkg in alpm_config.handle.localdb.pkgcache) {
if (pkg.reason == Alpm.Package.Reason.DEPEND) {
Alpm.List<string?> requiredby = pkg.compute_requiredby ();
if (requiredby.length == 0) {
Alpm.List<string?> optionalfor = pkg.compute_optionalfor ();
if (optionalfor.length == 0) {
result.add (pkg);
}
optionalfor.free_data ();
}
requiredby.free_data ();
}
}
return result;
}
public Alpm.List<unowned Alpm.Package?> get_local_pkgs () {
var result = new Alpm.List<unowned Alpm.Package?> ();
foreach (var pkg in alpm_config.handle.localdb.pkgcache) {
if (get_sync_pkg (pkg.name) == null) {
result.add (pkg);
}
}
return result;
}
public Alpm.List<unowned Alpm.Package?> get_repo_pkgs (string repo_name) {
var result = new Alpm.List<unowned Alpm.Package?> ();
foreach (var db in alpm_config.handle.syncdbs) {
if (db.name == repo_name) {
foreach (var sync_pkg in db.pkgcache) {
unowned Alpm.Package?local_pkg = alpm_config.handle.localdb.get_pkg (sync_pkg.name);
if (local_pkg != null) {
result.add (local_pkg);
} else {
result.add (sync_pkg);
}
}
}
}
return result;
}
public Alpm.List<unowned Alpm.Package?> get_all_pkgs () {
var syncpkgs = new Alpm.List<unowned Alpm.Package?> ();
var result = new Alpm.List<unowned Alpm.Package?> ();
result = alpm_config.handle.localdb.pkgcache.copy ();
foreach (var db in alpm_config.handle.syncdbs) {
if (syncpkgs.length == 0)
syncpkgs = db.pkgcache.copy ();
else {
syncpkgs.join (db.pkgcache.diff (syncpkgs, (Alpm.List.CompareFunc) alpm_pkg_compare_name));
}
}
result.join (syncpkgs.diff (result, (Alpm.List.CompareFunc) alpm_pkg_compare_name));
//result.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_name);
return result;
}
}

View File

@ -25,8 +25,8 @@ int aur_compare_name (Json.Object pkg_a, Json.Object pkg_b) {
} }
int aur_compare_state (Json.Object pkg_a, Json.Object pkg_b) { int aur_compare_state (Json.Object pkg_a, Json.Object pkg_b) {
unowned Alpm.Package? alpm_pkg_a = manager_window.transaction.alpm_config.handle.localdb.get_pkg (pkg_a.get_string_member ("Name")); unowned Alpm.Package? alpm_pkg_a = manager_window.transaction.alpm_utils.get_installed_pkg (pkg_a.get_string_member ("Name"));
unowned Alpm.Package? alpm_pkg_b = manager_window.transaction.alpm_config.handle.localdb.get_pkg (pkg_b.get_string_member ("Name")); unowned Alpm.Package? alpm_pkg_b = manager_window.transaction.alpm_utils.get_installed_pkg (pkg_b.get_string_member ("Name"));
if (pkg_a != null) { if (pkg_a != null) {
if (pkg_b != null) { if (pkg_b != null) {
return (int) (alpm_pkg_a.origin > alpm_pkg_b.origin) - (int) (alpm_pkg_a.origin < alpm_pkg_b.origin); return (int) (alpm_pkg_a.origin > alpm_pkg_b.origin) - (int) (alpm_pkg_a.origin < alpm_pkg_b.origin);
@ -100,9 +100,9 @@ namespace Pamac {
case 1: case 1:
val = Value (typeof (Object)); val = Value (typeof (Object));
if (pkg_info != null) { if (pkg_info != null) {
unowned Alpm.Package? pkg = manager_window.transaction.alpm_config.handle.localdb.get_pkg (pkg_info.get_string_member ("Name")); unowned Alpm.Package? pkg = manager_window.transaction.alpm_utils.get_installed_pkg (pkg_info.get_string_member ("Name"));
if (pkg != null) { if (pkg != null) {
if (manager_window.transaction.alpm_config.holdpkgs.find_custom (pkg.name, strcmp) != null) { if (manager_window.transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) != null) {
val.set_object (manager_window.locked_icon); val.set_object (manager_window.locked_icon);
} else if (manager_window.transaction.to_add.contains (pkg.name)) { } else if (manager_window.transaction.to_add.contains (pkg.name)) {
val.set_object (manager_window.to_reinstall_icon); val.set_object (manager_window.to_reinstall_icon);
@ -121,7 +121,7 @@ namespace Pamac {
case 2: case 2:
val = Value (typeof (string)); val = Value (typeof (string));
if (pkg_info != null) { if (pkg_info != null) {
unowned Alpm.Package? pkg = manager_window.transaction.alpm_config.handle.localdb.get_pkg (pkg_info.get_string_member ("Name")); unowned Alpm.Package? pkg = manager_window.transaction.alpm_utils.get_installed_pkg (pkg_info.get_string_member ("Name"));
if (pkg != null) { if (pkg != null) {
val.set_string (pkg.version); val.set_string (pkg.version);
} else { } else {

View File

@ -131,7 +131,7 @@ namespace Pamac {
} }
private void refresh_handle () { private void refresh_handle () {
alpm_config.get_handle (); alpm_config.set_handle ();
if (alpm_config.handle == null) { if (alpm_config.handle == null) {
current_error = ErrorInfos () { current_error = ErrorInfos () {
message = _("Failed to initialize alpm library"), message = _("Failed to initialize alpm library"),

View File

@ -132,10 +132,13 @@ namespace Pamac {
public SortInfo sortinfo; public SortInfo sortinfo;
bool refreshing;
public ManagerWindow (Gtk.Application application) { public ManagerWindow (Gtk.Application application) {
Object (application: application); Object (application: application);
support_aur (false, false); support_aur (false, false);
refreshing = false;
Timeout.add (100, populate_window); Timeout.add (100, populate_window);
} }
@ -196,7 +199,7 @@ namespace Pamac {
transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished); transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
transaction.set_pkgreason_finished.connect (on_set_pkgreason_finished); transaction.set_pkgreason_finished.connect (on_set_pkgreason_finished);
unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, "yaourt"); unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), "yaourt");
if (pkg != null) { if (pkg != null) {
support_aur (transaction.pamac_config.enable_aur, transaction.pamac_config.search_aur); support_aur (transaction.pamac_config.enable_aur, transaction.pamac_config.search_aur);
} }
@ -219,7 +222,7 @@ namespace Pamac {
if (recurse) { if (recurse) {
transaction.flags |= Alpm.TransFlag.RECURSE; transaction.flags |= Alpm.TransFlag.RECURSE;
} }
unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, "yaourt"); unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), "yaourt");
if (pkg != null) { if (pkg != null) {
support_aur (enable_aur, search_aur); support_aur (enable_aur, search_aur);
} }
@ -246,115 +249,6 @@ namespace Pamac {
cancel_button.set_sensitive (sensitive); cancel_button.set_sensitive (sensitive);
} }
async Alpm.List<unowned Alpm.Package?> search_all_dbs (string search_string) {
var syncpkgs = new Alpm.List<unowned Alpm.Package?> ();
var needles = new Alpm.List<unowned string> ();
string[] splitted = search_string.split (" ");
foreach (unowned string part in splitted) {
needles.add (part);
}
var result = transaction.alpm_config.handle.localdb.search (needles);
foreach (var db in transaction.alpm_config.handle.syncdbs) {
if (syncpkgs.length == 0) {
syncpkgs = db.search (needles);
} else {
syncpkgs.join (db.search (needles).diff (syncpkgs, (Alpm.List.CompareFunc) compare_name));
}
}
result.join (syncpkgs.diff (result, (Alpm.List.CompareFunc) compare_name));
//result.sort ((Alpm.List.CompareFunc) compare_name);
return result;
}
async Alpm.List<unowned Alpm.Package?> get_group_pkgs (string grp_name) {
var result = new Alpm.List<unowned Alpm.Package?> ();
unowned Alpm.Group? grp = transaction.alpm_config.handle.localdb.get_group (grp_name);
if (grp != null) {
foreach (var pkg in grp.packages) {
result.add (pkg);
}
}
result.join (Alpm.find_group_pkgs (transaction.alpm_config.handle.syncdbs, grp_name).diff (result, (Alpm.List.CompareFunc) compare_name));
//result.sort ((Alpm.List.CompareFunc) compare_name);
return result;
}
async Alpm.List<unowned Alpm.Package?> get_installed_pkgs () {
return transaction.alpm_config.handle.localdb.pkgcache.copy ();
}
async Alpm.List<unowned Alpm.Package?> get_orphans () {
var result = new Alpm.List<unowned Alpm.Package?> ();
foreach (var pkg in transaction.alpm_config.handle.localdb.pkgcache) {
if (pkg.reason == Alpm.Package.Reason.DEPEND) {
Alpm.List<string?> requiredby = pkg.compute_requiredby ();
if (requiredby.length == 0) {
Alpm.List<string?> optionalfor = pkg.compute_optionalfor ();
if (optionalfor.length == 0) {
result.add (pkg);
}
optionalfor.free_data ();
}
requiredby.free_data ();
}
}
return result;
}
async Alpm.List<unowned Alpm.Package?> get_local_pkgs () {
var result = new Alpm.List<unowned Alpm.Package?> ();
foreach (var pkg in transaction.alpm_config.handle.localdb.pkgcache) {
if (get_sync_pkg (pkg.name) == null) {
result.add (pkg);
}
}
return result;
}
async Alpm.List<unowned Alpm.Package?> get_repo_pkgs (string reponame) {
var result = new Alpm.List<unowned Alpm.Package?> ();
foreach (var db in transaction.alpm_config.handle.syncdbs) {
if (db.name == reponame) {
foreach (var sync_pkg in db.pkgcache) {
unowned Alpm.Package?local_pkg = transaction.alpm_config.handle.localdb.get_pkg (sync_pkg.name);
if (local_pkg != null) {
result.add (local_pkg);
} else {
result.add (sync_pkg);
}
}
}
}
return result;
}
//~ async Alpm.List<unowned Alpm.Package?> get_all_pkgs () {
//~ var syncpkgs = new Alpm.List<unowned Alpm.Package?> ();
//~ var result = new Alpm.List<unowned Alpm.Package?> ();
//~ result = transaction.alpm_config.handle.localdb.pkgcache.copy ();
//~ foreach (var db in transaction.alpm_config.handle.syncdbs) {
//~ if (syncpkgs.length == 0)
//~ syncpkgs = db.pkgcache.copy ();
//~ else {
//~ syncpkgs.join (db.pkgcache.diff (syncpkgs, (Alpm.List.CompareFunc) compare_name));
//~ }
//~ }
//~ result.join (syncpkgs.diff (result, (Alpm.List.CompareFunc) compare_name));
//~ //result.sort ((Alpm.List.CompareFunc) compare_name);
//~ return result;
//~ }
unowned Alpm.Package? get_sync_pkg (string pkgname) {
unowned Alpm.Package? pkg = null;
foreach (var db in transaction.alpm_config.handle.syncdbs) {
pkg = db.get_pkg (pkgname);
if (pkg != null) {
break;
}
}
return pkg;
}
void show_default_pkgs () { void show_default_pkgs () {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
get_installed_pkgs.begin ((obj, res) => { get_installed_pkgs.begin ((obj, res) => {
@ -369,7 +263,7 @@ namespace Pamac {
selection = repos_treeview.get_selection (); selection = repos_treeview.get_selection ();
selection.changed.disconnect (on_repos_treeview_selection_changed); selection.changed.disconnect (on_repos_treeview_selection_changed);
var groups_names = new GLib.List<string> (); var groups_names = new GLib.List<string> ();
foreach (var db in transaction.alpm_config.handle.syncdbs) { foreach (var db in transaction.alpm_utils.get_syncdbs ()) {
repos_list.insert_with_values (out iter, -1, 0, db.name); repos_list.insert_with_values (out iter, -1, 0, db.name);
foreach (var group in db.groupcache) { foreach (var group in db.groupcache) {
if (groups_names.find_custom (group.name, strcmp) == null) { if (groups_names.find_custom (group.name, strcmp) == null) {
@ -384,7 +278,7 @@ namespace Pamac {
selection = groups_treeview.get_selection (); selection = groups_treeview.get_selection ();
selection.changed.disconnect (on_groups_treeview_selection_changed); selection.changed.disconnect (on_groups_treeview_selection_changed);
foreach (var group in transaction.alpm_config.handle.localdb.groupcache) { foreach (var group in transaction.alpm_utils.get_localdb ().groupcache) {
if (groups_names.find_custom (group.name, strcmp) == null) { if (groups_names.find_custom (group.name, strcmp) == null) {
groups_names.append (group.name); groups_names.append (group.name);
} }
@ -481,7 +375,7 @@ namespace Pamac {
list = deps; list = deps;
string optdep_str = list.data.compute_string (); string optdep_str = list.data.compute_string ();
var optdep = new StringBuilder (optdep_str); var optdep = new StringBuilder (optdep_str);
if (Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, optdep_str) != null) { if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str) != null) {
optdep.append (" ["); optdep.append (" [");
optdep.append (dgettext (null, "Installed")); optdep.append (dgettext (null, "Installed"));
optdep.append ("]"); optdep.append ("]");
@ -492,7 +386,7 @@ namespace Pamac {
for (list = list.next (); list != null; list = list.next ()) { for (list = list.next (); list != null; list = list.next ()) {
optdep_str = list.data.compute_string (); optdep_str = list.data.compute_string ();
optdep = new StringBuilder (optdep_str); optdep = new StringBuilder (optdep_str);
if (Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, optdep_str) != null) { if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str) != null) {
optdep.append (" ["); optdep.append (" [");
optdep.append (dgettext (null, "Installed")); optdep.append (dgettext (null, "Installed"));
optdep.append ("]"); optdep.append ("]");
@ -620,7 +514,7 @@ namespace Pamac {
deps = node.get_array (); deps = node.get_array ();
string optdep_str = deps.get_string_element (0); string optdep_str = deps.get_string_element (0);
var optdep = new StringBuilder (optdep_str); var optdep = new StringBuilder (optdep_str);
if (Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, optdep_str) != null) { if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str) != null) {
optdep.append (" ["); optdep.append (" [");
optdep.append (dgettext (null, "Installed")); optdep.append (dgettext (null, "Installed"));
optdep.append ("]"); optdep.append ("]");
@ -633,7 +527,7 @@ namespace Pamac {
while (i < length) { while (i < length) {
optdep_str = deps.get_string_element (i); optdep_str = deps.get_string_element (i);
optdep = new StringBuilder (optdep_str); optdep = new StringBuilder (optdep_str);
if (Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, optdep_str.split (": ", 2)[0]) != null) { if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep_str.split (": ", 2)[0]) != null) {
optdep.append (" ["); optdep.append (" [");
optdep.append (dgettext (null, "Installed")); optdep.append (dgettext (null, "Installed"));
optdep.append ("]"); optdep.append ("]");
@ -984,7 +878,7 @@ namespace Pamac {
if (pkg_info == null) { if (pkg_info == null) {
return; return;
} }
unowned Alpm.Package? pkg = transaction.alpm_config.handle.localdb.get_pkg (pkg_info.get_string_member ("Name")); unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkg_info.get_string_member ("Name"));
if (pkg == null) { if (pkg == null) {
files_scrolledwindow.visible = false; files_scrolledwindow.visible = false;
switch (properties_notebook.get_current_page ()) { switch (properties_notebook.get_current_page ()) {
@ -1050,7 +944,7 @@ namespace Pamac {
} else if (transaction.to_remove.remove (pkg.name)) { } else if (transaction.to_remove.remove (pkg.name)) {
} else { } else {
if (pkg.origin == Alpm.Package.From.LOCALDB) { if (pkg.origin == Alpm.Package.From.LOCALDB) {
if (transaction.alpm_config.holdpkgs.find_custom (pkg.name, strcmp) == null) { if (transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) == null) {
transaction.to_remove.add (pkg.name); transaction.to_remove.add (pkg.name);
} }
} else { } else {
@ -1071,10 +965,10 @@ namespace Pamac {
void on_aur_treeview_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) { void on_aur_treeview_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) {
unowned Json.Object? pkg_info = aur_list.get_pkg_at_path (path); unowned Json.Object? pkg_info = aur_list.get_pkg_at_path (path);
if (pkg_info != null) { if (pkg_info != null) {
unowned Alpm.Package? pkg = transaction.alpm_config.handle.localdb.get_pkg (pkg_info.get_string_member ("Name")); unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkg_info.get_string_member ("Name"));
if (pkg != null) { if (pkg != null) {
if (pkg.origin == Alpm.Package.From.LOCALDB) { if (pkg.origin == Alpm.Package.From.LOCALDB) {
if (transaction.alpm_config.holdpkgs.find_custom (pkg.name, strcmp) == null) { if (transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) == null) {
transaction.to_remove.add (pkg.name); transaction.to_remove.add (pkg.name);
} }
} }
@ -1121,7 +1015,7 @@ namespace Pamac {
void on_remove_item_activate () { void on_remove_item_activate () {
foreach (var pkg in selected_pkgs) { foreach (var pkg in selected_pkgs) {
transaction.to_add.remove (pkg.name); transaction.to_add.remove (pkg.name);
if (transaction.alpm_config.holdpkgs.find_custom (pkg.name, strcmp) == null) { if (transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) == null) {
if (pkg.origin == Alpm.Package.From.LOCALDB) { if (pkg.origin == Alpm.Package.From.LOCALDB) {
transaction.to_remove.add (pkg.name); transaction.to_remove.add (pkg.name);
} }
@ -1156,7 +1050,7 @@ namespace Pamac {
Gtk.TreeIter iter; Gtk.TreeIter iter;
int length = 0; int length = 0;
foreach (var optdep in pkg.optdepends) { foreach (var optdep in pkg.optdepends) {
if (Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, optdep.name) == null) { if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep.name) == null) {
length++; length++;
choose_dep_dialog.deps_list.insert_with_values (out iter, -1, choose_dep_dialog.deps_list.insert_with_values (out iter, -1,
0, false, 0, false,
@ -1175,7 +1069,7 @@ namespace Pamac {
if ((bool) val) { if ((bool) val) {
// get value at column 1 to get the pkg name // get value at column 1 to get the pkg name
choose_dep_dialog.deps_list.get_value (iter, 1, out val); choose_dep_dialog.deps_list.get_value (iter, 1, out val);
unowned Alpm.Package? sync_pkg = get_sync_pkg ((string) val); unowned Alpm.Package? sync_pkg = transaction.alpm_utils.get_sync_pkg ((string) val);
if (sync_pkg != null) { if (sync_pkg != null) {
transaction.to_add.add (sync_pkg.name); transaction.to_add.add (sync_pkg.name);
} }
@ -1289,7 +1183,7 @@ namespace Pamac {
clicked_pkg = selected_pkgs.data; clicked_pkg = selected_pkgs.data;
if (clicked_pkg.origin == Alpm.Package.From.LOCALDB) { if (clicked_pkg.origin == Alpm.Package.From.LOCALDB) {
foreach (var optdep in clicked_pkg.optdepends) { foreach (var optdep in clicked_pkg.optdepends) {
if (Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, optdep.name) == null) { if (Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), optdep.name) == null) {
install_optional_deps_item.set_sensitive (true); install_optional_deps_item.set_sensitive (true);
break; break;
} }
@ -1297,7 +1191,7 @@ namespace Pamac {
if (clicked_pkg.reason == Alpm.Package.Reason.DEPEND) { if (clicked_pkg.reason == Alpm.Package.Reason.DEPEND) {
explicitly_installed_item.set_sensitive (true); explicitly_installed_item.set_sensitive (true);
} }
unowned Alpm.Package? find_pkg = get_sync_pkg (clicked_pkg.name); unowned Alpm.Package? find_pkg = transaction.alpm_utils.get_sync_pkg (clicked_pkg.name);
if (find_pkg != null) { if (find_pkg != null) {
if (Alpm.pkg_vercmp (find_pkg.version, clicked_pkg.version) == 0) { if (Alpm.pkg_vercmp (find_pkg.version, clicked_pkg.version) == 0) {
reinstall_item.set_sensitive (true); reinstall_item.set_sensitive (true);
@ -1339,7 +1233,7 @@ namespace Pamac {
selected_pkgs = new Alpm.List<unowned Alpm.Package?> (); selected_pkgs = new Alpm.List<unowned Alpm.Package?> ();
selected_aur = new GLib.List<unowned Json.Object> (); selected_aur = new GLib.List<unowned Json.Object> ();
foreach (unowned Gtk.TreePath path in selected_paths) { foreach (unowned Gtk.TreePath path in selected_paths) {
unowned Alpm.Package? pkg = transaction.alpm_config.handle.localdb.get_pkg (clicked_pkg_info.get_string_member ("Name")); unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (clicked_pkg_info.get_string_member ("Name"));
if (pkg != null) { if (pkg != null) {
selected_pkgs.add (pkg); selected_pkgs.add (pkg);
// there is for sure a pkg to remove // there is for sure a pkg to remove
@ -1573,6 +1467,30 @@ namespace Pamac {
on_search_entry_activate (); on_search_entry_activate ();
} }
async Alpm.List<unowned Alpm.Package?> search_all_dbs (string search_string) {
return transaction.alpm_utils.search_all_dbs (search_string);
}
async Alpm.List<unowned Alpm.Package?> get_group_pkgs (string group_name) {
return transaction.alpm_utils.get_group_pkgs (group_name);
}
async Alpm.List<unowned Alpm.Package?> get_installed_pkgs () {
return transaction.alpm_utils.get_installed_pkgs ();
}
async Alpm.List<unowned Alpm.Package?> get_orphans () {
return transaction.alpm_utils.get_orphans ();
}
async Alpm.List<unowned Alpm.Package?> get_local_pkgs () {
return transaction.alpm_utils.get_local_pkgs ();
}
async Alpm.List<unowned Alpm.Package?> get_repo_pkgs (string repo_name) {
return transaction.alpm_utils.get_repo_pkgs (repo_name);
}
[GtkCallback] [GtkCallback]
void on_search_treeview_selection_changed () { void on_search_treeview_selection_changed () {
Gtk.TreeModel model; Gtk.TreeModel model;
@ -1644,9 +1562,9 @@ namespace Pamac {
if (state == dgettext (null, "To install")) { if (state == dgettext (null, "To install")) {
var pkgs = new Alpm.List<unowned Alpm.Package?> (); var pkgs = new Alpm.List<unowned Alpm.Package?> ();
foreach (unowned string pkgname in transaction.to_add) { foreach (unowned string pkgname in transaction.to_add) {
unowned Alpm.Package? pkg = transaction.alpm_config.handle.localdb.get_pkg (pkgname); unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkgname);
if (pkg == null) { if (pkg == null) {
pkg = get_sync_pkg (pkgname); pkg = transaction.alpm_utils.get_sync_pkg (pkgname);
} }
if (pkg != null) { if (pkg != null) {
pkgs.add (pkg); pkgs.add (pkg);
@ -1656,7 +1574,7 @@ namespace Pamac {
} else if (state == dgettext (null, "To remove")) { } else if (state == dgettext (null, "To remove")) {
var pkgs = new Alpm.List<unowned Alpm.Package?> (); var pkgs = new Alpm.List<unowned Alpm.Package?> ();
foreach (unowned string pkgname in transaction.to_remove) { foreach (unowned string pkgname in transaction.to_remove) {
unowned Alpm.Package? pkg = transaction.alpm_config.handle.localdb.get_pkg (pkgname); unowned Alpm.Package? pkg = transaction.alpm_utils.get_installed_pkg (pkgname);
if (pkg != null) { if (pkg != null) {
pkgs.add (pkg); pkgs.add (pkg);
} }
@ -1815,17 +1733,20 @@ namespace Pamac {
[GtkCallback] [GtkCallback]
void on_refresh_button_clicked () { void on_refresh_button_clicked () {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
refreshing = true;
transaction.start_refresh (false); transaction.start_refresh (false);
} }
void on_transaction_finished (bool database_modified) { void on_transaction_finished (bool success) {
if (database_modified) { set_buttons_sensitive (false);
set_buttons_sensitive (false); refresh_packages_list ();
refresh_packages_list ();
} else {
this.get_window ().set_cursor (null);
}
transaction.to_load.remove_all (); transaction.to_load.remove_all ();
if (refreshing) {
if (success) {
transaction.sysupgrade (false);
}
refreshing = false;
}
} }
} }
} }

View File

@ -62,7 +62,7 @@ namespace Pamac {
val = Value (typeof (Object)); val = Value (typeof (Object));
if (pkg != null) { if (pkg != null) {
if (pkg.origin == Alpm.Package.From.LOCALDB) { if (pkg.origin == Alpm.Package.From.LOCALDB) {
if (manager_window.transaction.alpm_config.holdpkgs.find_custom (pkg.name, strcmp) != null) { if (manager_window.transaction.alpm_utils.get_holdpkgs ().find_custom (pkg.name, strcmp) != null) {
val.set_object (manager_window.locked_icon); val.set_object (manager_window.locked_icon);
} else if (manager_window.transaction.to_add.contains (pkg.name)) { } else if (manager_window.transaction.to_add.contains (pkg.name)) {
val.set_object (manager_window.to_reinstall_icon); val.set_object (manager_window.to_reinstall_icon);
@ -184,7 +184,7 @@ namespace Pamac {
// custom sort functions // custom sort functions
public void sort_by_name (Gtk.SortType order) { public void sort_by_name (Gtk.SortType order) {
pkgs.sort ((Alpm.List.CompareFunc) compare_name); pkgs.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_name);
if (order == Gtk.SortType.DESCENDING) { if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse (); pkgs.reverse ();
} }
@ -199,7 +199,7 @@ namespace Pamac {
} }
public void sort_by_state (Gtk.SortType order) { public void sort_by_state (Gtk.SortType order) {
pkgs.sort ((Alpm.List.CompareFunc) compare_state); pkgs.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_origin);
if (order == Gtk.SortType.DESCENDING) { if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse (); pkgs.reverse ();
} }
@ -214,7 +214,7 @@ namespace Pamac {
} }
public void sort_by_version (Gtk.SortType order) { public void sort_by_version (Gtk.SortType order) {
pkgs.sort ((Alpm.List.CompareFunc) compare_version); pkgs.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_version);
if (order == Gtk.SortType.DESCENDING) { if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse (); pkgs.reverse ();
} }
@ -229,7 +229,7 @@ namespace Pamac {
} }
public void sort_by_repo (Gtk.SortType order) { public void sort_by_repo (Gtk.SortType order) {
pkgs.sort ((Alpm.List.CompareFunc) compare_repo); pkgs.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_db_name);
if (order == Gtk.SortType.DESCENDING) { if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse (); pkgs.reverse ();
} }
@ -244,7 +244,7 @@ namespace Pamac {
} }
public void sort_by_size (Gtk.SortType order) { public void sort_by_size (Gtk.SortType order) {
pkgs.sort ((Alpm.List.CompareFunc) compare_size); pkgs.sort ((Alpm.List.CompareFunc) alpm_pkg_compare_installed_size);
if (order == Gtk.SortType.DESCENDING) { if (order == Gtk.SortType.DESCENDING) {
pkgs.reverse (); pkgs.reverse ();
} }

View File

@ -68,7 +68,7 @@ namespace Pamac {
this.transaction = transaction; this.transaction = transaction;
refresh_period_label.set_markup (dgettext (null, "How often to check for updates, value in hours") +":"); refresh_period_label.set_markup (dgettext (null, "How often to check for updates, value in hours") +":");
remove_unrequired_deps_button.active = transaction.pamac_config.recurse; remove_unrequired_deps_button.active = transaction.pamac_config.recurse;
check_space_button.active = (transaction.alpm_config.checkspace == 1); check_space_button.active = (transaction.alpm_utils.get_checkspace () == 1);
if (transaction.pamac_config.refresh_period == 0) { if (transaction.pamac_config.refresh_period == 0) {
check_updates_button.active = false; check_updates_button.active = false;
refresh_period_label.sensitive = false; refresh_period_label.sensitive = false;
@ -87,8 +87,8 @@ namespace Pamac {
// populate ignorepkgs_liststore // populate ignorepkgs_liststore
Gtk.TreeIter iter; Gtk.TreeIter iter;
for (unowned Alpm.List<string> list = transaction.alpm_config.ignorepkgs; list != null; list = list.next ()) { foreach (unowned string ignorepkg in transaction.alpm_utils.get_ignorepkgs ()) {
ignorepkgs_liststore.insert_with_values (out iter, -1, 0, list.data); ignorepkgs_liststore.insert_with_values (out iter, -1, 0, ignorepkg);
} }
remove_unrequired_deps_button.state_set.connect (on_remove_unrequired_deps_button_state_set); remove_unrequired_deps_button.state_set.connect (on_remove_unrequired_deps_button_state_set);
check_space_button.state_set.connect (on_check_space_button_state_set); check_space_button.state_set.connect (on_check_space_button_state_set);
@ -98,7 +98,7 @@ namespace Pamac {
no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled); no_update_hide_icon_checkbutton.toggled.connect (on_no_update_hide_icon_checkbutton_toggled);
transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished); transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, "pacman-mirrorlist"); unowned Alpm.Package? pkg = Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), "pacman-mirrorlist");
if (pkg == null) { if (pkg == null) {
mirrors_config_box.visible = false; mirrors_config_box.visible = false;
} else { } else {
@ -126,7 +126,7 @@ namespace Pamac {
transaction.write_mirrors_config_finished.connect (on_write_mirrors_config_finished); transaction.write_mirrors_config_finished.connect (on_write_mirrors_config_finished);
} }
pkg = Alpm.find_satisfier (transaction.alpm_config.handle.localdb.pkgcache, "yaourt"); pkg = Alpm.find_satisfier (transaction.alpm_utils.get_installed_pkgs (), "yaourt");
if (pkg == null) { if (pkg == null) {
aur_config_box.visible = false; aur_config_box.visible = false;
} else { } else {
@ -248,9 +248,9 @@ namespace Pamac {
[GtkCallback] [GtkCallback]
void on_add_ignorepkgs_button_clicked () { void on_add_ignorepkgs_button_clicked () {
var choose_ignorepkgs_dialog = new ChooseIgnorepkgsDialog (this); var choose_ignorepkgs_dialog = new ChooseIgnorepkgsDialog (this);
foreach (var pkg in transaction.alpm_config.handle.localdb.pkgcache) { foreach (var pkg in transaction.alpm_utils.get_installed_pkgs ()) {
Gtk.TreeIter iter; Gtk.TreeIter iter;
if (transaction.alpm_config.ignorepkgs.find_str (pkg.name) == null) { if (transaction.alpm_utils.get_ignorepkgs ().find_str (pkg.name) == null) {
choose_ignorepkgs_dialog.pkgs_list.insert_with_values (out iter, -1, 0, false, 1, pkg.name); choose_ignorepkgs_dialog.pkgs_list.insert_with_values (out iter, -1, 0, false, 1, pkg.name);
} else { } else {
choose_ignorepkgs_dialog.pkgs_list.insert_with_values (out iter, -1, 0, true, 1, pkg.name); choose_ignorepkgs_dialog.pkgs_list.insert_with_values (out iter, -1, 0, true, 1, pkg.name);
@ -311,8 +311,8 @@ namespace Pamac {
// re-populate ignorepkgs_liststore // re-populate ignorepkgs_liststore
Gtk.TreeIter iter; Gtk.TreeIter iter;
ignorepkgs_liststore.clear (); ignorepkgs_liststore.clear ();
for (unowned Alpm.List<string> list = transaction.alpm_config.ignorepkgs; list != null; list = list.next ()) { foreach (unowned string ignorepkg in transaction.alpm_utils.get_ignorepkgs ()) {
ignorepkgs_liststore.insert_with_values (out iter, -1, 0, list.data); ignorepkgs_liststore.insert_with_values (out iter, -1, 0, ignorepkg);
} }
} }

View File

@ -84,7 +84,7 @@ namespace Pamac {
Daemon daemon; Daemon daemon;
public AlpmConfig alpm_config; public AlpmUtils alpm_utils;
public Pamac.Config pamac_config; public Pamac.Config pamac_config;
public Alpm.TransFlag flags; public Alpm.TransFlag flags;
@ -113,6 +113,7 @@ namespace Pamac {
uint64 rates_nb; uint64 rates_nb;
Timer timer; Timer timer;
bool database_modified; bool database_modified;
bool success;
//dialogs //dialogs
TransactionSumDialog transaction_sum_dialog; TransactionSumDialog transaction_sum_dialog;
@ -121,7 +122,7 @@ namespace Pamac {
//parent window //parent window
public Gtk.ApplicationWindow? application_window; public Gtk.ApplicationWindow? application_window;
public signal void finished (bool database_modified); public signal void finished (bool success);
public signal void set_pkgreason_finished (); public signal void set_pkgreason_finished ();
public signal void get_updates_finished (Updates updates); public signal void get_updates_finished (Updates updates);
public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon, public signal void write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
@ -131,8 +132,7 @@ namespace Pamac {
public signal void write_mirrors_config_finished (string choosen_country, string choosen_generation_method); public signal void write_mirrors_config_finished (string choosen_country, string choosen_generation_method);
public Transaction (Gtk.ApplicationWindow? application_window) { public Transaction (Gtk.ApplicationWindow? application_window) {
alpm_config = new AlpmConfig ("/etc/pacman.conf"); alpm_utils = new AlpmUtils ("/etc/pacman.conf");
refresh_handle ();
pamac_config = new Pamac.Config ("/etc/pamac.conf"); pamac_config = new Pamac.Config ("/etc/pamac.conf");
flags = Alpm.TransFlag.CASCADE; flags = Alpm.TransFlag.CASCADE;
if (pamac_config.recurse) { if (pamac_config.recurse) {
@ -162,6 +162,7 @@ namespace Pamac {
sysupgrade_after_trans = false; sysupgrade_after_trans = false;
timer = new Timer (); timer = new Timer ();
database_modified = false; database_modified = false;
success = false;
} }
public async void run_preferences_dialog () { public async void run_preferences_dialog () {
@ -182,13 +183,6 @@ namespace Pamac {
daemon.disconnect (handler_id); daemon.disconnect (handler_id);
} }
public void refresh_handle () {
alpm_config.get_handle ();
if (alpm_config.handle == null) {
stderr.printf (dgettext (null, "Failed to initialize alpm library"));
}
}
public ErrorInfos get_current_error () { public ErrorInfos get_current_error () {
try { try {
return daemon.get_current_error (); return daemon.get_current_error ();
@ -280,15 +274,29 @@ namespace Pamac {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
daemon.refresh_finished.disconnect (on_refresh_finished); daemon.refresh_finished.disconnect (on_refresh_finished);
database_modified = true; database_modified = true;
success = false;
finish_transaction (); finish_transaction ();
} }
} }
public void start_get_updates () { public void start_get_updates () {
daemon.get_updates_finished.connect (on_get_updates_finished);
try { try {
daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates); daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates);
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
success = false;
finish_transaction ();
}
}
void start_get_updates_for_sysupgrade () {
daemon.get_updates_finished.connect (on_get_updates_for_sysupgrade_finished);
try {
daemon.start_get_updates (pamac_config.enable_aur && pamac_config.check_aur_updates);
} catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message);
success = false;
finish_transaction (); finish_transaction ();
} }
} }
@ -325,7 +333,7 @@ namespace Pamac {
void sysupgrade_simple (bool enable_downgrade) { void sysupgrade_simple (bool enable_downgrade) {
progress_dialog.progressbar.set_fraction (0); progress_dialog.progressbar.set_fraction (0);
progress_dialog.cancel_button.set_visible (true); progress_dialog.cancel_button.set_visible (true);
bool success = init (0); success = init (0);
if (success) { if (success) {
try { try {
success = daemon.trans_sysupgrade (enable_downgrade); success = daemon.trans_sysupgrade (enable_downgrade);
@ -343,6 +351,7 @@ namespace Pamac {
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
release (); release ();
success = false;
finish_transaction (); finish_transaction ();
} }
} else { } else {
@ -366,12 +375,16 @@ namespace Pamac {
while (Gtk.events_pending ()) { while (Gtk.events_pending ()) {
Gtk.main_iteration (); Gtk.main_iteration ();
} }
// sysupgrade start_get_updates_for_sysupgrade ();
daemon.get_updates_finished.connect (on_get_updates_finished);
start_get_updates ();
} }
void on_get_updates_finished (Updates updates) { void on_get_updates_finished (Updates updates) {
daemon.get_updates_finished.disconnect (on_get_updates_finished);
get_updates_finished (updates);
}
void on_get_updates_for_sysupgrade_finished (Updates updates) {
daemon.get_updates_finished.disconnect (on_get_updates_for_sysupgrade_finished);
// get syncfirst updates // get syncfirst updates
if (updates.is_syncfirst) { if (updates.is_syncfirst) {
clear_lists (); clear_lists ();
@ -402,8 +415,6 @@ namespace Pamac {
on_trans_prepare_finished (true); on_trans_prepare_finished (true);
} }
} }
daemon.get_updates_finished.disconnect (on_get_updates_finished);
get_updates_finished (updates);
} }
public void clear_lists () { public void clear_lists () {
@ -432,7 +443,7 @@ namespace Pamac {
// there only AUR packages to build so no need to prepare transaction // there only AUR packages to build so no need to prepare transaction
on_trans_prepare_finished (true); on_trans_prepare_finished (true);
} else { } else {
bool success = false; success = false;
try { try {
success = daemon.trans_init (flags); success = daemon.trans_init (flags);
} catch (IOError e) { } catch (IOError e) {
@ -476,6 +487,7 @@ namespace Pamac {
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
release (); release ();
success = false;
finish_transaction (); finish_transaction ();
} }
} else { } else {
@ -647,6 +659,7 @@ namespace Pamac {
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
database_modified = true; database_modified = true;
success = false;
finish_transaction (); finish_transaction ();
} }
} }
@ -1150,31 +1163,23 @@ namespace Pamac {
void finish_transaction () { void finish_transaction () {
if (database_modified) { if (database_modified) {
refresh_handle (); alpm_utils.reload ();
database_modified = false;
} }
if (progress_dialog.expander.get_expanded ()) { if (progress_dialog.expander.get_expanded ()) {
progress_dialog.cancel_button.set_visible (false); progress_dialog.cancel_button.set_visible (false);
progress_dialog.close_button.set_visible (true); progress_dialog.close_button.set_visible (true);
} else { } else {
finished (database_modified); on_progress_dialog_close_button_clicked ();
progress_dialog.hide ();
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
} }
database_modified = false;
} }
void on_refresh_finished (bool success) { void on_refresh_finished (bool success) {
database_modified = true; database_modified = true;
this.success = success;
clear_lists ();
if (success) { if (success) {
if (mode == Mode.UPDATER) { finish_transaction ();
finish_transaction ();
} else {
refresh_handle ();
clear_lists ();
sysupgrade (false);
}
} else { } else {
handle_error (get_current_error ()); handle_error (get_current_error ());
} }
@ -1183,11 +1188,12 @@ namespace Pamac {
} }
void on_progress_dialog_close_button_clicked () { void on_progress_dialog_close_button_clicked () {
finished (database_modified); finished (success);
progress_dialog.hide (); progress_dialog.hide ();
while (Gtk.events_pending ()) { while (Gtk.events_pending ()) {
Gtk.main_iteration (); Gtk.main_iteration ();
} }
success = false;
} }
void on_progress_dialog_cancel_button_clicked () { void on_progress_dialog_cancel_button_clicked () {
@ -1201,6 +1207,7 @@ namespace Pamac {
} }
void on_trans_prepare_finished (bool success) { void on_trans_prepare_finished (bool success) {
this.success = success;
if (success) { if (success) {
show_warnings (); show_warnings ();
Type type = set_transaction_sum (); Type type = set_transaction_sum ();
@ -1228,6 +1235,7 @@ namespace Pamac {
release (); release ();
//to_build.remove_all (); //to_build.remove_all ();
sysupgrade_after_trans = false; sysupgrade_after_trans = false;
success = false;
finish_transaction (); finish_transaction ();
} }
} else { } else {
@ -1245,6 +1253,7 @@ namespace Pamac {
} }
void on_trans_commit_finished (bool success) { void on_trans_commit_finished (bool success) {
this.success = success;
if (success) { if (success) {
if (to_build.length != 0) { if (to_build.length != 0) {
if (to_add.length != 0 if (to_add.length != 0
@ -1270,13 +1279,11 @@ namespace Pamac {
} else { } else {
// if it is an authentication error, database was not modified // if it is an authentication error, database was not modified
var err = get_current_error (); var err = get_current_error ();
if (err.message == dgettext (null, "Authentication failed")) { if (err.message != dgettext (null, "Authentication failed")) {
handle_error (err);
} else {
clear_lists (); clear_lists ();
database_modified = true; database_modified = true;
handle_error (err);
} }
handle_error (err);
} }
total_download = 0; total_download = 0;
already_downloaded = 0; already_downloaded = 0;
@ -1289,21 +1296,25 @@ namespace Pamac {
// let the time to the daemon to update databases // let the time to the daemon to update databases
Timeout.add (1000, () => { Timeout.add (1000, () => {
if (status == 0) { if (status == 0) {
success = true;
unowned string action = dgettext (null, "Transaction successfully finished"); unowned string action = dgettext (null, "Transaction successfully finished");
progress_dialog.spawn_in_term ({"echo", action + ".\n"}); progress_dialog.spawn_in_term ({"echo", action + ".\n"});
progress_dialog.action_label.set_text (action); progress_dialog.action_label.set_text (action);
} else { } else {
success = false;
progress_dialog.spawn_in_term ({"echo"}); progress_dialog.spawn_in_term ({"echo"});
} }
progress_dialog.progressbar.set_fraction (1); progress_dialog.progressbar.set_fraction (1);
database_modified = true; alpm_utils.reload ();
finish_transaction (); database_modified = false;
progress_dialog.cancel_button.set_visible (false);
progress_dialog.close_button.set_visible (true);
return false; return false;
}); });
} }
void on_set_pkgreason_finished () { void on_set_pkgreason_finished () {
refresh_handle (); alpm_utils.reload ();
set_pkgreason_finished (); set_pkgreason_finished ();
} }
@ -1317,7 +1328,7 @@ namespace Pamac {
} }
void on_write_alpm_config_finished (bool checkspace) { void on_write_alpm_config_finished (bool checkspace) {
alpm_config.reload (); alpm_utils.reload ();
write_alpm_config_finished (checkspace); write_alpm_config_finished (checkspace);
} }

View File

@ -321,7 +321,7 @@ namespace Pamac {
Notify.init (_("Update Manager")); Notify.init (_("Update Manager"));
var alpm_config = new AlpmConfig ("/etc/pacman.conf"); var alpm_config = new AlpmConfig ("/etc/pacman.conf");
alpm_config.get_handle (); alpm_config.set_handle ();
lockfile = GLib.File.new_for_path (alpm_config.handle.lockfile); lockfile = GLib.File.new_for_path (alpm_config.handle.lockfile);
start_daemon (); start_daemon ();
Timeout.add (200, check_pacman_running); Timeout.add (200, check_pacman_running);

View File

@ -69,8 +69,7 @@ namespace Pamac {
transaction = new Transaction (this as Gtk.ApplicationWindow); transaction = new Transaction (this as Gtk.ApplicationWindow);
transaction.mode = Mode.UPDATER; transaction.mode = Mode.UPDATER;
transaction.finished.connect (on_transaction_finished); transaction.finished.connect (populate_updates_list);
transaction.get_updates_finished.connect (on_get_updates_finished); transaction.get_updates_finished.connect (on_get_updates_finished);
on_refresh_button_clicked (); on_refresh_button_clicked ();
@ -159,14 +158,6 @@ namespace Pamac {
this.application.quit (); this.application.quit ();
} }
void on_transaction_finished (bool database_modified) {
if (database_modified) {
populate_updates_list ();
} else {
this.get_window ().set_cursor (null);
}
}
void populate_updates_list () { void populate_updates_list () {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
transaction.start_get_updates (); transaction.start_get_updates ();