Version 0 of file and directory change notifications

Updated 2003-08-20 14:54:32

File and directory change notifications/events are useful for (G)UIs showing a list of files, for mirroring direcory(trees) and some other things I can't think of right now. I asked if anyone knew of an extension for win32 that uses the directory notification API of windows. The quick consensus on the chat was that there wasn't one.

It'd also be nice to have this functionality for a lot of platforms. Pat Thoyts quickly found FindFirstChangeNotification and friends on MSDN and created a working extension.

-- 20Aug03 PS


Generic Solution Not a complete solution, but on the systems where [file mtime] returns the last update of a directory/file a reasonably efficient solution is just glob all files in a directory tree and storing their mtime. If you are only interested in create/rename/delete events (like most UIs are) you only need to call file mtime $dir to see if a file has been created/renamed/deleted since you last checked. Doing this every two seconds gives good interactive response in most cases (for UIs)

 #[ps] will paste some code here soon

Platform specific Which platforms can do this? It would be nice to create a (core?) extension to do this.

  • Windows 95: Unknown
  • Windows NT: Unknown, but NTFS can do file mtime $dir
  • Windows 98: Unknown
  • Windows ME: Unknown
  • Windows 2000, XP: Yes, FindFirstChangeNotification() and NTFS can do file mtime $dir
  • Linux <2.2: Unknown, but ext2 can do file mtime $dir
  • Linux 2.2+: Yes, see linux/Documentation/dnotify.txt using fcntl(fd, F_NOTIFY,DN_MODIFY|DN_CREATE|DN_MULTISHOT);
  • FreeBSD: Yes, kqueue: http://people.freebsd.org/~jlemon/papers/kqueue.pdf
  • (Other)BSD: Same as FreeBSD?
  • Classic Mac: Unknown
  • MacOSX: Is (free?)BSD. yes?
  • Solaris: stevel thought so.
  • HP-UX: unknown
  • irix: unknown
  • dec: unknown
  • others: ???