[Jython-checkins] jython: Fix regression tests for test_glob (pull request #29 against bitbucket)
jim.baker
jython-checkins at python.org
Thu Apr 17 02:28:36 CEST 2014
http://hg.python.org/jython/rev/7096b5a3f8e7
changeset: 7207:7096b5a3f8e7
user: Indra Talip <indra.talip at gmail.com>
date: Wed Apr 16 18:28:27 2014 -0600
summary:
Fix regression tests for test_glob (pull request #29 against bitbucket)
files:
src/org/python/modules/posix/PosixModule.java | 39 +++++++--
1 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/src/org/python/modules/posix/PosixModule.java b/src/org/python/modules/posix/PosixModule.java
--- a/src/org/python/modules/posix/PosixModule.java
+++ b/src/org/python/modules/posix/PosixModule.java
@@ -13,6 +13,9 @@
import java.nio.channels.Channel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
import java.security.SecureRandom;
import java.util.Iterator;
import java.util.Map;
@@ -727,17 +730,23 @@
public static void unlink(PyObject path) {
String absolutePath = absolutePath(path);
- File file = new File(absolutePath);
- if (file.isDirectory()) {
- throw Py.OSError(Errno.EISDIR, path);
- } else if (!file.delete()) {
- // Something went wrong, does stat raise an error?
- posix.stat(absolutePath);
- // It exists, do we not have permissions?
- if (!file.canWrite()) {
- throw Py.OSError(Errno.EPERM, path);
+ try {
+ Path nioPath = new File(absolutePath).toPath();
+ if (Files.isDirectory(nioPath, LinkOption.NOFOLLOW_LINKS)) {
+ throw Py.OSError(Errno.EISDIR, path);
+ } else if (!Files.deleteIfExists(nioPath)) {
+ // Something went wrong, does stat raise an error?
+ posix.stat(absolutePath);
+ // It exists, do we not have permissions?
+ if (!Files.isWritable(nioPath)) {
+ throw Py.OSError(Errno.EPERM, path);
+ }
+ throw Py.OSError("unlink(): an unknown error occurred: " + absolutePath);
}
- throw Py.OSError("unlink(): an unknown error occurred: " + absolutePath);
+ } catch (IOException ex) {
+ PyException pyError = Py.OSError("unlink(): an unknown error occurred: " + absolutePath);
+ pyError.initCause(ex);
+ throw pyError;
}
}
@@ -935,7 +944,15 @@
@Override
public PyObject __call__(PyObject path) {
- return PyStatResult.fromFileStat(posix.lstat(absolutePath(path)));
+ String absolutePath = absolutePath(path);
+
+ // round tripping from a string to a file to a string loses
+ // trailing slashes so add them back back in to get correct posix.lstat
+ // behaviour if path is not a directory.
+ if (asPath(path).endsWith(File.separator)) {
+ absolutePath = absolutePath + File.separator;
+ }
+ return PyStatResult.fromFileStat(posix.lstat(absolutePath));
}
}
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list