Merge lp:~mhr3/unity-lens-files/fix-955229 into lp:unity-lens-files

Proposed by Michal Hruby
Status: Merged
Approved by: Neil J. Patel
Approved revision: 220
Merged at revision: 219
Proposed branch: lp:~mhr3/unity-lens-files/fix-955229
Merge into: lp:unity-lens-files
Diff against target: 211 lines (+160/-1)
4 files modified
src/Makefile.am (+1/-0)
src/blacklist-tracker.vala (+129/-0)
src/locate.vala (+16/-0)
tests/manual/locate.txt (+14/-1)
To merge this branch: bzr merge lp:~mhr3/unity-lens-files/fix-955229
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Siegfried Gevatter (community) Approve
Review via email: mp+97603@code.launchpad.net

Commit message

Monitor Zeitgeist's blacklist to make sure locate search respects privacy settings.

Description of the change

Watch Zeitgeist blacklists to make sure the non-zeitgeist searches respect privacy settings

To post a comment you must log in.
lp:~mhr3/unity-lens-files/fix-955229 updated
220. By Michal Hruby

Add manual test

Revision history for this message
Siegfried Gevatter (rainct) wrote :

There might be races with get_blacklisted_uris() being called before blacklist_proxy gets initialized, but like you said on IRC it's unlikely and the result will be an empty set being returned so I guess it's safe enough to ignore...

