diff -r 6543a4a393fe Lib/test/test_file_jy.py --- a/Lib/test/test_file_jy.py Wed Jan 21 04:25:24 2015 +0000 +++ b/Lib/test/test_file_jy.py Tue Jan 20 22:45:35 2015 -0800 @@ -43,6 +43,14 @@ else: self.assertTrue(False) + @unittest.skipUnless(hasattr(os, 'chmod'), 'chmod() support required for this test') + def test_issue2081(self): + f = open(test_support.TESTFN, 'wb') + f.close() + os.chmod(test_support.TESTFN, 200) # write-only + f = open(test_support.TESTFN, 'w') # should succeed, raised IOError (permission denied) prior to fix + f.close() + def test_main(): test_support.run_unittest(FileTestCase) diff -r 6543a4a393fe src/org/python/core/io/FileIO.java --- a/src/org/python/core/io/FileIO.java Wed Jan 21 04:25:24 2015 +0000 +++ b/src/org/python/core/io/FileIO.java Tue Jan 20 22:45:35 2015 -0800 @@ -72,7 +72,7 @@ File absPath = new RelativeFile(name.toString()); try { - if (appending && !(reading || plus)) { + if ((appending && !(reading || plus)) || (writing && !reading && !plus)) { // Take advantage of FileOutputStream's append mode fromFileOutputStream(absPath); } else { @@ -181,7 +181,7 @@ * @param absPath The absolute path File to open */ private void fromFileOutputStream(File absPath) throws FileNotFoundException { - fileOutputStream = new FileOutputStream(absPath, true); + fileOutputStream = new FileOutputStream(absPath, appending); fileChannel = fileOutputStream.getChannel(); }