Issue2083

classification
Title: os.unlink() can delete directories, it should raise an exception instead.
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jeff.allen Nosy List: cdleonard, jeff.allen, santa4nt
Priority: Keywords: patch

Created on 2013-09-05.13:24:21 by cdleonard, last changed 2013-12-22.17:57:20 by jeff.allen.

Files
File name Uploaded Description Edit Remove
issue2083.patch santa4nt, 2013-09-05.20:04:11 Raise an exception when os.unlink() is called with a directory path.
Messages
msg8100 (view) Author: Leonard Crestez (cdleonard) Date: 2013-09-05.13:24:21
Here is some very simple sample code:

import os
from tempfile import mkdtemp
tempdir = mkdtemp()
print "temp is %r" % tempdir
os.unlink(tempdir)

This throws an exception on cpython (OSError with errno EISDIR) but succeeds on jython.
msg8101 (view) Author: Santoso Wijaya (santa4nt) Date: 2013-09-05.20:04:11
This is because the Java API used, File#delete() [1] does not distinguish between files and directories, unlike the semantics of os.unlink().

Attaching a simple fix.


[1] http://docs.oracle.com/javase/7/docs/api/java/io/File.html#delete()
msg8208 (view) Author: Jeff Allen (jeff.allen) Date: 2013-12-21.22:50:48
I have tried this out locally and it seems fine.

I have added a test for OSError thrown to test.test_os_jy (which fails before the patch is applied) and a NEWS entry. Regression tests run with no new failures.

I will commit the whole as one change set in Santoso's name. Thanks for this!
msg8210 (view) Author: Jeff Allen (jeff.allen) Date: 2013-12-22.17:57:20
Now resolved at http://hg.python.org/jython/rev/dc9b1aa30f6d thanks to this patch.
History
Date User Action Args
2013-12-22 17:57:20jeff.allensetstatus: open -> closed
resolution: fixed
messages: + msg8210
2013-12-21 22:50:49jeff.allensetassignee: jeff.allen
messages: + msg8208
nosy: + jeff.allen
2013-09-05 20:04:17santa4ntsettype: behaviour
components: + Core
2013-09-05 20:04:12santa4ntsetfiles: + issue2083.patch
keywords: + patch
messages: + msg8101
nosy: + santa4nt
2013-09-05 13:24:21cdleonardcreate