Exemple #1
0
        public bool HasNextIndexable()
        {
            if (metadata != null)
            {
                if (metadata.MoveNext())
                {
                    return(true);
                }
                else
                {
                    metadata = null;
                    FileAttributesStore.AttachLastWriteTime((string)metafiles.Current, DateTime.UtcNow);
                }
            }

            while (metadata == null)
            {
                if (metafiles == null)
                {
                    metafiles = DirectoryWalker.GetItems(nautilus_dir, is_xml_file).GetEnumerator();
                }

                if (!metafiles.MoveNext())
                {
                    return(false);
                }

                string file = (string)metafiles.Current;

                if (FileAttributesStore.IsUpToDate(file))
                {
                    continue;
                }

                metadata = NautilusTools.GetMetadata((string)metafiles.Current).GetEnumerator();

                if (metadata.MoveNext())
                {
                    return(true);
                }
                else
                {
                    metadata = null;
                    FileAttributesStore.AttachLastWriteTime(file, DateTime.UtcNow);
                }
            }

            return(false);            // Makes the compiler happy
        }
        public OperaIndexer(OperaQueryable queryable, FileAttributesStore store, string root_dir)
        {
            this.attribute_store = store;
            this.queryable       = queryable;
            this.cache_dirs      = new ArrayList();

            // Try to find all cache dirs
            foreach (string dir in DirectoryWalker.GetDirectories(root_dir))
            {
                foreach (string file in DirectoryWalker.GetItems
                             (dir, new DirectoryWalker.FileFilter(IsCacheFile)))
                {
                    Inotify.Subscribe(dir, OnInotify, Inotify.EventType.MovedTo | Inotify.EventType.CloseWrite);
                    cache_dirs.Add(dir);
                }
            }
        }
        private void IndexDirectory(string directory)
        {
            Queue pending = new Queue();

            pending.Enqueue(directory);
            while (pending.Count > 0)
            {
                string dir = pending.Dequeue() as string;

                foreach (string subdir in DirectoryWalker.GetDirectories(dir))
                {
                    if (Shutdown.ShutdownRequested)
                    {
                        return;
                    }

                    pending.Enqueue(subdir);
                }

                if (Inotify.Enabled)
                {
                    inotify.Watch(dir,
                                  Inotify.EventType.Modify |
                                  Inotify.EventType.Create |
                                  Inotify.EventType.Delete |
                                  Inotify.EventType.MovedFrom |
                                  Inotify.EventType.MovedTo);
                }

                foreach (string file in DirectoryWalker.GetItems
                             (dir, new DirectoryWalker.FileFilter(Thunderbird.IsMorkFile)))
                {
                    if (Shutdown.ShutdownRequested)
                    {
                        return;
                    }

                    IndexFile(file);
                }
            }
        }
        private void Watch(string root)
        {
            Queue pending = new Queue();

            pending.Enqueue(root);

            while (pending.Count > 0)
            {
                string dir = (string)pending.Dequeue();

                foreach (string subdir in DirectoryWalker.GetDirectories(dir))
                {
                    if (Shutdown.ShutdownRequested)
                    {
                        return;
                    }

                    if (Inotify.Enabled)
                    {
                        Inotify.Subscribe(subdir, OnInotifyEvent,
                                          Inotify.EventType.Create
                                          | Inotify.EventType.Delete
                                          | Inotify.EventType.MovedTo);
                    }

                    pending.Enqueue(subdir);
                }

                Stopwatch watch = new Stopwatch();
                if (Debug)
                {
                    Logger.Log.Debug("Starting watch on {0}", dir);
                }
                watch.Start();
                foreach (string path in DirectoryWalker.GetItems(dir, new DirectoryWalker.FileFilter(IsSummary)))
                {
                    if (Shutdown.ShutdownRequested)
                    {
                        return;
                    }

                    FileInfo file = new FileInfo(path);

                    if (file.Name == "summary")
                    {
                        if (SummaryAddedEvent != null && FileIsInteresting(file))
                        {
                            SummaryAddedEvent(file, false);
                        }
                    }
                    else if (file.Extension == ".ev-summary")
                    {
                        string mbox_name = Path.Combine(file.DirectoryName,
                                                        Path.GetFileNameWithoutExtension(file.Name));
                        FileInfo mbox_file = new FileInfo(mbox_name);
                        if (MboxAddedEvent != null && FileIsInteresting(mbox_file))
                        {
                            MboxAddedEvent(mbox_file, false);
                        }
                    }
                }
                watch.Stop();
                if (Debug)
                {
                    Logger.Log.Debug("Crawled {0} in {1}", dir, watch);
                }
            }
        }