[Twisted-Python] symlink support in filepath.FilePath

Jean-Paul Calderone exarkun at divmod.com
Mon Mar 24 13:37:07 EDT 2008

On Mon, 24 Mar 2008 09:34:00 -0500, Ying Li <cyli at alum.mit.edu> wrote:
>I've been trying to put a few patches into twisted.python.filepath lately to 
>support symlinks.  This is because I'm trying to implement a conch SFTP 
>server using FilePath.

Hooray!  Thanks for working on FilePath. :)

>I know FilePath is supposed to be cross-platform, so I am wondering how to 
>go about it.

Hmm.  I guess FilePath _is_ supposed to be cross-platform.  Maybe it would
be useful to list the other things it is supposed to be:

  * easier to use than os.path.*
  * more efficient in naive usage (hence `restat´)
  * sufficiently self-contained so that things like ZipPath are possible
  * safe against common security-related mistakes (hence `child´)

Whether or not it succeeds at any of these goals is probably an open
question, and work could probably be done to improve it in all these
areas, _and_ the approach taken to accomplish some of these goals may
be questionable.

>  For instance, it would be really easy to add a flag to restat 
>that specifies whether to use os.stat o os.lstat.

It sounds like this change would increase the (already slightly too high)
level of weirdness in FilePath stat caching.  On the other hand, I'm not
really sure how link handling should sensibly be done in FilePath at all.

>But how should I handle the getAccessTime/etc. functions?  Should I add a 
>FilePath.symlink() function (that creates a symlink to said FilePath)?

`FilePath.symlink´ (or maybe better, something like `FilePath.linkTo´)
seems like a good addition to the API.  `get*Time´ is a bit trickier.  An
option might be to expose an `lstat´ method and let applications worry
about getting the necessary information out of that when they know they
care about the link, not its target.

>Should I just implement my own subclass of FilePath that handles symlinks 
>and not try to change FilePath?

It'd be great to have anything that's generally useful incorporated into
Twisted.  It might make sense to have a FilePath subclass for a while to
see what is an isn't useful for your SFTP server - or you might be happy
enough to briefly have a local copy of Twisted with your modifications
and only submit them once you're happy with them.


More information about the Twisted-Python mailing list