PathData Add (string path, bool postEvents, ref List<int> fds)
{
PathData pathData;
pathsDict.TryGetValue (path, out pathData);
if (pathData != null)
return pathData;
if (fdsDict.Count >= maxFds)
throw new IOException ("kqueue() FileSystemWatcher has reached the maximum nunmber of files to watch.");
var fd = open (path, O_EVTONLY, 0);
if (fd == -1) {
fsw.DispatchErrorEvents (new ErrorEventArgs (new IOException (String.Format (
"open() error while attempting to process path '{0}', error code = '{1}'", path, Marshal.GetLastWin32Error ()))));
return null;
}
try {
fds.Add (fd);
var attrs = File.GetAttributes (path);
pathData = new PathData {
Path = path,
Fd = fd,
IsDirectory = (attrs & FileAttributes.Directory) == FileAttributes.Directory
};
pathsDict.Add (path, pathData);
fdsDict.Add (fd, pathData);
if (postEvents)
PostEvent (FileAction.Added, path);
return pathData;
} catch (Exception e) {
close (fd);
fsw.DispatchErrorEvents (new ErrorEventArgs (e));
return null;
}
}