[Twisted-Python] symlink support in filepath.FilePath

Jean-Paul Calderone exarkun at divmod.com
Mon Mar 24 14:30:18 EDT 2008

On Mon, 24 Mar 2008 13:15:46 -0500, Ying Li <cyli at alum.mit.edu> wrote:
>>>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.
>Well, I did write one, and that's when I was told to start submitting my 
>changes into FilePath.  :)

Aha. :)

>Basically I need to be able to handle symlinks as links - hence the restat.

So are you looking for something like this?

    fp = FilePath(...)
    fp.getModificationTime() # link's modification time

I'm not sure about that.  Aside from the freaky action at a distance, it
probably is prone to failures when certain FilePath methods internally
decide to restat, thus replacing the link data with data about the target.

The cop-out API would be one like this:

    fp = FilePath(...)
    fp.lstat().st_mtime # link's modification time

I can't think of anything strictly better at the moment, though.  What does
usage in your application suggest is a good approach?

>There are other things I need, such as an openWithFlags method (basically, 
>the ISFPTServer interface specifies that I need to be able to open a file 
>with a bunch of flags (read, write, append, create, truncate, exclusive), 
>and I'd like to simply pass that through to a method.  I've tried to come up 
>with a fairly elaborate mapping of said flags onto (r, w, r+, w+, etc.), but 
>there are some things (like the exclusive flag) I don't know what to do 

It seems like FilePath.open has some issues currently.  It would be a good
thing if it had an API which allowed explicit, precise control over how the
open happened.

>I'm not sure if this would be useful in FilePath.
>Another thing I need is to be able to change permissions.  My applications 
>ignores requests to change ownership and such, but being able to change 
>permissions I think would be good.  And I know that FilePath.copyTo and 
>FilePath.moveTo right now do not preserve permissions or ownership - I'm not 
>sure if this is desired behavior, but if it isn't, then FilePath needs some 
>mechanism for changing the attributes of a file or directory.  But then we 
>get into platform problems, and FilePath may get overly complicated.

FilePath.chmod would be a great addition.  `copyTo´ and `moveTo´ should try
to preserve permission (at least optionally).  I'm not sure if this would
have scary consequences (handling failures, for example, complicates the
matter), but at least the idea is nice.


More information about the Twisted-Python mailing list