52
53
public static void UpdateItems ()
54
foreach (string filePath in GetUnprocessedOpenSearchFiles ()) {
55
foreach (string filePath in GetUnprocessedOpenSearchFiles (firefox_provider.OpenSearchPluginDirectories)) {
56
57
OpenSearchItem item = OpenSearchParser.Create (filePath);
57
58
if (item != null) {
69
private static IEnumerable<string> GetUnprocessedOpenSearchFiles ()
70
private static IEnumerable<string> GetUnprocessedOpenSearchFiles (IEnumerable<string> directoriesToProcess)
71
foreach (string path in firefox_provider.OpenSearchPluginDirectories) {
72
List<string> unprocessedFiles = new List<string> ();
74
foreach (string path in directoriesToProcess) {
72
76
if(!Directory.Exists (path))
75
string [] filePaths = Directory.GetFiles (path);
79
IEnumerable<string> filePaths = Directory.GetFiles (path).Concat (Directory.GetDirectories (path));
76
81
foreach (string filePath in filePaths) {
82
// It's a trap! The firefox-addons/searchplugins folder stashes some of its plugins in folders
83
// so we need to recurse...but it also has a symlink called common which links to it's containing
84
// folder, which means if we blindly recurse, we'll keep following it. So let's just skip it.
85
if((File.GetAttributes(filePath) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) {
86
Log<CachingOpenSearchItemSource>.Debug ("Skipping symlink: {0}", filePath);
89
if (Directory.Exists(filePath)) {
90
Log<CachingOpenSearchItemSource>.Debug ("Recursing into: {0}",filePath);
91
unprocessedFiles.AddRange (GetUnprocessedOpenSearchFiles (new[]{filePath}));
77
93
if (cached_items.ContainsKey (filePath))
79
95
if (!Regex.IsMatch (filePath, valid_file_pattern))
81
yield return filePath;
98
unprocessedFiles.Add (filePath);
101
return unprocessedFiles;