예제 #1
0
        private void OnInotifyEvent(Inotify.Watch watch,
                                    string path,
                                    string subitem,
                                    string srcpath,
                                    Inotify.EventType type)
        {
            if (subitem == "")
            {
                return;
            }

            string full_path = Path.Combine(path, subitem);

            if ((type & Inotify.EventType.Create) != 0 && (type & Inotify.EventType.IsDirectory) != 0)
            {
                Watch(full_path);
                return;
            }

            if ((type & Inotify.EventType.Delete) != 0 && (type & Inotify.EventType.IsDirectory) != 0)
            {
                watch.Unsubscribe();
                return;
            }

            if ((type & Inotify.EventType.MovedTo) != 0)
            {
                if (subitem == "summary")
                {
                    // IMAP summary
                    if (SummaryAddedEvent != null && File.Exists(full_path))
                    {
                        Logger.Log.Info("Reindexing updated IMAP summary: {0}", full_path);
                        SummaryAddedEvent(new FileInfo(full_path), true);
                    }
                }
                else if (Path.GetExtension(full_path) == ".ev-summary")
                {
                    // mbox summary
                    string mbox_file = Path.ChangeExtension(full_path, null);
                    if (MboxAddedEvent != null && File.Exists(mbox_file))
                    {
                        Logger.Log.Info("Reindexing updated mbox: {0}", mbox_file);
                        MboxAddedEvent(new FileInfo(mbox_file), true);
                    }
                }
            }
        }
예제 #2
0
        private void OnInotify(Inotify.Watch watch,
                               string path,
                               string subitem,
                               string srcpath,
                               Inotify.EventType type)
        {
            if (subitem == null)
            {
                return;
            }

            // Unsubscribe to directories that have been removed
            if ((type & Inotify.EventType.Delete) != 0 && (type & Inotify.EventType.IsDirectory) != 0)
            {
                watch.Unsubscribe();
            }

            lock (queue.SyncRoot) {
                bool found = false;
                for (int i = 0; i < queue.Count; i++)
                {
                    Event ev = (Event)queue.Dequeue();

                    if (ev.Path == path && ev.Subitem == subitem && ev.Srcpath == srcpath)
                    {
                        found   = true;
                        ev.Type = (ev.Type | type);
                        queue.Enqueue(ev);
                        break;
                    }

                    queue.Enqueue(ev);
                }

                if (!found)
                {
                    queue.Enqueue(new Event(watch, path, subitem, srcpath,
                                            type, -1, Thunderbird.GetFileSize(Path.Combine(path, subitem))));
                }
            }
        }
        private void OnInotifyEvent(
            Inotify.Watch watch,
            string path,
            string subitem,
            string srcpath,
            Inotify.EventType type)
        {
            // Stop watching if we were deleted
            if ((type & Inotify.EventType.DeleteSelf) != 0)
            {
                watch.Unsubscribe();
                return;
            }

            // We want a directory
            if ((type & Inotify.EventType.IsDirectory) == 0)
            {
                return;
            }

            // We are only watching one directory, so we only have to check for ToIndex
            // as subitem
            if (subitem != "ToIndex")
            {
                return;
            }

            // We only have to watch for creation of the ToIndex directory here, so that
            // the indexing process can be started. The Indexer will automatically clean
            // up if the ToIndex diretory is deleted (we still display a status message
            // here though)
            if ((type & Inotify.EventType.Create) != 0)
            {
                ExceptionHandlingThread.Start(new ThreadStart(StartWorker));
            }
            else if ((type & Inotify.EventType.Delete) != 0)
            {
                Logger.Log.Debug("Stopping the Thunderbird indexing process; ToIndex disappeared");
            }
        }
