Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107514

RE: Remove directory tree without following symlinks

Path csiph.com!news.fcku.it!peer04.fr7!news.highwinds-media.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Albert-Jan Roskam <sjeik_appie@hotmail.com>
Newsgroups comp.lang.python
Subject RE: Remove directory tree without following symlinks
Date Sat, 23 Apr 2016 09:34:12 +0000
Lines 19
Message-ID <mailman.8.1461404121.32212.python-list@python.org> (permalink)
References <CACL+1aueH_scSTYW1Q6pGsZ92+8OWHB6tks3SqAAaU-wb6Ac4Q@mail.gmail.com> <DUB123-W362E7C64F347B92A74E34B83600@phx.gbl>
Mime-Version 1.0
Content-Type text/plain; charset="windows-1256"
Content-Transfer-Encoding base64
X-Trace news.uni-berlin.de SQODkQUa+QR13WIOUFFYjA+Yx0y/kuORjF0aQ+A8xWnQ==
Return-Path <sjeik_appie@hotmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; '-0500': 0.07; 'only,': 0.07; 'raises': 0.07; 'seemed': 0.07; '"%s"': 0.09; '22,': 0.09; 'raised,': 0.09; 'url:github': 0.09; 'windowserror': 0.09; ':-)': 0.12; '2016': 0.16; 'dirs,': 0.16; 'email addr:hotmail.com&gt;': 0.16; 'fyi,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Remove': 0.16; 'subprocess': 0.16; 'url:pip': 0.16; 'wrote:': 0.16; 'tree': 0.18; '&gt;': 0.18; 'windows': 0.20; 'to:2**1': 0.21; '(or': 0.23; 'help.': 0.23; 'thanks,': 0.24; 'header:In-Reply-To:1': 0.24; 'error': 0.27; 'fri,': 0.27; "skip:' 10": 0.28; 'looks': 0.29; 'sure,': 0.29; 'comments': 0.30; 'date:': 0.31; 'option': 0.31; 'aside': 0.32; 'useful': 0.33; 'that,': 0.34; 'dir': 0.35; 'subject:': 0.35; 'but': 0.36; 'email addr:python.org': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thought': 0.37; "won't": 0.38; 'from:': 0.39; 'to:addr:python.org': 0.40; 'email addr:gmail.com': 0.62; 'today': 0.65; 'improvement.': 0.66; 'email name:python-list': 0.67; 'charset:windows-1256': 0.67; 'pip': 0.84; 'subject:tree': 0.84
X-TMN [4KYcA/JfAXlSouBFOYln2TnUOKpTFXPi]
X-Originating-Email [sjeik_appie@hotmail.com]
Importance Normal
In-Reply-To <CACL+1aueH_scSTYW1Q6pGsZ92+8OWHB6tks3SqAAaU-wb6Ac4Q@mail.gmail.com>
X-OriginalArrivalTime 23 Apr 2016 09:34:13.0091 (UTC) FILETIME=[4BD27B30:01D19D43]
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <DUB123-W362E7C64F347B92A74E34B83600@phx.gbl>
X-Mailman-Original-References <571a3ba2$0$1597$c3e8da3$5496439d@news.astraweb.com>, <1461337766.365000.586700849.0DDBDB0B@webmail.messagingengine.com>, <mailman.16.1461337768.2861.python-list@python.org>, <571a5be6$0$1590$c3e8da3$5496439d@news.astraweb.com>, <DUB123-W22A605538041FB2749C64B836F0@phx.gbl>, <CACL+1aueH_scSTYW1Q6pGsZ92+8OWHB6tks3SqAAaU-wb6Ac4Q@mail.gmail.com>
X-Received-Bytes 5102
X-Received-Body-CRC 1632228310
Xref csiph.com comp.lang.python:107514

Show key headers only | View raw



> From: eryksun@gmail.com
> Date: Fri, 22 Apr 2016 13:28:01 -0500
> Subject: Re: Remove directory tree without following symlinks
> To: python-list@python.org
> 
> On Fri, Apr 22, 2016 at 12:39 PM, Albert-Jan Roskam
> <sjeik_appie@hotmail.com> wrote:
> > FYI, Just today I found out that shutil.rmtree raises a WindowsError if the dir is read-
> > only (or its contents). Using 'ignore_errors', won't help. Sure, no error is raised, but the
> > dir is not deleted either! A 'force' option would be a nice improvement.
> 
> Use the onerror handler to call os.chmod(path, stat.S_IWRITE). For
> example, see pip's rmtree_errorhandler:
> 
> https://github.com/pypa/pip/blob/8.1.1/pip/utils/__init__.py#L105

Thanks, that looks useful indeed. I thought about os.chmod, but with os.walk. That seemed expensive. So I used subprocess.call('rmdir "%s" /s /q' % dirname). That's Windows only, of course, but aside of that, is using subprocess less preferable?Fun fact: I used it to remove .svn dirs, just like what is mentioned in the pip comments :-)

 		 	   		  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Remove directory tree without following symlinks Steven D'Aprano <steve@pearwood.info> - 2016-04-23 00:56 +1000
  Re: Remove directory tree without following symlinks Random832 <random832@fastmail.com> - 2016-04-22 11:09 -0400
    Re: Remove directory tree without following symlinks Steven D'Aprano <steve@pearwood.info> - 2016-04-23 03:14 +1000
      RE: Remove directory tree without following symlinks Albert-Jan Roskam <sjeik_appie@hotmail.com> - 2016-04-22 17:39 +0000
      Re: Remove directory tree without following symlinks eryk sun <eryksun@gmail.com> - 2016-04-22 13:28 -0500
      RE: Remove directory tree without following symlinks Albert-Jan Roskam <sjeik_appie@hotmail.com> - 2016-04-23 09:34 +0000
      Re: Remove directory tree without following symlinks eryk sun <eryksun@gmail.com> - 2016-04-23 15:22 -0500
      Re: Remove directory tree without following symlinks eryk sun <eryksun@gmail.com> - 2016-04-24 14:42 -0500
  Re: Remove directory tree without following symlinks Paul Rubin <no.email@nospam.invalid> - 2016-04-23 01:13 -0700
    Re: Remove directory tree without following symlinks Steven D'Aprano <steve@pearwood.info> - 2016-04-23 20:24 +1000
      Re: Remove directory tree without following symlinks Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-04-23 23:37 +1200
      Re: Remove directory tree without following symlinks Random832 <random832@fastmail.com> - 2016-04-23 17:04 -0400
  Re: Remove directory tree without following symlinks Nobody <nobody@nowhere.invalid> - 2016-04-23 17:29 +0100
    Re: Remove directory tree without following symlinks Random832 <random832@fastmail.com> - 2016-04-23 17:07 -0400

csiph-web