shutil _isindir

D

David Hoese

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
 
S

Steven D'Aprano

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?

Probably because abspath goes back to Python 1.5, while realpath is
comparatively recent only going back to 2.2, and nobody has thought to
change the code in shutil.

I recommend you raise a bug/feature request on the bug tracker,
preferably with a fix and a test demonstrating the problem.

http://bugs.python.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top