[Twisted-Python] symlink support in filepath.FilePath

glyph at divmod.com glyph at divmod.com
Mon Mar 24 14:58:45 MDT 2008


On 06:30 pm, exarkun at divmod.com wrote:
>On Mon, 24 Mar 2008 13:15:46 -0500, Ying Li <cyli at alum.mit.edu> wrote:

>So are you looking for something like this?
>
>    fp = FilePath(...)
>    fp.restat(lstat=True)
>    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?

I am not working on this application, but I have some ideas of my own...

It occurs to me that isfile and isdir both use cached stat results, but 
islink re-lstat()s each time.  This could of course give a potentially 
inconsistent view of the filesystem without restat()'ing.

Without regard to backwards compatibility, I would probably suggest that 
we do something like this:

    fp = FilePath(...)
    fp.getModificationTime() # link time
    fp.followLink().getModificationTime() # destination time (even if 
dest is a link!)

This would allow finer-grained control of what exactly you were asking 
for.  (It would also work more nicely by default with broken symlinks.) 
However, keeping compatibility in mind (given that this is easily API- 
compatible,  but behavior would change very slightly and ostensibly be 
less buggy, I'm not sure whether to do this or not):

    fp = FilePath(...)
    fp.getModificationTime() # destination time
    fp.asLink().getModificationTime() # link time
    fp.asLink().followLink() #... etc

This is basically the same as your cop-out example, except we don't 
introduce yet another interface for other filepath implementations to 
emulate.




More information about the Twisted-Python mailing list