Title: open fails on write-only files
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: dcoles, santa4nt, zyasoft
Priority: Keywords: patch

Created on 2013-08-29.21:17:59 by dcoles, last changed 2014-07-05.02:45:18 by zyasoft.

File name Uploaded Description Edit Remove
issue2081.patch santa4nt, 2013-09-03.21:05:59
msg8096 (view) Author: David Coles (dcoles) Date: 2013-08-29.21:17:58
Jython can't open files with write-only permission (write-bit is set, but read-bit is not set).

This appears to be due to using which only supports "r" or "rw" modes. The same file can be opened from Jython by using Java's

How to reproduce:

  $ touch /tmp/write-only-file
  $ chmod 200 /tmp/write-only-file
  $ jython2.7 --version
  Jython 2.7b1+
  $ jython2.7 -c 'f = open("/tmp/write-only-file", "w"); print(f)'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  IOError: [Errno 13] Permission denied: '/tmp/write-only-file'

Expected behavior:

  $ python -c 'f = open("/tmp/write-only-file", "w"); print(f)'
  <_io.TextIOWrapper name='/tmp/write-only-file' mode='w' encoding='ANSI_X3.4-1968'>

It seems like also has the same problem:

  $ jython2.7 -c 'import os; fd ="/tmp/write-only-file", os.O_WRONLY); print(fd)'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  IOError: [Errno 13] Permission denied: '/tmp/write-only-file'
msg8097 (view) Author: David Coles (dcoles) Date: 2013-08-29.21:27:15
This is probably the cause of issue1856 since the file they attempted to open has the same write-only permissions.

$ ls -l /sys/block/sdc/device/delete 
--w------- 1 root root 4096 Aug 29 14:01 /sys/block/sdc/device/delete
msg8098 (view) Author: Santoso Wijaya (santa4nt) Date: 2013-09-03.21:05:59
This is because the underlying FileIO object uses Java's RandomAccessFile object to open the file, which cannot open files in write-only mode.

Attaching a possible quickfix.
Date User Action Args
2014-07-05 02:45:18zyasoftsetnosy: + zyasoft
2013-09-03 21:06:00santa4ntsetfiles: + issue2081.patch
keywords: + patch
messages: + msg8098
nosy: + santa4nt
2013-08-29 21:27:15dcolessetmessages: + msg8097
2013-08-29 21:17:59dcolescreate