diff -r 8fe9bef4cde4 src/org/python/modules/posix/PosixModule.java --- a/src/org/python/modules/posix/PosixModule.java Tue Sep 03 14:08:28 2013 -0700 +++ b/src/org/python/modules/posix/PosixModule.java Thu Sep 05 13:06:01 2013 -0700 @@ -728,13 +728,13 @@ public static void unlink(PyObject path) { String absolutePath = absolutePath(path); File file = new File(absolutePath); + if (file.isDirectory()) { + throw Py.OSError(Errno.EISDIR, path); + } if (!file.delete()) { // Something went wrong, does stat raise an error? posix.stat(absolutePath); - // It exists, is it a directory, or do we not have permissions? - if (file.isDirectory()) { - throw Py.OSError(Errno.EISDIR, path); - } + // It exists, do we not have permissions? if (!file.canWrite()) { throw Py.OSError(Errno.EPERM, path); }