2006-09-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 5 Sep 2006 15:38:06 +0000 (15:38 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Tue, 5 Sep 2006 15:38:06 +0000 (15:38 -0000)
* InotifyWatcher.cs: fix file names for the rename event.
* FileSystemWatcher.cs: ignore exceptions that happen when invoking
event handlers.

svn path=/trunk/mcs/; revision=64950

mcs/class/System/System.IO/ChangeLog
mcs/class/System/System.IO/FileSystemWatcher.cs
mcs/class/System/System.IO/InotifyWatcher.cs

index 310e7be19cc30851c79230d392443e3f8b9f02d9..745daec1cf55764d382c0054ab7b056233fd7597 100644 (file)
@@ -1,3 +1,9 @@
+2006-09-05 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * InotifyWatcher.cs: fix file names for the rename event.
+       * FileSystemWatcher.cs: ignore exceptions that happen when invoking
+       event handlers.
+
 2006-08-21 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * InotifyWatcher.cs: handle CloseWrite, as it might happen without other
index 98cd41d7bd3e56388a465c81612c449c8f6026d4..2dba82cd9e6e0de027c36f8eef029c5aeb05d39b 100644 (file)
@@ -354,44 +354,60 @@ namespace System.IO {
                        throw new NotImplementedException (); 
                }
 
-               private void RaiseEvent (Delegate ev, EventArgs arg)
+               enum EventType {
+                       FileSystemEvent,
+                       ErrorEvent,
+                       RenameEvent
+               }
+               private void RaiseEvent (Delegate ev, EventArgs arg, EventType evtype)
                {
                        if (ev == null)
                                return;
 
-                       object [] args = new object [] {this, arg};
-
                        if (synchronizingObject == null) {
-                               ev.DynamicInvoke (args);
+                               Delegate [] delegates = ev.GetInvocationList ();
+                               if (evtype == EventType.RenameEvent) {
+                                       foreach (RenamedEventHandler d in delegates){
+                                               d.BeginInvoke (this, (RenamedEventArgs) arg, null, null);
+                                       }
+                               } else if (evtype == EventType.ErrorEvent) {
+                                       foreach (ErrorEventHandler d in delegates){
+                                               d.BeginInvoke (this, (ErrorEventArgs) arg, null, null);
+                                       }
+                               } else {
+                                       foreach (FileSystemEventHandler d in delegates){
+                                               d.BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
+                                       }
+                               }
                                return;
                        }
                        
-                       synchronizingObject.BeginInvoke (ev, args);
+                       synchronizingObject.BeginInvoke (ev, new object [] {this, arg});
                }
 
                protected void OnChanged (FileSystemEventArgs e)
                {
-                       RaiseEvent (Changed, e);
+                       RaiseEvent (Changed, e, EventType.FileSystemEvent);
                }
 
                protected void OnCreated (FileSystemEventArgs e)
                {
-                       RaiseEvent (Created, e);
+                       RaiseEvent (Created, e, EventType.FileSystemEvent);
                }
 
                protected void OnDeleted (FileSystemEventArgs e)
                {
-                       RaiseEvent (Deleted, e);
+                       RaiseEvent (Deleted, e, EventType.FileSystemEvent);
                }
 
                protected void OnError (ErrorEventArgs e)
                {
-                       RaiseEvent (Error, e);
+                       RaiseEvent (Error, e, EventType.ErrorEvent);
                }
 
                protected void OnRenamed (RenamedEventArgs e)
                {
-                       RaiseEvent (Renamed, e);
+                       RaiseEvent (Renamed, e, EventType.RenameEvent);
                }
 
                public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType)
@@ -454,9 +470,7 @@ namespace System.IO {
                        case FileAction.RenamedNewName:
                                lastData.Name = filename;
                                lastData.ChangeType = WatcherChangeTypes.Renamed;
-                               if (renamed != null) {
-                                       renamed.SetName (filename);
-                               } else {
+                               if (renamed == null) {
                                        renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, path, "", filename);
                                }
                                OnRenamed (renamed);
index 06dd9575fac6e0c05c3959b30560ba37b75b06b6..a717f40922c2959fe131dd01c639baf3c0af717d 100644 (file)
@@ -498,9 +498,12 @@ namespace System.IO {
                                                } else {
                                                        nread += i;
                                                        action = FileAction.RenamedNewName;
-                                                       renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, data.Directory, evt.Name, to.Name);
-                                                       filename = to.Name;
-                                                       evt = to;
+                                                       if (evt.Name == data.Directory || fsw.Pattern.IsMatch (evt.Name)) {
+                                                               renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, data.Directory, to.Name, evt.Name);
+                                                       } else {
+                                                               renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, data.Directory, evt.Name, to.Name);
+                                                               filename = to.Name;
+                                                       }
                                                }
                                        } else if ((mask & InotifyMask.MovedTo) != 0) {
                                                action = (new_name_needed) ? FileAction.RenamedNewName : FileAction.Added;