On 01/10/13 15:18, Chris Larson wrote:
You are almost right. On normal folders, this will work with
recurse=True, but on /tmp folders you get: OSError: [Errno 1]
Operation not permitted: '/tmp/tmpl8qBDW' on the unlink call. This
makes the if test inside the except catching false, and nothing
happens.
I'm not sure why this happens, as I am allowed to remove it using
shutil.rmtree. Making a folder in linux with the exact same
permissions does work however, so it seems to be some difference in
how the os handles the call.
Other than that, I feel that it is cleaner to have an explicit check
like this, and not use the exception framework for control flow.
Which means in the except just use raise, or just ignore it and let
someone else handle it like we actually do.
To get back the same functionality though, we should change the
isdir call to: 'if os.path.isdir(name) and recurse:'
Are you totally opposed to changing this? What I don't want to do is
to add exc.errno == errno.EPERM to the line, which will just bloath
it.
- Martin