From: <pj...@us...> - 2009-05-21 04:11:07
|
Revision: 6361 http://jython.svn.sourceforge.net/jython/?rev=6361&view=rev Author: pjenvey Date: 2009-05-21 04:10:49 +0000 (Thu, 21 May 2009) Log Message: ----------- fix open(os.devnull, 'w') on Windows Modified Paths: -------------- trunk/jython/.classpath trunk/jython/build.xml trunk/jython/src/org/python/core/io/FileIO.java Modified: trunk/jython/.classpath =================================================================== --- trunk/jython/.classpath 2009-05-20 15:09:43 UTC (rev 6360) +++ trunk/jython/.classpath 2009-05-21 04:10:49 UTC (rev 6361) @@ -17,5 +17,6 @@ <classpathentry kind="lib" path="extlibs/asm-3.1.jar"/> <classpathentry kind="lib" path="extlibs/asm-commons-3.1.jar"/> <classpathentry kind="lib" path="extlibs/constantine-0.4.jar"/> + <classpathentry kind="lib" path="extlibs/jna-posix.jar"/> <classpathentry kind="output" path="bugtests/classes"/> </classpath> Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-05-20 15:09:43 UTC (rev 6360) +++ trunk/jython/build.xml 2009-05-21 04:10:49 UTC (rev 6361) @@ -158,6 +158,7 @@ <pathelement path="${extlibs.dir}/asm-3.1.jar" /> <pathelement path="${extlibs.dir}/asm-commons-3.1.jar" /> <pathelement path="${extlibs.dir}/constantine-0.4.jar" /> + <pathelement path="${extlibs.dir}/jna-posix.jar"/> </path> <available property="informix.present" classname="com.informix.jdbc.IfxDriver" classpath="${informix.jar}" /> Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-05-20 15:09:43 UTC (rev 6360) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-05-21 04:10:49 UTC (rev 6361) @@ -13,6 +13,7 @@ import java.nio.channels.FileChannel; import com.kenai.constantine.platform.Errno; +import org.jruby.ext.posix.util.Platform; import org.python.core.Py; import org.python.core.util.FileUtil; import org.python.core.util.RelativeFile; @@ -162,12 +163,14 @@ try { fileChannel.truncate(0); } catch (IOException ioe) { - // On Solaris and Linux, ftruncate(3C) returns EINVAL - // if not a regular file whereas, e.g., - // open("/dev/null", "w") works fine. Because we have - // to simulate the "w" mode in Java, we suppress the - // exception. - if (ioe.getMessage().equals("Invalid argument")) { + // On Solaris and Linux, ftruncate(3C) returns EINVAL if not a regular + // file whereas, e.g., open(os.devnull, "w") works. Likewise Windows + // returns ERROR_INVALID_FUNCTION. Because we have to simulate the "w" + // mode in Java, we suppress the exception. + String message = ioe.getMessage(); + if (((Platform.IS_SOLARIS || Platform.IS_LINUX) + && Errno.EINVAL.description().equals(message)) + || (Platform.IS_WINDOWS && "Incorrect function".equals(message))) { return; } throw Py.IOError(ioe); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |