[issue19643] shutil rmtree fails on readonly files in Windows

2014-10-16 Thread Paul Moore
Paul Moore added the comment: Not a bad idea. I would want the implementation to remain in the documentation as well, as code that wants to be portable back to earlier versions of Python will need it. But for code that targets Python 3.5+ only, having it available "out of the box" is a nice ad

[issue19643] shutil rmtree fails on readonly files in Windows

2014-10-16 Thread R. David Murray
R. David Murray added the comment: I think it is an interesting idea. Probably worth opening a new enhancement request with the suggestion. -- ___ Python tracker ___ __

[issue19643] shutil rmtree fails on readonly files in Windows

2014-10-16 Thread Spencer Judge
Spencer Judge added the comment: Although this is closed, I stumbled across it while looking to see if this behavior had changed at all recently, and I have a suggestion I think might work. How about we take Tim's example error function which was added to the docs, and it's bound to something

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Tim Golden
Changes by Tim Golden : -- resolution: -> fixed stage: commit review -> resolved status: open -> closed ___ Python tracker ___ ___ Py

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Roundup Robot
Roundup Robot added the comment: New changeset 31d63ea5dffa by Tim Golden in branch 'default': Issue19643 Add an example of shutil.rmtree which shows how to cope with readonly files on Windows http://hg.python.org/cpython/rev/31d63ea5dffa New changeset a7560c8f38ee by Tim Golden in branch 'defa

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Tim Golden
Tim Golden added the comment: Thanks. I'll hold off pushing until I've had a chance to run it on a Unix system. I'm not 100% whether it will operate in the same way there. -- ___ Python tracker

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Zachary Ware
Zachary Ware added the comment: LGTM! -- stage: -> commit review ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Tim Golden
Tim Golden added the comment: Thanks, Zach. Updated patch. -- assignee: -> tim.golden Added file: http://bugs.python.org/file35170/issue19643-doc.2.patch ___ Python tracker ___

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Zachary Ware
Zachary Ware added the comment: Fair point, Paul. Patch looks good to me, Tim, barring a couple of nits pointed out on Rietveld. -- ___ Python tracker ___ __

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Tim Golden
Changes by Tim Golden : -- keywords: +patch Added file: http://bugs.python.org/file35168/issue19643-doc.patch ___ Python tracker ___ _

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-07 Thread Tim Golden
Tim Golden added the comment: The attached patch adds an example to the shutil documentation showing how to use an onerror handler to reattempt the removal of a read-only file. It's deliberately low-tech and simply removes the attribute and retries. If there's some other obstacle, it will cont

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-06 Thread Paul Moore
Paul Moore added the comment: Checking the exact error could be a bit fragile. I have a feeling I recently saw an issue somewhere with code that stopped working on Python 3.4 because the precise error raised for a read-only file changed. I don't recall where the issue was, unfortunately. It's

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-06 Thread Zachary Ware
Zachary Ware added the comment: I'm good with just adding an example to the docs, along the lines of Paul's del_rw. I think it would be better to use a more conservative example though, something like: def readonly_handler(rm_func, path, exc_info): if issubclass(exc_info[0], Permiss

[issue19643] shutil rmtree fails on readonly files in Windows

2014-05-06 Thread Tim Golden
Tim Golden added the comment: Ok, so to move this forward we have essentially two proposals: 1) Add a remove_readonly flag 2) Add a doc example which shows how to use the onerror handler to remove a recalcitrant file. I'm -0.5 on (1) because it feels like Windows-specific clutter; and +0 on (

[issue19643] shutil rmtree fails on readonly files in Windows

2014-03-17 Thread Jovik
Jovik added the comment: This could be at least part of docs; I found that people tend to avoid shutil.rmtree(...) on Windows because of such issues. Some of them call subprocess("rmdir /S /Q ") to get desired behavior. -- nosy: +Jovik ___ Python tr

[issue19643] shutil rmtree fails on readonly files in Windows

2014-01-21 Thread Paul Moore
Paul Moore added the comment: Looks like that works. At least in my case - I just did def del_rw(action, name, exc): os.chmod(name, stat.S_IWRITE) os.remove(name) shutil.rmtree(path, onerror=del_rw) Something more robust might check if name is a directory and os.rmdir th

[issue19643] shutil rmtree fails on readonly files in Windows

2014-01-21 Thread R. David Murray
R. David Murray added the comment: OK, rereading that issue, I disagree with Tarek and I think that the patch on that issue is ill-advised as it looks like it changes behavior in a non-backward-compatible way. If you changed your set_rw onerror handler to a rm_ro_file error handler, would thi

[issue19643] shutil rmtree fails on readonly files in Windows

2014-01-21 Thread Paul Moore
Paul Moore added the comment: It's similar. But the problem is that it only returns a list of errors, it doesn't let you address the error *while the rmtree is in progress*. The key thing is that if you can fix the problem in onerror, you can avoid needing to restart the whole tree walk, which

[issue19643] shutil rmtree fails on readonly files in Windows

2014-01-21 Thread R. David Murray
R. David Murray added the comment: See issue 8523 for a discussion of changing the way onerror behaves. I think it is addressing this same use case, but I didn't reread it in detail. -- ___ Python tracker ___

[issue19643] shutil rmtree fails on readonly files in Windows

2014-01-21 Thread Paul Moore
Paul Moore added the comment: The most obvious solution would be if the onerror argument allowed for retries. At the moment, all it can do is report issues, not recover. Suppose that returning True from onerror meant "retry the operation". Then you could do def set_rw(operation, name, exc)

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread Zachary Ware
Zachary Ware added the comment: I make no claims of being good at naming things :) -- ___ Python tracker ___ ___ Python-bugs-list mail

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread Tim Golden
Tim Golden added the comment: TBH I'm still fairly -0 and edging towards -0.5. If we didn't already have two keyword args I might be convinced towards a jfdi=True flag. But, as the OP described, the current params already allow for a workaround of sorts and another param of the semantics we're

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread R. David Murray
R. David Murray added the comment: That's not a good name for the flag. The problem is that 'read-only' means different things on Windows than it does on Unix. Which is why I suggested that the flag control whether or not it acts "posix like" on Windows. So perhaps 'posix_compat'? That fee

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread Zachary Ware
Zachary Ware added the comment: I like the idea of a remove_readonly flag. I was going to say that I'm a bit worried about the fact that shutil.rmtree already has a couple of keyword arguments, but it's nowhere near what, say, copytree has. Call me +0.75. --

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread Ivan Radic
Ivan Radic added the comment: >You are essentially asking that we have an option to make the windows behavior >mirror the posix behavior? (A read only file in a writable directory can be >deleted in posix, since only the directory entry, not the file, is being >deleted.) Actually, your expla

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread R. David Murray
R. David Murray added the comment: Well, it would *definitely* need to be a new explicit option whose default value was the current behavior. -- ___ Python tracker ___ _

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread Tim Golden
Tim Golden added the comment: This, unfortunately, is the classic edge-case where intra-platform consistency and inter-platform consistency clash. I (on Windows) would certainly be surprised if a tree delete removed read-only files without my specifying some kind of override. I understand why

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread R. David Murray
R. David Murray added the comment: You are essentially asking that we have an option to make the windows behavior mirror the posix behavior? (A read only file in a writable directory can be deleted in posix, since only the directory entry, not the file, is being deleted.) That makes some sen

[issue19643] shutil rmtree fails on readonly files in Windows

2013-11-18 Thread Ivan Radic
New submission from Ivan Radic: shutil.rmtree works nice on Windows until it hits file with read only attribute set. Workaround is to provide a onerror parameter as a function that checks and removes file attribute before attempting to delete it. Can option to delete read_only files be integra