Merge lp://qastaging/~jejones/do-plugins/opensearch-fix into lp://qastaging/do-plugins

Proposed by Jason Jones
Status: Merged
Merged at revision: not available
Proposed branch: lp://qastaging/~jejones/do-plugins/opensearch-fix
Merge into: lp://qastaging/do-plugins
Diff against target: 101 lines (+43/-8)
2 files modified
OpenSearch/src/CachingOpenSearchItemSource.cs (+25/-8)
OpenSearch/src/FirefoxOpenSearchDirectoryProvider.cs (+18/-0)
To merge this branch: bzr merge lp://qastaging/~jejones/do-plugins/opensearch-fix
Reviewer Review Type Date Requested Status
Alex Launi (community) Approve
Review via email: mp+17978@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Jason Jones (jejones) wrote :

Branch updates my OpenSearch plugin to index the firefox-addons folder when looking for OpenSearch plugins.

Revision history for this message
Alex Launi (alexlauni) wrote :

Looks good! Thanks a lot

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'OpenSearch/src/CachingOpenSearchItemSource.cs'
2--- OpenSearch/src/CachingOpenSearchItemSource.cs 2009-06-22 04:05:16 +0000
3+++ OpenSearch/src/CachingOpenSearchItemSource.cs 2010-01-24 19:49:10 +0000
4@@ -20,6 +20,7 @@
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8+using System.Linq;
9 using System.Text.RegularExpressions;
10
11 using Mono.Addins;
12@@ -51,7 +52,7 @@
13
14 public static void UpdateItems ()
15 {
16- foreach (string filePath in GetUnprocessedOpenSearchFiles ()) {
17+ foreach (string filePath in GetUnprocessedOpenSearchFiles (firefox_provider.OpenSearchPluginDirectories)) {
18 try {
19 OpenSearchItem item = OpenSearchParser.Create (filePath);
20 if (item != null) {
21@@ -66,22 +67,38 @@
22 }
23 }
24
25- private static IEnumerable<string> GetUnprocessedOpenSearchFiles ()
26+ private static IEnumerable<string> GetUnprocessedOpenSearchFiles (IEnumerable<string> directoriesToProcess)
27 {
28- foreach (string path in firefox_provider.OpenSearchPluginDirectories) {
29+ List<string> unprocessedFiles = new List<string> ();
30+
31+ foreach (string path in directoriesToProcess) {
32+
33 if(!Directory.Exists (path))
34 continue;
35-
36- string [] filePaths = Directory.GetFiles (path);
37+
38+ IEnumerable<string> filePaths = Directory.GetFiles (path).Concat (Directory.GetDirectories (path));
39+
40 foreach (string filePath in filePaths) {
41+ // It's a trap! The firefox-addons/searchplugins folder stashes some of its plugins in folders
42+ // so we need to recurse...but it also has a symlink called common which links to it's containing
43+ // folder, which means if we blindly recurse, we'll keep following it. So let's just skip it.
44+ if((File.GetAttributes(filePath) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) {
45+ Log<CachingOpenSearchItemSource>.Debug ("Skipping symlink: {0}", filePath);
46+ continue;
47+ }
48+ if (Directory.Exists(filePath)) {
49+ Log<CachingOpenSearchItemSource>.Debug ("Recursing into: {0}",filePath);
50+ unprocessedFiles.AddRange (GetUnprocessedOpenSearchFiles (new[]{filePath}));
51+ }
52 if (cached_items.ContainsKey (filePath))
53 continue;
54 if (!Regex.IsMatch (filePath, valid_file_pattern))
55- continue;
56- yield return filePath;
57+ continue;
58+
59+ unprocessedFiles.Add (filePath);
60 }
61 }
62+ return unprocessedFiles;
63 }
64-
65 }
66 }
67
68=== modified file 'OpenSearch/src/FirefoxOpenSearchDirectoryProvider.cs'
69--- OpenSearch/src/FirefoxOpenSearchDirectoryProvider.cs 2009-01-17 01:19:26 +0000
70+++ OpenSearch/src/FirefoxOpenSearchDirectoryProvider.cs 2010-01-24 19:49:10 +0000
71@@ -57,6 +57,12 @@
72 Log<FirefoxOpenSearchDirectoryProvider>.Debug ("Library plugin search path: {0}", firefoxLibPath);
73 openSearchPluginDirectories.Add (firefoxLibPath);
74 }
75+
76+ string firefoxAddonsPath = GetAddonsSearchPluginsPath ();
77+ if (firefoxAddonsPath != null) {
78+ Log<FirefoxOpenSearchDirectoryProvider>.Debug ("Addons plugin search path: {0}", firefoxAddonsPath);
79+ openSearchPluginDirectories.Add (firefoxAddonsPath);
80+ }
81 }
82
83 /// <value>
84@@ -155,5 +161,17 @@
85
86 return null;
87 }
88+
89+ /// <summary>
90+ /// Retrieves the firefox-addons search plugin directory, which
91+ /// is where the default OpenSearch plugins are installed.
92+ /// </summary>
93+ /// <returns>
94+ /// The full path to the firefox-addons searchplugins directory.
95+ /// </returns>
96+ private string GetAddonsSearchPluginsPath ()
97+ {
98+ return "/usr/lib/firefox-addons/searchplugins";
99+ }
100 }
101 }

Subscribers

People subscribed via source and target branches