Пример #1
0
            public void Unsubscribe()
            {
                if (!this.is_subscribed)
                {
                    return;
                }

                Inotify.Unsubscribe(watchinfo, this);
                this.is_subscribed = false;
            }
Пример #2
0
        /////////////////////////////////////////////////////////////////////////////////

#if INOTIFY_TEST
        private static void Main(string [] args)
        {
            Queue to_watch  = new Queue();
            bool  recursive = false;

            foreach (string arg in args)
            {
                if (arg == "-r" || arg == "--recursive")
                {
                    recursive = true;
                }
                else
                {
                    // Our hashes work without a trailing path delimiter
                    string path = arg.TrimEnd('/');
                    to_watch.Enqueue(path);
                }
            }

            while (to_watch.Count > 0)
            {
                string path = (string)to_watch.Dequeue();

                Console.WriteLine("Watching {0}", path);
                Inotify.Subscribe(path, null, Inotify.EventType.All);

                if (recursive)
                {
                    foreach (string subdir in DirectoryWalker.GetDirectories(path))
                    {
                        to_watch.Enqueue(subdir);
                    }
                }
            }

            Inotify.Start();
            Inotify.Verbose = true;

            while (Inotify.Enabled && Inotify.WatchCount > 0)
            {
                Thread.Sleep(1000);
            }

            if (Inotify.WatchCount == 0)
            {
                Console.WriteLine("Nothing being watched.");
            }

            // Kill the event-reading thread so that we exit
            Inotify.Stop();
        }
Пример #3
0
        private static void OnInotifyEvent(Inotify.Watch watch, string path, string subitem, string srcpath, Inotify.EventType type)
        {
            if (subitem == "" || watching_for_updates == false)
                return;

            Reload ();
        }
Пример #4
0
		private void OnInotifyEvent (Inotify.Watch     watch,
					     string            path,
					     string            subitem,
					     string            srcpath,
					     Inotify.EventType type)
		{
			bool is_directory;
			is_directory = (type & Inotify.EventType.IsDirectory) != 0;

			queryable.ReportEventInDirectory (path);

			// The case of matched move events
			if ((type & Inotify.EventType.MovedTo) != 0 && srcpath != null) {
				queryable.HandleMoveEvent (Path.GetDirectoryName (srcpath),
							   Path.GetFileName (srcpath),
							   path, subitem, is_directory);
				return;
			}

			// Then this must be an unmatched moveto
			// An unmatched MovedTo is like a create
			if ((type & Inotify.EventType.MovedTo) != 0) { 

				// Synthesize the appropriate Create event.  Note that we could check for the
				// IsDirectory event here, but this also shrinks the race window.
				if (is_directory)
					type |= Inotify.EventType.Create;
				else
					type |= Inotify.EventType.CloseWrite;
				Logger.Log.Debug ("Synthesizing event on unpaired MoveTo", type);
			}

			// An unmatched MovedFrom is like a delete
			if ((type & Inotify.EventType.MovedFrom) != 0) {
				type |= Inotify.EventType.Delete;
				Logger.Log.Debug ("Synthesizing event on unpaired MoveFrom", type);
			}

			if ((type & Inotify.EventType.Delete) != 0) {
				queryable.HandleRemoveEvent (path, subitem, is_directory);
				return;
			}

			if ((type & Inotify.EventType.Create) != 0) {
				if (is_directory)
					queryable.HandleAddEvent (path, subitem, is_directory);
				return;
			}

			if ((type & Inotify.EventType.CloseWrite) != 0) {
				queryable.HandleAddEvent (path, subitem, is_directory);
				return;
			}

			if ((type & Inotify.EventType.Attrib) != 0) {
				queryable.HandleAttribEvent (path, subitem, is_directory);
				return;
			}

			if ((type & Inotify.EventType.QueueOverflow) != 0) {
				Logger.Log.Warn ("Inotify queue overflowed: file system is in an unknown state");
				queryable.HandleOverflowEvent ();
				return;
			}
		}
Пример #5
0
		private void OnInotifyEvent (Inotify.Watch watch,
					     string path,
					     string subitem,
					     string srcpath,
					     Inotify.EventType type)
		{
			if (subitem == "")
				return;
			
			if (subitem[0] == '.') {
				string data_file = Path.Combine (path, subitem.Substring (1));

				lock (pending_files) {
					if (File.Exists (data_file) && ! pending_files.Contains (data_file)) {
						pending_files.Add (data_file);
						IndexFile (new FileInfo (data_file));
					}
				}
			} else {
				string meta_file = Path.Combine (path, "." + subitem);
				string data_file = Path.Combine (path, subitem);

				lock (pending_files) {
					if (File.Exists (meta_file) && ! pending_files.Contains (data_file)) {
						pending_files.Add (data_file);
						IndexFile (new FileInfo (data_file));
					}
				}
			}
		}