Merge lp:~jeremy-munsch/synapse-project/fix-locate-plugin into lp:synapse-project

Proposed by Jeremy Munsch
Status: Needs review
Proposed branch: lp:~jeremy-munsch/synapse-project/fix-locate-plugin
Merge into: lp:synapse-project
Diff against target: 65 lines (+10/-5)
2 files modified
src/core/utils.vala (+3/-2)
src/plugins/locate-plugin.vala (+7/-3)
To merge this branch: bzr merge lp:~jeremy-munsch/synapse-project/fix-locate-plugin
Reviewer Review Type Date Requested Status
Rico Tzschichholz Pending
Review via email: mp+278971@code.launchpad.net

Description of the change

This fix issue of folders not showing up using the locate plugin.

To post a comment you must log in.
633. By Jeremy Munsch

locate-plugin:

    - fix an issue where locate command is getting hidden files and folders potentially hidding wanted files due to countless results
    - add more relevancy for query matchinf files and folders

utils: fix FileInfo not getting "mime type" for inode/folder correctly.

Revision history for this message
Jeremy Munsch (jeremy-munsch) wrote :

This makes directory plugin obsolete. As I think it should be since folders are actually like any files. Handling them differently makes things too much complicated.

Unmerged revisions

633. By Jeremy Munsch

locate-plugin:

    - fix an issue where locate command is getting hidden files and folders potentially hidding wanted files due to countless results
    - add more relevancy for query matchinf files and folders

utils: fix FileInfo not getting "mime type" for inode/folder correctly.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/utils.vala'
2--- src/core/utils.vala 2015-11-19 09:11:34 +0000
3+++ src/core/utils.vala 2015-11-30 14:20:38 +0000
4@@ -491,7 +491,8 @@
5 {
6 var fi = yield f.query_info_async (interesting_attributes,
7 0, 0, null);
8- if (fi.get_file_type () == FileType.REGULAR &&
9+ if ((fi.get_file_type () == FileType.REGULAR ||
10+ fi.get_file_type () == FileType.DIRECTORY) &&
11 !fi.get_is_hidden () &&
12 !fi.get_is_backup ())
13 {
14@@ -524,7 +525,7 @@
15 {
16 file_type = QueryFlags.IMAGES;
17 }
18- else if (ContentType.is_a (mime_type, "text/*"))
19+ else if (ContentType.is_a (mime_type, "text/*") || ContentType.is_a (mime_type, "inode/directory"))
20 {
21 file_type = QueryFlags.DOCUMENTS;
22 }
23
24=== modified file 'src/plugins/locate-plugin.vala'
25--- src/plugins/locate-plugin.vala 2014-07-10 09:54:28 +0000
26+++ src/plugins/locate-plugin.vala 2015-11-30 14:20:38 +0000
27@@ -111,8 +111,7 @@
28 q.max_results = 256;
29 string regex = Regex.escape_string (q.query_string);
30 // FIXME: split pattern into words and search using --regexp?
31- string[] argv = {"locate", "-i", "-l", "%u".printf (q.max_results),
32- "*%s*".printf (regex.replace (" ", "*"))};
33+ string[] argv = {"locate", "-i", "*%s*".printf (regex.replace (" ", "*"))};
34
35 Gee.Set<string> uris = new Gee.HashSet<string> ();
36
37@@ -131,6 +130,8 @@
38 string? line = null;
39
40 Regex filter_re = new Regex ("/\\."); // hidden file/directory
41+
42+ int i = 0;
43 do
44 {
45 line = yield locate_output.read_line_async (Priority.DEFAULT_IDLE, q.cancellable);
46@@ -139,8 +140,9 @@
47 if (filter_re.match (line)) continue;
48 var file = File.new_for_path (line);
49 uris.add (file.get_uri ());
50+ i++;
51 }
52- } while (line != null);
53+ } while (line != null && i <= q.max_results);
54 }
55 catch (Error err)
56 {
57@@ -159,6 +161,8 @@
58 {
59 int relevancy = MatchScore.INCREMENT_SMALL; // FIXME: relevancy
60 if (fi.uri.has_prefix ("file:///home/")) relevancy += MatchScore.INCREMENT_MINOR;
61+ if (-1 != fi.uri.down ().slice (fi.uri.last_index_of_char ('/'), fi.uri.length).index_of (q.query_string_folded))
62+ relevancy += MatchScore.INCREMENT_MINOR;
63 result.add (fi.match_obj, relevancy);
64 }
65 q.check_cancellable ();