Some other comments for the sake of completeness:

 * You're assuming that if there's a URI it will be in the first subject template. This is true for Activity Log Manager, but generally it could be in any position (although indeed there should be only one them; two URIs in the same event template don't make sense).

 * You're ignoring single files being blacklisted. Is this because ALM only supports folders?

 * And, obviously, blacklists consist of much more than URIs, but yeah, probably not much point in hiding downloads by mimetype.

review: Approve
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2012-03-12 23:23:48 +0000
3+++ src/Makefile.am 2012-03-15 11:52:20 +0000
4@@ -36,6 +36,7 @@
5 $(NULL)
6
7 unity_files_daemon_VALASOURCES = \
8+ blacklist-tracker.vala \
9 config.vala \
10 daemon.vala \
11 folder.vala \
12
13=== added file 'src/blacklist-tracker.vala'
14--- src/blacklist-tracker.vala 1970-01-01 00:00:00 +0000
15+++ src/blacklist-tracker.vala 2012-03-15 11:52:20 +0000
16@@ -0,0 +1,129 @@
17+/*
18+ * Copyright (C) 2012 Canonical Ltd
19+ *
20+ * This program is free software: you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License version 3 as
22+ * published by the Free Software Foundation.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ * Authored by Michal Hruby <michal.hruby@canonical.com>
33+ *
34+ */
35+using Zeitgeist;
36+using Config;
37+using Gee;
38+
39+namespace Unity.FilesLens
40+{
41+ /* Libzeitgeist currently doesn't expose any blacklist API, so we need to
42+ * use direct dbus calls */
43+ [DBus (name = "org.gnome.zeitgeist.Blacklist")]
44+ public interface Blacklist : Object
45+ {
46+ [DBus (signature = "a{s(asaasay)}")]
47+ public abstract async Variant get_templates () throws Error;
48+ public signal void template_added (string template_id,
49+ [DBus (signature = "(asassay)")] Variant template);
50+ public signal void template_removed (string template_id,
51+ [DBus (signature = "(asassay)")] Variant template);
52+ }
53+
54+ public class BlacklistTracker : Object
55+ {
56+ private HashTable<string, Event> event_templates;
57+ private Blacklist blacklist_proxy;
58+
59+ private Set<string> blacklisted_uris;
60+ private bool cached_uris_dirty;
61+
62+ construct
63+ {
64+ event_templates = new HashTable<string, Event> (str_hash, str_equal);
65+ blacklisted_uris = new HashSet<string> ();
66+
67+ Bus.get_proxy<Blacklist> (BusType.SESSION, "org.gnome.zeitgeist.Engine",
68+ "/org/gnome/zeitgeist/blacklist", 0, null, (src, res) =>
69+ {
70+ try
71+ {
72+ blacklist_proxy = (src as DBusConnection).get_proxy<Blacklist>.end (res);
73+ fetch_blacklists ();
74+ }
75+ catch (GLib.Error err)
76+ {
77+ warning ("%s", err.message);
78+ }
79+ });
80+ }
81+
82+ private async void fetch_blacklists ()
83+ {
84+ blacklist_proxy.template_added.connect (this.template_added);
85+ blacklist_proxy.template_removed.connect (this.template_removed);
86+ Variant all_templates = yield blacklist_proxy.get_templates ();
87+
88+ VariantIter iter = new VariantIter (all_templates);
89+ string template_id;
90+ Variant event_variant;
91+ while (iter.next ("{s@(asaasay)}", out template_id, out event_variant))
92+ {
93+ Event e = new Event.from_variant (event_variant);
94+ event_templates[template_id] = e;
95+ }
96+ cached_uris_dirty = true;
97+ }
98+
99+ private void template_added (string id, Variant template)
100+ {
101+ Event e = new Event.from_variant (template);
102+ event_templates[id] = e;
103+ cached_uris_dirty = true;
104+ }
105+
106+ private void template_removed (string id, Variant template)
107+ {
108+ event_templates.remove (id);
109+ cached_uris_dirty = true;
110+ }
111+
112+ private void update_uris ()
113+ {
114+ var iter = HashTableIter<string, Event> (event_templates);
115+ unowned Event e;
116+ while (iter.next (null, out e))
117+ {
118+ if (e.num_subjects () > 0)
119+ {
120+ unowned Subject s = e.get_subject (0);
121+ unowned string uri = s.get_uri ();
122+ if (uri == null || uri == "") continue;
123+
124+ if (uri.has_suffix ("*"))
125+ {
126+ blacklisted_uris.add (uri.substring (0, uri.length - 1));
127+ }
128+ }
129+ }
130+ }
131+
132+ public unowned Set<string> get_blacklisted_uris ()
133+ {
134+ if (cached_uris_dirty)
135+ {
136+ blacklisted_uris.clear ();
137+ update_uris ();
138+ cached_uris_dirty = false;
139+ }
140+ return blacklisted_uris;
141+ }
142+ }
143+
144+} /* namespace */
145+
146
147=== modified file 'src/locate.vala'
148--- src/locate.vala 2012-03-02 16:04:21 +0000
149+++ src/locate.vala 2012-03-15 11:52:20 +0000
150@@ -36,9 +36,12 @@
151 FILE_ATTRIBUTE_ACCESS_CAN_WRITE + "," +
152 FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE;
153
154+ private BlacklistTracker blacklist_tracker;
155+
156 public async GLib.SList<FileInfo> locate (string input_query,
157 Cancellable cancellable) throws Error
158 {
159+ if (blacklist_tracker == null) blacklist_tracker = new BlacklistTracker ();
160 var result = new GLib.SList<FileInfo> ();
161 var query = Regex.escape_string (input_query.strip ());
162
163@@ -65,6 +68,19 @@
164 if ("/." in line) continue; // we don't want no hidden files
165
166 var file = File.new_for_path (line);
167+ var uri = file.get_uri ();
168+
169+ bool skip = false;
170+ foreach (var blacklisted_uri in blacklist_tracker.get_blacklisted_uris ())
171+ {
172+ if (uri.has_prefix (blacklisted_uri))
173+ {
174+ skip = true;
175+ break;
176+ }
177+ }
178+ if (skip) continue;
179+
180 var fi = yield file.query_info_async (ATTRIBS, 0, Priority.DEFAULT_IDLE,
181 cancellable);
182 if (fi.get_is_hidden () || fi.get_is_backup () ||
183
184=== modified file 'tests/manual/locate.txt'
185--- tests/manual/locate.txt 2012-03-08 16:26:02 +0000
186+++ tests/manual/locate.txt 2012-03-15 11:52:20 +0000
187@@ -1,6 +1,9 @@
188 Locate scope
189 ============
190-Tests that the locate scope works.
191+Tests that the built-in locate scope works.
192+
193+Search
194+------
195
196 #. Create a file named "report.txt" in your home directory (`touch report.txt`).
197 #. Run updatedb (`sudo updatedb`).
198@@ -9,3 +12,13 @@
199 Outcome
200 The "report.txt" should show up as a result in the Recent category of files lens.
201
202+Privacy
203+-------
204+
205+#. Open the "Privacy" application and add your home directory to the list of folders that shouldn't be monitored.
206+#. Create a file named "report.txt" in your home directory (`touch report.txt`).
207+#. Run updatedb (`sudo updatedb`).
208+#. Search for this file with files lens.
209+
210+Outcome
211+ The "report.txt" should NOT show up as a result in any of the categories of files lens.

Subscribers

People subscribed via source and target branches