[baobab/wip/vala: 22/53] rework code for excluded locations
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 22/53] rework code for excluded locations
- Date: Thu, 5 Apr 2012 22:03:24 +0000 (UTC)
commit 9341f910b0fc39c88e45f409d74d66d707a17339
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Jan 6 09:39:47 2012 -0500
rework code for excluded locations
Instead of keeping a list attached to the Baobab.Application and having
a method there for checking it, attach a list to the scanner object and
create it at the start of the scan.
This prevents the scanner from calling back into the application class
from the worker thread.
Also, switch to using a hashtable. We have at least 4 items in it (plus
the ones that the user added) so this should already be slightly faster
than a linear scan.
src/baobab-application.vala | 42 +++++++++++++++++--------------------
src/baobab-scanner.vala | 2 +
src/baobab-sync-scanner.vala | 2 +-
src/baobab-threaded-scanner.vala | 3 +-
src/baobab-window.vala | 8 +++---
5 files changed, 28 insertions(+), 29 deletions(-)
---
diff --git a/src/baobab-application.vala b/src/baobab-application.vala
index d346fa5..b96772b 100644
--- a/src/baobab-application.vala
+++ b/src/baobab-application.vala
@@ -23,8 +23,6 @@ namespace Baobab {
Settings prefs_settings;
Settings ui_settings;
- File[] excluded_locations;
-
static Application baobab;
protected override void activate () {
@@ -38,18 +36,31 @@ namespace Baobab {
}
}
- void excluded_uris_changed (Settings settings, string key) {
- var uris = settings.get_strv (key);
+ static void add_excluded_location (HashTable<File, unowned File> table, File file) {
+ table.insert (file, file);
+ }
+
+ public static HashTable<File, unowned File> get_excluded_locations () {
+ var app = baobab;
- excluded_locations = new File[0];
+ var excluded_locations = new HashTable<File, unowned File> (file_hash, file_equal);
+ add_excluded_location (excluded_locations, File.new_for_path ("/proc"));
+ add_excluded_location (excluded_locations, File.new_for_path ("/sys"));
+ add_excluded_location (excluded_locations, File.new_for_path ("/selinux"));
+ add_excluded_location (excluded_locations, File.new_for_path ("/selinux"));
+
+ var home = File.new_for_path (Environment.get_home_dir ());
+ add_excluded_location (excluded_locations, home.get_child (".gvfs"));
var root = File.new_for_path ("/");
- foreach (var uri in uris) {
- var file = File.new_for_uri (uri);
+ foreach (var uri in app.prefs_settings.get_value ("excluded-uris")) {
+ var file = File.new_for_uri ((string) uri);
if (!file.equal (root)) {
- excluded_locations += file;
+ excluded_locations.insert (file, file);
}
}
+
+ return excluded_locations;
}
protected override void startup () {
@@ -60,9 +71,6 @@ namespace Baobab {
ui_settings = new Settings ("org.gnome.baobab.ui");
prefs_settings = new Settings ("org.gnome.baobab.preferences");
desktop_settings = new Settings ("org.gnome.desktop.interface");
-
- excluded_uris_changed (prefs_settings, "excluded-uris");
- prefs_settings.changed["excluded-uris"] += excluded_uris_changed;
}
protected override bool local_command_line ([CCode (array_length = false, array_null_terminated = true)] ref unowned string[] arguments, out int exit_status) {
@@ -79,18 +87,6 @@ namespace Baobab {
Object (application_id: "org.gnome.baobab", flags: ApplicationFlags.HANDLES_OPEN);
}
- public static bool is_excluded_location (File file) {
- var app = baobab;
-
- foreach (var location in app.excluded_locations) {
- if (file.equal (location)) {
- return true;
- }
- }
-
- return false;
- }
-
public static Settings get_desktop_settings () {
var app = baobab;
return app.desktop_settings;
diff --git a/src/baobab-scanner.vala b/src/baobab-scanner.vala
index 66d50a7..7d5d830 100644
--- a/src/baobab-scanner.vala
+++ b/src/baobab-scanner.vala
@@ -49,6 +49,7 @@ namespace Baobab {
}
protected Cancellable cancellable;
+ protected HashTable<File, unowned File> excluded_locations;
protected HardLink[] hardlinks;
protected static const string ATTRIBUTES =
@@ -83,6 +84,7 @@ namespace Baobab {
typeof (int), /* ELEMENTS */
typeof (State)}); /* STATE */
set_sort_column_id (Columns.SIZE, Gtk.SortType.DESCENDING);
+ excluded_locations = Application.get_excluded_locations ();
}
}
}
diff --git a/src/baobab-sync-scanner.vala b/src/baobab-sync-scanner.vala
index 10f16ce..4cc5bd6 100644
--- a/src/baobab-sync-scanner.vala
+++ b/src/baobab-sync-scanner.vala
@@ -31,7 +31,7 @@ namespace Baobab {
var results = Results ();
Gtk.TreeIter iter;
- if (Application.is_excluded_location (directory)) {
+ if (excluded_locations.lookup (directory) != null) {
return results;
}
diff --git a/src/baobab-threaded-scanner.vala b/src/baobab-threaded-scanner.vala
index 5ab9bbe..09980f2 100644
--- a/src/baobab-threaded-scanner.vala
+++ b/src/baobab-threaded-scanner.vala
@@ -87,7 +87,7 @@ namespace Baobab {
Results? add_directory (File directory, FileInfo info, Results? parent = null) {
var results_array = new ResultsArray ();
- if (Application.is_excluded_location (directory)) {
+ if (excluded_locations.lookup (directory) != null) {
return null;
}
@@ -240,6 +240,7 @@ namespace Baobab {
protected override void scan (File directory) {
this.directory = directory;
+ this.excluded_locations = Application.get_excluded_locations ();
// the thread owns a reference on the Scanner object
this.self = this;
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 3554172..cdb9a4c 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -195,10 +195,10 @@ namespace Baobab {
}
public bool check_dir (File directory) {
- if (Application.is_excluded_location (directory)) {
- message("", _("Cannot check an excluded folder!"), Gtk.MessageType.INFO);
- return false;
- }
+ //if (Application.is_excluded_location (directory)) {
+ // message("", _("Cannot check an excluded folder!"), Gtk.MessageType.INFO);
+ // return false;
+ //}
try {
var info = directory.query_info (FILE_ATTRIBUTE_STANDARD_TYPE, FileQueryInfoFlags.NONE, null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]