shutil _isindir

David Hoese dhoese at gmail.com
Fri Oct 21 23:13:06 EDT 2011


Hi,

I wasn't really sure where to post this since the python-dev list seems 
way too official.  I'm wondering/questioning the behavior of 
shutil.move.  It currently does a check for if the dst is inside the src 
directory with a _destinsrc function.  This function uses 
os.path.abspath to convert the arguments, but I think it should convert 
using os.path.realpath.  A recent problem I had with this I ended up 
asking on stackoverflow: 
http://stackoverflow.com/questions/7854608/python-shutil-move-odd-softlinking

So I was wondering if this sounds like a change that should happen in 
the shutil code or should programmers(me) just be more careful.  I feel 
like it should be in the shutil code since its getting around a checked 
case (destination inside source) and it can end up deleting information 
when a move was intended.  But then again this has been in the standard 
lib for a while now, so I'm guessing there are reasons for it...plus it 
was a dumb mistake by me.

So I guess what I'm asking is what are the reasons that _destinsrc uses 
abspath instead of realpath?  And is there a better place to ask this?

FYI, I was provided this link to the shutil.py source on SO: 
http://hg.python.org/cpython/file/d30482d51c25/Lib/shutil.py#l262

-Dave



More information about the Python-list mailing list