delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/11/27/09:51:29

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:subject:message-id:mime-version
:content-type; q=dns; s=default; b=fjw2/aYEjaNDsyNbgmxiRCChsHmFg
YFYwu0EYRIG4YbYj1PQ6v+S80IRaPbXR4xGkWLc/8N9q5ceKTe5AdX9wXjyqfzpD
ZD99jDLUjlrBRpGC9SU8GD+F6LdFv+OPICYLQIvMVgLNizqSS3Ns2R4O5YjRYlpC
DCSegzfxGBIfN4=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:subject:message-id:mime-version
:content-type; s=default; bh=TD2YWdNX8iB7pmADGWqFrk/G1nE=; b=Ai7
FSMQDvfWtp62nFXfPvzpjmTodmHAJen1ivnLTymjSlcourIRDYuThtFrInX66deE
Y4rLDOHfdVohb7CdaSsiP2Lqt2Ekbrvj3sC0yZGFpKGYCzWHtLSDvdQT783JQEhF
z6CliYBap9noUS28ypsVFxbDe+nr1Gqdc2yfkEoY=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-wm0-f50.google.com
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=rrsRuv30g4LhrqLlVsc7BwJLdiYE0OQYo33coYqnSgY=; b=JPkMoIwim3QfWk1sZh+2puOzMF+mIusVM0Nn9KERl305OklDofRnaauuOYFO53Odls 4rgF0oa5JGh1J4myrOKy5N4XZh+pUNndSovW/JkRbF5zuqrm7H4fCx54sGQf58fDsJHv nVIRu/pXzmpDVMtsbi6OJwwkSTOElt2NgTLbLMDGkK/cFwb2i4m/g6uuJCpZ0Co6UtjI Xz1lOSJkg0PDJc/YNRqKg/EjbRd4ZvlpkaX9mm2g8xG9Wp9yGy5a1mE/byzma0HOCY+p R6I/Gpm04DGRcugHuXh/Bi5LqGdNtkYJ3qf8BFmWkuTHgfYSHBpBIgAWatVtWap+1bl4 Lwgw==
X-Gm-Message-State: ALoCoQmf8HXPfsOrG+nSNMcrzQTRYQkNeMfEnzrX+cOZ24R3NMDy6w2bJSvN9xSUptRR4AKvQ+HF
X-Received: by 10.194.90.79 with SMTP id bu15mr65914995wjb.36.1448635869166; Fri, 27 Nov 2015 06:51:09 -0800 (PST)
Date: Fri, 27 Nov 2015 14:51:05 +0000
From: Adam Dinwoodie <adam AT dinwoodie DOT org>
To: cygwin AT cygwin DOT com
Subject: Incorrect Python errors when using os.remove to delete a directory
Message-ID: <20151127145105.GG14466@dinwoodie.org>
MIME-Version: 1.0
User-Agent: Mutt/1.5.21 (2010-09-15)
X-IsSubscribed: yes

If I use os.remove in Python to remove a directory, I expect it to fail
with an OSError on Python2 or a IsADirectoryError on Python3.  On
Python2, I get OSError, but with the wrong error code, whereas on
Python3 I get completely the wrong exception.

Simple testcases:

    $ rm -rf testdir && mkdir testdir && python -c 'import os; os.remove("testdir")'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    OSError: [Errno 1] Operation not permitted: 'testdir'

    $ rm -rf testdir && mkdir testdir && python3 -c 'import os; os.remove("testdir")'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    PermissionError: [Errno 1] Operation not permitted: 'testdir'

On my handy CentOS box, I see the following instead:

    $ rm -rf testdir && mkdir testdir && python -c 'import os; os.remove("testdir")'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    OSError: [Errno 21] Is a directory: 'testdir'

    $ rm -rf testdir && mkdir testdir && python3 -c 'import os; os.remove("testdir")'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    IsADirectoryError: [Errno 21] Is a directory: 'testdir'

Now I've realised what's going wrong I can work around it, but it'd be
nice if the correct error were raised in the first place.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019