[issue8523] shutil.rmtree and os.listdir cannot recover on error conditions

rubenlm report at bugs.python.org
Thu Apr 29 16:08:11 CEST 2010


rubenlm <ruben at libhertz.com> added the comment:

Here is my current error handler:

def handleRmtreeError(func, path, exc):
  excvalue = exc[1]
  if excvalue.errno == errno.EACCES:
    if func in (os.rmdir, os.remove):
      parentpath = path.rpartition('/')[0]
      os.chmod(parentpath, stat.S_IRWXU) # 0700
      func(path)
    elif func is os.listdir:
      os.chmod(path, stat.S_IRWXU) # 0700
      rmtree(path=path, ignore_errors=False, onerror=handleRmtreeError)
  else:
      raise

Looking back to this code there is an infinite recursion bug if os.chmod fails for some reason in the os.listdir condition. I don't see an easy way to solve this...

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8523>
_______________________________________


More information about the Python-bugs-list mailing list