예제 #4
0
        /**
         * inotify callback
         */
        private void OnInotifyEvent(Inotify.Watch watch,
                                    string path,
                                    string subitem,
                                    string srcpath,
                                    Inotify.EventType type)
        {
            if (subitem == "")
            {
                return;
            }
            string fullPath = Path.Combine(path, subitem);

            // we need to watch for all kinds of events - this is tricky

            // Case: new file is created
            // - if it is one of the folder_directories, index it
            // - if is in one of the mail_directories, index it if it is an mbox file
            if ((type & Inotify.EventType.Create) != 0 && (type & Inotify.EventType.IsDirectory) == 0)
            {
                if (IsMailDir(path))
                {
                    Indexable indexable = MaildirMessageToIndexable(fullPath, false);
                    AddIndexableTask(indexable, fullPath);
                }
                else
                {
                    // add mbox file to mbox_files
                    string mbox = GetMboxFile(path, subitem);
                    if (mbox != null)
                    {
                        mbox_files.Add(mbox);
                        IndexMbox(mbox, true);
                    }
                }
                return;
            }

            // Case: file is deleted
            // - if it is a mail file, we might like it to be deleted
            if ((type & Inotify.EventType.MovedFrom) != 0 ||
                ((type & Inotify.EventType.Delete) != 0 &&
                 (type & Inotify.EventType.IsDirectory) == 0))
            {
                if (IsMailDir(path))
                {
                    RemoveMail(fullPath);
                }
                else if (mbox_files.Contains(fullPath))
                {
                    RemoveMbox(fullPath);
                    mbox_files.Remove(fullPath);
                }
                return;
            }

            // Case: file is moved
            // - files are moved from tmp/new to cur
            // - need to delete from the source
            if ((type & Inotify.EventType.MovedTo) != 0 && (type & Inotify.EventType.IsDirectory) == 0)
            {
                if (IsMailDir(path))
                {
                    Indexable indexable = MaildirMessageToIndexable(fullPath, false);
                    AddIndexableTask(indexable, fullPath);
                }
                if (IsMailDir(srcpath))
                {
                    RemoveMail(srcpath);
                }
                if (mbox_files.Contains(fullPath))
                {
                    // check if this because of compaction, in which case need to delete previous mbox
                    if (srcpath != null && srcpath.EndsWith("." + subitem + ".compacted"))
                    {
                        RemoveMbox(fullPath);
                    }
                    // FIXME need to ensure IndexMbox is scheduled *after* RemoveMbox finishes
                    // RemoveMbox creates a job with immediate priority while
                    // IndexMbox creates a job with the default priority of a generator
                    // Is there a better way to ensure the order ?
                    IndexMbox(fullPath, true);
                }
                return;
            }

            // Case: file is modified i.e. there was no create event but closewrite event
            // - possibly some mbox was changed
            // FIXME kmail doesnt physically delete the deleted mails from mbox files unless compacted
            // - which means one has to read the .index files to find deleted messages...
            // - need to find the format of the .index/.index.ids etc files and parse them
            if ((type & Inotify.EventType.Modify) != 0 && (type & Inotify.EventType.IsDirectory) == 0)
            {
                if (mbox_files.Contains(fullPath))
                {
                    IndexMbox(fullPath, false);
                }
                return;
            }

            // Case: a directory is created:
            // well watch it anyway but also make sure its a maildir directory
            // if it a maildir directory, then add it to maildir_dirs
            if ((type & Inotify.EventType.Create) != 0 && (type & Inotify.EventType.IsDirectory) != 0)
            {
                if (!IgnoreFolder(fullPath))
                {
                    Watch(fullPath);
                    UpdateDirectories(fullPath);
                }
                return;
            }

            // Case: if a directory is deleted:
            // remove watch
            if ((type & Inotify.EventType.Delete) != 0 && (type & Inotify.EventType.IsDirectory) != 0)
            {
                watch.Unsubscribe();
                mail_directories.Remove(fullPath);
                folder_directories.Remove(fullPath);
                return;
            }

            // Case: directory is moved
            // FIXME: implement renaming of mail folders
        }