~peter-stuifzand/do-plugins/vmware

« back to all changes in this revision

Viewing changes to OpenSearch/src/CachingOpenSearchItemSource.cs

  • Committer: Alex Launi
  • Date: 2010-01-25 02:16:56 UTC
  • mfrom: (674.2.1 do-plugins)
  • Revision ID: alex.launi@gmail.com-20100125021656-cfjiidol06778bo0
merge fix for opensearch plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
using System;
21
21
using System.Collections.Generic;
22
22
using System.IO;
 
23
using System.Linq;
23
24
using System.Text.RegularExpressions;
24
25
 
25
26
using Mono.Addins;
51
52
                
52
53
                public static void UpdateItems ()
53
54
                {
54
 
                        foreach (string filePath in GetUnprocessedOpenSearchFiles ()) {
 
55
                        foreach (string filePath in GetUnprocessedOpenSearchFiles (firefox_provider.OpenSearchPluginDirectories)) {
55
56
                                try {
56
57
                                        OpenSearchItem item = OpenSearchParser.Create (filePath);
57
58
                                        if (item != null) {
66
67
                        }
67
68
                }       
68
69
                
69
 
                private static IEnumerable<string> GetUnprocessedOpenSearchFiles ()
 
70
                private static IEnumerable<string> GetUnprocessedOpenSearchFiles (IEnumerable<string> directoriesToProcess)
70
71
                {
71
 
                        foreach (string path in firefox_provider.OpenSearchPluginDirectories) {
 
72
                        List<string> unprocessedFiles = new List<string> ();
 
73
                        
 
74
                        foreach (string path in directoriesToProcess) {
 
75
 
72
76
                                if(!Directory.Exists (path))
73
77
                                        continue;
74
 
                                
75
 
                                string [] filePaths = Directory.GetFiles (path);
 
78
 
 
79
                                IEnumerable<string> filePaths = Directory.GetFiles (path).Concat (Directory.GetDirectories (path));
 
80
 
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);
 
87
                                                continue;               
 
88
                                        }
 
89
                                        if (Directory.Exists(filePath)) {
 
90
                                                Log<CachingOpenSearchItemSource>.Debug ("Recursing into: {0}",filePath);
 
91
                                            unprocessedFiles.AddRange (GetUnprocessedOpenSearchFiles (new[]{filePath}));
 
92
                                        }
77
93
                                        if (cached_items.ContainsKey (filePath))
78
94
                                                continue;
79
95
                                        if (!Regex.IsMatch (filePath, valid_file_pattern))
80
 
                                                continue;                       
81
 
                                        yield return filePath;
 
96
                                                continue;               
 
97
                                        
 
98
                                        unprocessedFiles.Add (filePath);
82
99
                                }
83
100
                        }
 
101
                        return unprocessedFiles;
84
102
                }
85
 
 
86
103
        }
87
104
}