override protected Uri PostAddHook (Indexable indexable, IndexerAddedReceipt receipt) { // Retrieve our cached info about the file. CachedFileInfo info; info = file_info_cache [indexable.Uri] as CachedFileInfo; if (info == null) return indexable.Uri; file_info_cache.Remove (info.Uri); // Yeah, this is ghetto. If it's a file that's shared across multiple // indexables, only tag it with when the last indexable has been indexed. if (info.Shared && DecrementReferenceCount (info.Path)) return indexable.Uri; // Since we know that the file has been successfully // indexed, update the file attributes accordingly. // Don't set filter information on a file if multiple // indexables has been created from it. FileAttributes attr; attr = FileAttributesStore.ReadOrCreate (info.Path); attr.LastWriteTime = info.Mtime; // Don't set filter information on a file if multiple indexables has been // created from it. if (! info.Shared) { attr.FilterName = receipt.FilterName; attr.FilterVersion = receipt.FilterVersion; } if (! FileAttributesStore.Write (attr)) Logger.Log.Warn ("Couldn't write attributes for {0}", info.Path); return indexable.Uri; }
// This is mostly a copy of LuceneQueryable.Flush + FSQ.PostAddHooks/PostRemoveHook static bool FlushIndexer(IIndexer indexer) { IndexerRequest flushed_request; if (pending_request.IsEmpty) { return(false); } flushed_request = pending_request; pending_request = new IndexerRequest(); IndexerReceipt [] receipts; receipts = indexer.Flush(flushed_request); // Flush will return null if it encounters a shutdown during flushing if (receipts == null) { return(false); } fa_store.BeginTransaction(); bool indexer_indexable_receipt = false; foreach (IndexerReceipt raw_r in receipts) { if (raw_r is IndexerAddedReceipt) { // Update the file attributes IndexerAddedReceipt r = (IndexerAddedReceipt)raw_r; Indexable indexable = flushed_request.RetrieveRequestIndexable(r); if (indexable == null) { Logger.Log.Debug("Should not happen! Previously requested indexable with id #{0} has eloped!", r.Id); continue; } // We don't need to write out any file attributes for // children. if (indexable.ParentUri != null) { continue; } string path = indexable.Uri.LocalPath; FileAttributes attr; attr = fa_store.ReadOrCreate(path); attr.LastWriteTime = indexable.Timestamp; attr.FilterName = r.FilterName; attr.FilterVersion = r.FilterVersion; fa_store.Write(attr); } else if (raw_r is IndexerRemovedReceipt) { // Update the file attributes IndexerRemovedReceipt r = (IndexerRemovedReceipt)raw_r; Indexable indexable = flushed_request.RetrieveRequestIndexable(r); if (indexable == null) // Should never happen { Log.Warn("Unable to match indexable-remove #{0} to any request!", r.Id); continue; } string path = indexable.Uri.LocalPath; Logger.Log.Debug("Removing: '{0}'", path); fa_store.Drop(path); } else if (raw_r is IndexerIndexablesReceipt) { indexer_indexable_receipt = true; } } pending_request.DeferredIndexables = flushed_request.DeferredIndexables; // Reschedule if some indexable generated more indexables if (indexer_indexable_receipt) { pending_request.ContinueIndexing = true; return(true); } fa_store.CommitTransaction(); return(false); }