[Jython-checkins] jython: Fix os.stat behaviour for paths with trailing slash when the path exists as a
jim.baker
jython-checkins at python.org
Fri May 9 20:44:58 CEST 2014
http://hg.python.org/jython/rev/a7b71df0cfd3
changeset: 7223:a7b71df0cfd3
parent: 7181:6e438088c0e3
user: Indra Talip <indra.talip at gmail.com>
date: Fri Apr 25 15:50:35 2014 +1000
summary:
Fix os.stat behaviour for paths with trailing slash when the path exists as a file
files:
Lib/test/test_os_jy.py | 15 ++++++++++
src/org/python/modules/posix/PosixModule.java | 10 ++++++-
2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_os_jy.py b/Lib/test/test_os_jy.py
--- a/Lib/test/test_os_jy.py
+++ b/Lib/test/test_os_jy.py
@@ -76,10 +76,25 @@
os.removedirs(p)
+class OSStatTestCase(unittest.TestCase):
+
+ def setUp(self):
+ open(test_support.TESTFN, 'w').close()
+
+ def tearDown(self):
+ if os.path.exists(test_support.TESTFN):
+ os.remove(test_support.TESTFN)
+
+ def test_stat_with_trailing_slash(self):
+ self.assertRaises(OSError, os.stat, test_support.TESTFN + os.path.sep)
+ self.assertRaises(OSError, os.lstat, test_support.TESTFN + os.path.sep)
+
+
def test_main():
test_support.run_unittest(
OSFileTestCase,
OSDirTestCase,
+ OSStatTestCase,
)
if __name__ == '__main__':
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
@@ -950,7 +950,15 @@
@Override
public PyObject __call__(PyObject path) {
- return PyStatResult.fromFileStat(posix.stat(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.stat
+ // behaviour if path is not a directory.
+ if (asPath(path).endsWith(File.separator)) {
+ absolutePath = absolutePath + File.separator;
+ }
+ return PyStatResult.fromFileStat(posix.stat(absolutePath));
}
}
}
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list