Issue2068

classification
Title: os.write does not properly support os.O_APPEND
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
process
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: jamesls, santa4nt, zyasoft
Priority: Keywords:

Created on 2013-07-14.19:32:15 by jamesls, last changed 2014-05-21.21:45:36 by zyasoft.

Messages
msg8063 (view) Author: James (jamesls) Date: 2013-07-14.19:32:14
Mac OS X 10.8.3, using jython 2.7b1 I get:

import os

fd = os.open('testfile', os.O_RDWR|os.O_CREAT|os.O_APPEND)
os.write(fd, bytes('one'))
os.write(fd, bytes('two'))
os.write(fd, bytes('three'))
os.close(fd)

with open('testfile', 'rb') as f:
    print(f.read())

# Output, first time run:
$ jython /tmp/repro.py
three
# Second time
$ jython /tmp/repro.py
threethree

On CPython 2.7.5 I get:
$ python /tmp/repro.py
onetwothree
$ python /tmp/repro.py
onetwothreeonetwothree
msg8064 (view) Author: James (jamesls) Date: 2013-07-14.19:39:26
The actual issue appears to be with the O_APPEND flag, if I remove this option, I get the correct behavior the first time the script is run, but then of course the second time around the file is not appended to (as expected since O_APPEND is not specified).

import os

fd = os.open('testfile', os.O_RDWR|os.O_CREAT)
os.write(fd, bytes('one'))
os.write(fd, bytes('two'))
os.write(fd, bytes('three'))
os.close(fd)

with open('testfile', 'rb') as f:
    print(f.read())


$ jython /tmp/repro.py
onetwothree
msg8484 (view) Author: Jim Baker (zyasoft) Date: 2014-05-21.21:45:36
Removing bytes(...) as an issue, it's really just OS_APPEND

Target beta 4
History
Date User Action Args
2014-05-21 21:45:36zyasoftsetresolution: accepted
messages: + msg8484
nosy: + zyasoft
title: Incorrect behavior with bytes() and with os.write with os.O_APPEND -> os.write does not properly support os.O_APPEND
2013-07-15 18:20:07santa4ntsetnosy: + santa4nt
type: behaviour
2013-07-14 19:39:26jameslssetmessages: + msg8064
title: Incorrect behavior with bytes() and with os.write -> Incorrect behavior with bytes() and with os.write with os.O_APPEND
2013-07-14 19:32:15jameslscreate