Author: gonzalo
Date: 2006-09-05 11:38:06 -0400 (Tue, 05 Sep 2006)
New Revision: 64950

Modified:
   trunk/mcs/class/System/System.IO/ChangeLog
   trunk/mcs/class/System/System.IO/FileSystemWatcher.cs
   trunk/mcs/class/System/System.IO/InotifyWatcher.cs
Log:
2006-09-05 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * InotifyWatcher.cs: fix file names for the rename event.
        * FileSystemWatcher.cs: ignore exceptions that happen when invoking
        event handlers.



Modified: trunk/mcs/class/System/System.IO/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.IO/ChangeLog  2006-09-05 15:23:12 UTC (rev 
64949)
+++ trunk/mcs/class/System/System.IO/ChangeLog  2006-09-05 15:38:06 UTC (rev 
64950)
@@ -1,3 +1,9 @@
+2006-09-05 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * 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 <[EMAIL PROTECTED]>
 
        * InotifyWatcher.cs: handle CloseWrite, as it might happen without other

Modified: trunk/mcs/class/System/System.IO/FileSystemWatcher.cs
===================================================================
--- trunk/mcs/class/System/System.IO/FileSystemWatcher.cs       2006-09-05 
15:23:12 UTC (rev 64949)
+++ trunk/mcs/class/System/System.IO/FileSystemWatcher.cs       2006-09-05 
15:38:06 UTC (rev 64950)
@@ -354,44 +354,60 @@
                        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 @@
                        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);

Modified: trunk/mcs/class/System/System.IO/InotifyWatcher.cs
===================================================================
--- trunk/mcs/class/System/System.IO/InotifyWatcher.cs  2006-09-05 15:23:12 UTC 
(rev 64949)
+++ trunk/mcs/class/System/System.IO/InotifyWatcher.cs  2006-09-05 15:38:06 UTC 
(rev 64950)
@@ -498,9 +498,12 @@
                                                } 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;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to