Message6097
Here's a simple example demonstrating the problem:
import os
for c in 254, 255, 256:
f = unichr(c)+'.txt'
open(f, 'w').close()
print repr(f), 'exists', os.path.exists(f)
os.stat(f)
When the above code is run Linux, it reports all created files as existing and exits cleanly. On Windows you get this:
D:\>jython os_stat_bug.py
u'\xfe.txt' exists True
u'\xff.txt' exists True
u'\u0100.txt' exists False
Traceback (most recent call last):
File "os_stat_bug.py", line 6, in <module>
os.stat(f)
File "C:\jython2.5.1\Lib\os.py", line 478, in stat
return stat_result.from_jnastat(_posix.stat(abs_path))
File "C:\jython2.5.1\Lib\os.py", line 103, in error
raise OSError(err, strerror(err), asPyString(msg))
OSError: [Errno 2] No such file or directory: 'D:\\\u0100.txt'
As the failing os.path.exists in the above code already illustrated, a bug in os.stat is pretty annoying because so many other methods depend on it. I originally noticed this problem when shutil.rmtree didn't work.
The error occurs when the stat method calls _posix.stat. This _posix is returned by a factory and in my case it was WindowsPOSIX. I was able to make our projects acceptance tests pass with this workarounds:
if sys.platform.startswith('java') and os.sep == '\\':
os._posix = os.JavaPOSIX(os.PythonPOSIXHandler())
os._native_posix = False
Could someone who knows Jython internals better comment is this workaround valid? Hopefully this is can be fixed in 2.5.2. |
|
Date |
User |
Action |
Args |
2010-09-26 21:23:44 | pekka.klarck | set | recipients:
+ pekka.klarck |
2010-09-26 21:23:44 | pekka.klarck | set | messageid: <1285536224.32.0.0748361056963.issue1658@psf.upfronthosting.co.za> |
2010-09-26 21:23:44 | pekka.klarck | link | issue1658 messages |
2010-09-26 21:23:42 | pekka.klarck | create | |
|