Version 20 of directory notification package in Tcl

Updated 2002-10-08 12:29:30

I (Colin McCormack) have written a quick package to take advantage of the Linux directory modification facility.

What this means is that you can open a directory, register your interest, and have an asynchronous script invoked when a file is added to, modified in, deleted from that directory.

I have it in mind to use this under tclhttpd.

You can get the package here: http://sourceforge.net/projects/libtclpq/

Documentation available here: http://sourceforge.net/docman/display_doc.php?docid=11924&group_id=18733

Written with CriTcl.


AK - Now this is a useful thing. Note that the documentation about directory notification [L1 ] mentions that this can trigger when files in a directory change. In other words, this can be used to write a more efficient tail. (you could also use it in conjunction with VFS to lazily mirror real directories)

Also note that this is restricted to Linux kernel 2.4 and higher.

Regarding the described interface of dnotify I have one nit: That the caller is burdened with the task to extract the fd to watch out of a channel handle. A better interface (IMHO) would be to accept channel handles and have the C code determine the file handle (There are functions in the Tcl C API for this: Tcl_GetChannelHandle IIRC). Channel handles for non-files (like sockets) would simply cause the command to throw an error.

CMcC Good suggestion, I've made the change you suggested. Had to add something to extract fd from channel name, too, since tcl doesn't provide a fd->chan mapping anymore.

AK, query: Where do you need a mapping from fd's to channels, and why does that mean that the fd has to be extracted from the channel name (which is a nimplicit mapping from channel to fd, and not the other way around) ? I am confused.


CL has a still-too-vague memory that much of this is possible in Windows, also. More on this, in time.

Darren New I can't help too much, but the place to start with this on Windows is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/dirref_9hgu.asp [Davy's been threatening to put some of this in winutils.]

That's now a dead link -- MSDN regularly is rearranged such that links into MSDN tend to become invalid over time.


CmCc The idea for tclhttpd is to use directory notification to maintain a cache. .tml files can be transformed on-the-fly to .html by inspection at fetch-time by tclhttpd. However, I would like to experiment with something like Linux's kernel httpd, which doesn't transfer control to tclhttpd if the URL can be satisfied by static inspection of the directory tree. One possible solution, then, is to have tclhttpd monitor a directory for changes, and simply delete more-derived files. Thus kernel httpd would provoke tclhttpd to regenerate content.

Another idea is for look-aside (if that's the right word) caching for tclhttpd, where several directories could contain variant caches of a single source directory (perhaps specialised for different browsers?) Such a facility needs to be able to invalidate the caches on changes to the source - I think it would be more effective to maintain records of the relationship of source-to-cache in the source directory than the cached directories, and propagate changes (by simply removing the derived/cached content.)


It finally dawned on CL that there's a better way to handle all the people who ask for directory-change events, tail-write events, and so on. Until now, we've gravely responded: "thou must poll, with certain platform-dependent exceptions."

Here's what questioners really want to hear: "use XXX; it synthesizes a virtual event that perfectly matches your description." Now all that's left is to write up the XXX implementations. With me traveling, and a weekend approaching, will RS or someone else beat me to it?


Bah! It's all trivial until you start looking at NFS, and then at NFS mounts under NFS mounts... then it get's too scary.

Dangers I have known...


I think libfam handles NFS mounts. Not sure about NFS mounts under NFS mounts though.


Category Package