[issue1669] shutil.rmtree fails on symlink, after deleting contents

2008-01-21 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

If rmtree() always returns in case of symbolic links (as it is
checked-in), wouldn't it be much simpler to totally do away with
'onerror' handling? I thought 'onerror' gives the user the option how to
proceed (which is true in other usages).

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1669] shutil.rmtree fails on symlink, after deleting contents

2008-01-21 Thread Georg Brandl

Georg Brandl added the comment:

Guido explicitly said it should raise IOError, not ValueError,
and it should use the onerror() handling used for all other errors
which makes sense for me too.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com




[issue1669] shutil.rmtree fails on symlink, after deleting contents

2008-01-21 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

 and it should use the onerror() handling used for all other errors
 which makes sense for me too.

Sure. I am ok with using 'onerror'. The point I am trying to make is
that there is slight difference between 'onerror' in this case and in
the three other places where it is called. In the case of symlink,
rmtree() returns even when 'onerror' doesn't raise exception. This is
not same in the other cases where rmtree() continues. I am just
wondering if this inconsistency is worth it and if it is, an explicit
mention in the doc will be nice.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1669] shutil.rmtree fails on symlink, after deleting contents

2007-12-20 Thread Tim Koopman

Changes by Tim Koopman:


--
title: shutils.rmtree fails on symlink, after deleting contents - 
shutil.rmtree fails on symlink, after deleting contents

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1669] shutil.rmtree fails on symlink, after deleting contents

2007-12-20 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

Please try to include stack trace in bug reports. I reproduced the error
on my Linux (SuSE 10). 

marvin:tmp$ ls -l dirlink testdir
lrwxrwxrwx 1 raghu users7 2007-12-20 10:10 dirlink - testdir/

testdir:
total 0
-rw-r--r-- 1 raghu users 0 2007-12-20 10:36 testfile

shutil.rmtree('dirlink') produces:

--
Traceback (most recent call last):
  File t.py, line 4, in module
shutil.rmtree('dirlink')
  File /localhome/raghu/localwork/cpython/python/Lib/shutil.py, line
194, in rmtree
onerror(os.rmdir, path, sys.exc_info())
  File /localhome/raghu/localwork/cpython/python/Lib/shutil.py, line
192, in rmtree
os.rmdir(path)
OSError: [Errno 20] Not a directory: 'dirlink'
--

While we are removing the contents of the target directory as expected,
the final 'rmdir' fails on removing the symbolic link. For the sake of
consistency, we can explicitly remove the target directory and leave the
symbolic link intact. Is this what you are expecting?

--
nosy: +draghuram

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1669] shutil.rmtree fails on symlink, after deleting contents

2007-12-20 Thread Guido van Rossum

Guido van Rossum added the comment:

I agree with Tesiph, more useful behavior would be to raise an error
immediately because the argument is not a directory. If you wanted to
remove the think linked to, you could use rmtree(foo/.,
ignore_errors=True).

--
nosy: +gvanrossum

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1669] shutil.rmtree fails on symlink, after deleting contents

2007-12-20 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

I am ok with disallowing symlinks in rmtree() because if it were to be
allowed, the semantics are not clear. In addition, neither 'rmdir' nor
'rm -rf' delete the target directory. 

The attached patch would raise error if symbolic link is passed to
rmtree. Even though there is a parameter 'ignore_errors, I don't think
it should be used in suppressing symbolic link error. Comments?

Added file: http://bugs.python.org/file9015/rmtree.diff

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__Index: Lib/shutil.py
===
--- Lib/shutil.py	(revision 59581)
+++ Lib/shutil.py	(working copy)
@@ -140,7 +140,8 @@
 raise Error, errors
 
 def rmtree(path, ignore_errors=False, onerror=None):
-Recursively delete a directory tree.
+Recursively delete a directory tree. Fail if path is symbolic
+link.
 
 If ignore_errors is set, errors are ignored; otherwise, if onerror
 is set, it is called to handle the error with arguments (func,
@@ -150,6 +151,10 @@
 is false and onerror is None, an exception is raised.
 
 
+
+if os.path.islink(path):
+raise ValueError('path can not be symbolic link')
+
 if ignore_errors:
 def onerror(*args):
 pass
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1669] shutil.rmtree fails on symlink, after deleting contents

2007-12-20 Thread Guido van Rossum

Guido van Rossum added the comment:

Thanks for the patch. I think it should raise IOError, not ValueError,
and it should use the onerror() handling used for all other errors.
Also, can you include an update for the docs in the Doc tree?

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1669] shutil.rmtree fails on symlink, after deleting contents

2007-12-20 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

Index: Lib/shutil.py
===
--- Lib/shutil.py   (revision 59581)
+++ Lib/shutil.py   (working copy)
@@ -156,6 +156,16 @@
 elif onerror is None:
 def onerror(*args):
 raise
+
+try:
+if os.path.islink(path):
+if ignore_errors:
+return
+else:
+raise IOError('path can not be symbolic link')
+except IOError, err:
+onerror(os.path.islink, path, sys.exc_info())
+
 names = []
 try:
 names = os.listdir(path)
---

How does this look? The error handling is slightly different for this
case because it can not continue if 'ignore_errors' is True. I will
update the doc if the code change is ok.

On Dec 20, 2007 12:43 PM, Guido van Rossum [EMAIL PROTECTED] wrote:

 Guido van Rossum added the comment:

 Thanks for the patch. I think it should raise IOError, not ValueError,
 and it should use the onerror() handling used for all other errors.
 Also, can you include an update for the docs in the Doc tree?


 __
 Tracker [EMAIL PROTECTED]
 http://bugs.python.org/issue1669
 __


__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1669
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com