From bfee1fcc52bec611f85760318bf19f013fe4415e Mon Sep 17 00:00:00 2001 From: guinux Date: Fri, 3 Mar 2017 12:21:27 +0100 Subject: [PATCH] add files db support --- src/alpm_config.vala | 14 +++++++++ src/daemon.vala | 69 +++++++++++++++++++++++++++++------------ src/manager_window.vala | 47 +++++++++++++++++++++------- src/package.vala | 1 - src/transaction.vala | 10 ++++++ 5 files changed, 109 insertions(+), 32 deletions(-) diff --git a/src/alpm_config.vala b/src/alpm_config.vala index de90146..ab7279b 100644 --- a/src/alpm_config.vala +++ b/src/alpm_config.vala @@ -187,6 +187,20 @@ class AlpmConfig { return handle; } + public Alpm.Handle? get_files_handle () { + Alpm.Handle? handle = new Alpm.Handle (rootdir, dbpath, null); + if (handle == null) { + return null; + } + // define options + handle.dbext = ".files"; + // register dbs + foreach (unowned AlpmRepo repo in repo_order) { + handle.register_syncdb (repo.name, 0); + } + return handle; + } + void parse_file (string path, string? section = null) { string? current_section = section; var file = GLib.File.new_for_path (path); diff --git a/src/daemon.vala b/src/daemon.vala index f7d49d1..6757add 100644 --- a/src/daemon.vala +++ b/src/daemon.vala @@ -96,6 +96,7 @@ namespace Pamac { public class Daemon: Object { private AlpmConfig alpm_config; private Alpm.Handle? alpm_handle; + private Alpm.Handle? files_handle; public Cond provider_cond; public Mutex provider_mutex; public int? choosen_provider; @@ -230,6 +231,7 @@ namespace Pamac { alpm_handle.logcb = (Alpm.LogCallBack) cb_log; lockfile = GLib.File.new_for_path (alpm_handle.lockfile); } + files_handle = alpm_config.get_files_handle (); } private bool check_pacman_running () { @@ -433,6 +435,7 @@ namespace Pamac { uint success = 0; cancellable.reset (); init_curl (); + string[] dbexts = {".db", ".files"}; unowned Alpm.List syncdbs = alpm_handle.syncdbs; while (syncdbs != null) { unowned Alpm.DB db = syncdbs.data; @@ -442,13 +445,16 @@ namespace Pamac { databases_lock_mutex.unlock (); return; } - if (db.update (force) >= 0) { - success++; - } else { - Alpm.Errno errno = alpm_handle.errno (); - current_error.errno = (uint) errno; - if (errno != 0) { - current_error.details = { Alpm.strerror (errno) }; + foreach (unowned string dbext in dbexts) { + alpm_handle.dbext = dbext; + if (db.update (force) >= 0) { + success++; + } else { + Alpm.Errno errno = alpm_handle.errno (); + current_error.errno = (uint) errno; + if (errno != 0) { + current_error.details = { Alpm.strerror (errno) }; + } } } syncdbs.next (); @@ -1188,7 +1194,6 @@ namespace Pamac { string installdate = ""; string[] groups = {}; string[] backups = {}; - string[] files = {}; string[] licenses = {}; string[] depends = {}; string[] optdepends = {}; @@ -1273,14 +1278,6 @@ namespace Pamac { list.next (); } pkg_optionalfor.free_inner (GLib.free); - // files - unowned Alpm.FileList filelist = alpm_pkg.files; - Alpm.File* file_ptr = filelist.files; - for (size_t i = 0; i < filelist.count; i++, file_ptr++) { - if (!file_ptr->name.has_suffix ("/")) { - files += "/" + file_ptr->name; - } - } // sync pkg } else if (alpm_pkg.origin == Alpm.Package.From.SYNCDB) { // repos @@ -1339,10 +1336,41 @@ namespace Pamac { details.conflicts = (owned) conflicts; details.groups = (owned) groups; details.backups = (owned) backups; - details.files = (owned) files; return details; } + public string[] get_pkg_files (string pkgname) { + string[] files = {}; + unowned Alpm.Package? alpm_pkg = alpm_handle.localdb.get_pkg (pkgname); + if (alpm_pkg != null) { + unowned Alpm.FileList filelist = alpm_pkg.files; + Alpm.File* file_ptr = filelist.files; + for (size_t i = 0; i < filelist.count; i++, file_ptr++) { + if (!file_ptr->name.has_suffix ("/")) { + files += "/" + file_ptr->name; + } + } + } else { + unowned Alpm.List syncdbs = files_handle.syncdbs; + while (syncdbs != null) { + unowned Alpm.DB db = syncdbs.data; + unowned Alpm.Package? files_pkg = db.get_pkg (pkgname); + if (files_pkg != null) { + unowned Alpm.FileList filelist = files_pkg.files; + Alpm.File* file_ptr = filelist.files; + for (size_t i = 0; i < filelist.count; i++, file_ptr++) { + if (!file_ptr->name.has_suffix ("/")) { + files += "/" + file_ptr->name; + } + } + break; + } + syncdbs.next (); + } + } + return files; + } + public void start_get_updates (bool check_aur_updates) { UpdateInfos[] updates_infos = {}; unowned Alpm.Package? pkg = null; @@ -2410,6 +2438,9 @@ private int cb_fetch (string fileurl, string localpath, int force) { pamac_daemon.curl->setopt (Curl.Option.ERRORBUFFER, error_buffer); pamac_daemon.curl->setopt (Curl.Option.NOPROGRESS, 0L); pamac_daemon.curl->setopt (Curl.Option.XFERINFODATA, (void*) url.get_basename ()); + pamac_daemon.curl->setopt (Curl.Option.TIMECONDITION, Curl.TimeCond.NONE); + pamac_daemon.curl->setopt (Curl.Option.TIMEVALUE, 0); + pamac_daemon.curl->setopt (Curl.Option.RESUME_FROM_LARGE, 0); bool remove_partial_download = true; if (fileurl.contains (".pkg.tar.") && !fileurl.has_suffix (".sig")) { @@ -2545,8 +2576,8 @@ private int cb_fetch (string fileurl, string localpath, int force) { } catch (GLib.Error e) { stderr.printf ("Error: %s\n", e.message); } - // do not report error for missing sig with db - if (!fileurl.has_suffix ("db.sig")) { + // do not report error for missing sig + if (!fileurl.has_suffix (".sig")) { string hostname = url.get_uri ().split("/")[2]; pamac_daemon.emit_log ((uint) Alpm.LogLevel.ERROR, _("failed retrieving file '%s' from %s : %s\n").printf ( diff --git a/src/manager_window.vala b/src/manager_window.vala index b00b755..b2e4e6f 100644 --- a/src/manager_window.vala +++ b/src/manager_window.vala @@ -79,6 +79,8 @@ namespace Pamac { [GtkChild] Gtk.StackSwitcher packages_stackswitcher; [GtkChild] + Gtk.Stack properties_stack; + [GtkChild] Gtk.StackSwitcher properties_stackswitcher; [GtkChild] Gtk.Grid deps_grid; @@ -300,6 +302,7 @@ namespace Pamac { main_stack.notify["visible-child"].connect (on_main_stack_visible_child_changed); filters_stack.notify["visible-child"].connect (on_filters_stack_visible_child_changed); packages_stack.notify["visible-child"].connect (on_packages_stack_visible_child_changed); + properties_stack.notify["visible-child"].connect (on_properties_stack_visible_child_changed); return false; } @@ -622,18 +625,9 @@ namespace Pamac { } deps_grid.show_all (); // files - if (details.files.length > 0) { - files_scrolledwindow.visible = true; - StringBuilder text = new StringBuilder (); - foreach (unowned string file in details.files) { - if (text.len > 0) { - text.append ("\n"); - } - text.append (file); - } - files_textview.buffer.set_text (text.str, (int) text.len); - } else { - files_scrolledwindow.visible = false; + // will be populated on properties_stack switch + if (properties_stack.visible_child_name == "files") { + on_properties_stack_visible_child_changed (); } } @@ -871,6 +865,7 @@ namespace Pamac { void display_package_properties (string pkgname) { current_package_displayed = pkgname; + files_scrolledwindow.visible = true; set_package_details (current_package_displayed); } @@ -883,12 +878,17 @@ namespace Pamac { [GtkCallback] void on_packages_treeview_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) { if (column.title == dgettext (null, "Name")) { + this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); + while (Gtk.events_pending ()) { + Gtk.main_iteration (); + } main_stack.visible_child_name = "details"; Gtk.TreeIter iter; packages_list.get_iter (out iter, path); string pkgname; packages_list.get (iter, 1, out pkgname); display_package_properties (pkgname); + this.get_window ().set_cursor (null); } } @@ -939,6 +939,29 @@ namespace Pamac { } } + void on_properties_stack_visible_child_changed () { + switch (properties_stack.visible_child_name) { + case "files": + this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH)); + while (Gtk.events_pending ()) { + Gtk.main_iteration (); + } + string[] files = transaction.get_pkg_files (current_package_displayed); + StringBuilder text = new StringBuilder (); + foreach (unowned string file in files) { + if (text.len > 0) { + text.append ("\n"); + } + text.append (file); + } + files_textview.buffer.set_text (text.str, (int) text.len); + this.get_window ().set_cursor (null); + break; + default: + break; + } + } + void on_packages_state_icon_activated (Gtk.TreePath path) { Gtk.TreeIter iter; packages_list.get_iter (out iter, path); diff --git a/src/package.vala b/src/package.vala index 33f369c..b9cb72d 100644 --- a/src/package.vala +++ b/src/package.vala @@ -49,7 +49,6 @@ namespace Pamac { public string[] conflicts; public string[] groups; public string[] backups; - public string[] files; } public struct AURPackage { diff --git a/src/transaction.vala b/src/transaction.vala index 0dac7ae..2e59304 100644 --- a/src/transaction.vala +++ b/src/transaction.vala @@ -52,6 +52,7 @@ namespace Pamac { public abstract string[] get_groups_names () throws IOError; public abstract async AlpmPackage[] get_group_pkgs (string groupname) throws IOError; public abstract AlpmPackageDetails get_pkg_details (string pkgname) throws IOError; + public abstract string[] get_pkg_files (string pkgname) throws IOError; public abstract async AURPackageDetails get_aur_details (string pkgname) throws IOError; public abstract string[] get_pkg_uninstalled_optdeps (string pkgname) throws IOError; public abstract void start_get_updates (bool check_aur_updates) throws IOError; @@ -690,6 +691,15 @@ namespace Pamac { } } + public string[] get_pkg_files (string pkgname) { + try { + return daemon.get_pkg_files (pkgname); + } catch (IOError e) { + stderr.printf ("IOError: %s\n", e.message); + return {}; + } + } + public async AURPackageDetails get_aur_details (string pkgname) { var pkg = AURPackageDetails () { name = "",