Fri 15 Dec 2006

AllegroServe, relative pathnames, and working directories

I just ran into a quirk/characteristic of Lisp and AllegroServe that I think is worth documenting.

Consider a directory structure like the following:
  • /tmp/
    • xyz/
      • test.txt
      • xyz/
        • test.txt
Start mlisp in /tmp/ and evaluate
  (require :aserve)
(use-package :net.aserve)
(publish-directory :prefix "/" :destination "xyz/")
(net.aserve:start :port 8100)
Visit the test URL. You'll see the contents of /tmp/xyz/test.txt.

Now, evaluate the following:
  :cd xyz
and refresh the page in your browser. You'll see the contents of /tmp/xyz/xyz/test.txt. If that file doesn't exist, you'll get an error.

This, to me, was quite unexpected. The AllegroServe publishing mechanism stores the mapping when you call publish-*, and looks up the file in the current context each time it is requested. Unless you provide an absolute pathname, the files published in this way — and, similarly, relative pathnames used for writing new data — will change if you change your working directory. Quite correct, and consistent, but unexpected.

AllegroServe provides something of a solution (the preload argument), but this actually stores the data in-memory rather than pinning the pathname. I can think of two solutions: call publish-* in a fixed environment, or convert the relative pathname to an absolute one when publishing. I don't think either of these should be done by AllegroServe itself (though a third preload alternative would be cool), particularly as the issue is not confined to publishing, but it's definitely something to be aware of.

Posted at 2006-12-15 11:15:51 by RichardLink to AllegroServe, rela…
Comments, trackbacks.

Google
Web holygoat.co.uk
  • richard is: