[MERGE] [BUG 363837] Catch _win32_delete_readonly failure to remove file or directory and try to recover
Maritza Mendez
martitzam at gmail.com
Thu May 7 18:42:05 BST 2009
2009/5/7 Alexander Belchenko <bialix at ukr.net>
> Hi Maritza,
>
> Because I'm the one who was involved in writing _win32_delete_readonly,
> I'll try to provide some hints for you.
>
> def _win32_delete_readonly(function, path, excinfo):
> """Error handler for shutil.rmtree function [for win32]
> Helps to remove files and dirs marked as read-only.
> """
> exception = excinfo[1]
> if function in (os.remove, os.rmdir) \
> and isinstance(exception, OSError) \
> and exception.errno == errno.EACCES:
> make_writable(path)
> function(path)
> else:
> raise
>
> The problem in the code above is that it used too-broad testing for error,
> e.g.
>
> and exception.errno == errno.EACCES:
>
> errno.EACCES it's a POSIX-style error constant, IIUC it's about Access
> Denied.
>
> Fortunately it seems like actually we have there WindowsError exception,
> and therefore can get real Windows Error Code (as of GetLastError()
> returns).
>
> So, if you're adding following debugging prints to the function:
>
> def _win32_delete_readonly(function, path, excinfo):
> """Error handler for shutil.rmtree function [for win32]
> Helps to remove files and dirs marked as read-only.
> """
> exception = excinfo[1]
>
> + print type(exception), dir(exception)
> + print getattr(exception, 'winerror', None)
>
> if function in (os.remove, os.rmdir) \
> and isinstance(exception, OSError) \
> and exception.errno == errno.EACCES:
> make_writable(path)
> function(path)
> else:
> raise
>
>
> You will obtain additional information about your error with
> BeyondCompare3. Especially the second print should print to you actual
> Windows error code (
> http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx<http://msdn.microsoft.com/en-us/library/ms681381%28VS.85%29.aspx>
> )
>
> Knowing actual error code there is possible to imprtove
> _win32_delete_readonly function to make more fine-grained analysis why
> deletion of file fails and provide appropriate solution for different cases:
> deleting read-only files, files currently in use etc.
>
> HTH
>
>
That's very helpful and informative, Alexander. Thanks! I will try to
follow your lead and report back to the list what this reveals. It will
probably be tomorrow or the weekend before I get to it. I am impressed by
how rapidly discussions progress here. Do you guys all work for a
bzr-friendly boss like Canonical or do you just never sleep? :)
-M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/bazaar/attachments/20090507/19c487ed/attachment.htm
More information about the bazaar
mailing list