public bool IsUpToDate (string path, Filter filter) { return IsUpToDate (path, filter, DateTime.MaxValue); }
// To be used if the last_write_time to use for comparison is not the // one obtained from path public bool IsUpToDate (string path, Filter filter, DateTime last_write_time) { FileAttributes attr; attr = Read (path); // If there are no attributes set on the file, there is no // way that we can be up-to-date. // Also, if attribute has no filter information, try once // again. if (attr == null) return false; // Note that when filter is set to null, we ignore // any existing filter data. That might not be the // expected behavior... if (filter != null) { if (! attr.HasFilterInfo) return false; if (attr.FilterName != filter.Name) return false; // FIXME: Obviously we want to reindex if // attr.FilterVersion < filter.Version. // But what if the filter we would use is older // than the one that was previously used? if (attr.FilterVersion != filter.Version) return false; } if (last_write_time == DateTime.MaxValue) return (attr.LastWriteTime >= FileSystem.GetLastWriteTimeUtc (path)); else return (attr.LastWriteTime >= last_write_time); }
static public bool FilterIndexable (Indexable indexable, out Filter filter) { return FilterIndexable (indexable, null, out filter); }
/* Returns false if content can't/needn't be indexed. * If AlreadyFiltered, then we don't return a filter but return true. */ static public bool FilterIndexable (Indexable indexable, TextCache text_cache, out Filter filter) { filter = null; ICollection filters = null; if (indexable.Filtering == IndexableFiltering.AlreadyFiltered) return true; if (! ShouldWeFilterThis (indexable)) return false; string path = null; // First, figure out which filter we should use to deal with // the indexable. // If a specific mime type is specified, try to index as that type. if (indexable.MimeType != null) filters = CreateFiltersFromMimeType (indexable.MimeType); if (indexable.ContentUri.IsFile) { path = indexable.ContentUri.LocalPath; // Otherwise, set the mime type for a directory, // or sniff it from the file. if (indexable.MimeType == null) { if (Directory.Exists (path)) { indexable.MimeType = "inode/directory"; indexable.NoContent = true; } else if (File.Exists (path)) { indexable.MimeType = XdgMime.GetMimeType (path); } else { Log.Warn ("Unable to filter {0}. {1} not found.", indexable.DisplayUri, path); return false; } } // Set the timestamp to the last write time, if it isn't // set by the backend. if (! indexable.ValidTimestamp && indexable.IsNonTransient) indexable.Timestamp = FileSystem.GetLastWriteTimeUtc (path); // Check the timestamp to make sure the file hasn't // disappeared from underneath us. if (! FileSystem.ExistsByDateTime (indexable.Timestamp)) { Log.Warn ("Unable to filter {0}. {1} appears to have disappeared from underneath us", indexable.DisplayUri, path); return false; } if (filters == null || filters.Count == 0) { filters = CreateFiltersFromIndexable (indexable); } } // We don't know how to filter this, so there is nothing else to do. if (filters.Count == 0) { if (! indexable.NoContent) Logger.Log.Debug ("No filter for {0} ({1}) [{2}]", indexable.DisplayUri, path, indexable.MimeType); return false; } foreach (Filter candidate_filter in filters) { if (Debug) Logger.Log.Debug ("Testing filter: {0}", candidate_filter); // Hook up the snippet writer. if (candidate_filter.SnippetMode && text_cache != null) { if (candidate_filter.OriginalIsText && indexable.IsNonTransient) { text_cache.MarkAsSelfCached (indexable.Uri); } else if (indexable.CacheContent) { TextWriter writer = text_cache.GetWriter (indexable.Uri); candidate_filter.AttachSnippetWriter (writer); } } // Set the indexable on the filter. candidate_filter.Indexable = indexable; // Open the filter, copy the file's properties to the indexable, // and hook up the TextReaders. bool successful_open = false; TextReader text_reader; Stream binary_stream; if (path != null) successful_open = candidate_filter.Open (path); else if ((text_reader = indexable.GetTextReader ()) != null) successful_open = candidate_filter.Open (text_reader); else if ((binary_stream = indexable.GetBinaryStream ()) != null) successful_open = candidate_filter.Open (binary_stream); if (successful_open) { // Set FileType indexable.AddProperty (Property.NewKeyword ("beagrep:FileType", candidate_filter.FileType)); indexable.SetTextReader (candidate_filter.GetTextReader ()); indexable.SetHotTextReader (candidate_filter.GetHotTextReader ()); if (Debug) Logger.Log.Debug ("Successfully filtered {0} with {1}", path, candidate_filter); filter = candidate_filter; return true; } else { Log.Warn ("Error in filtering {0} with {1}, falling back", path, candidate_filter); candidate_filter.Cleanup (); } } if (Debug) Logger.Log.Debug ("None of the matching filters could process the file: {0}", path); return false; }
/////////////////////////////////////////////////////////////////////////// // Convenience functions public bool IsUpToDate (string path, Filter filter) { return FileAttributesStore.IsUpToDate (path, filter); }
public void Cleanup () { Filter.Cleanup (); Filter.CleanGeneratedIndexables (); Indexable.Cleanup (); Filter = null; Indexable = null; if (PersistentPropDocs != null) PersistentPropDocs.Clear (); }
public Hashtable PersistentPropDocs; // Contains the persistent properties for itself and children public DeferredInfo (Indexable indexable, Filter filter, Hashtable persistent_property_docs) { this.Indexable = indexable; this.Filter = filter; this.PersistentPropDocs = persistent_property_docs; }