Bug 33844

Summary: OS/2: Wrong flags set for file open
Product: APR Reporter: Vitali Pelenyov <sunlover>
Component: APRAssignee: Apache Portable Runtime bugs mailinglist <bugs>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 0.9.6   
Target Milestone: ---   
Hardware: PC   
OS: OS/2   

Description Vitali Pelenyov 2005-03-04 14:34:30 UTC
Actually bug is in APR:
/apr/branches/1.1.x/file_io/os2/open.c

Problem is that when a PUT is made with Content_Range: to a existing DAV
resource, the file is truncated.

Here are explanation why this happen and how to fix it:

DAV module (dav_fs_open_stream called with DAV_MODE_WRITE_SEEKABLE)
calls APR without the APR_TRUNCATE flag:
    switch (mode) {
    default:
        flags = APR_READ | APR_BINARY;
        break;

    case DAV_MODE_WRITE_TRUNC:
        flags = APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BINARY;
        break;
    case DAV_MODE_WRITE_SEEKABLE:
        flags = APR_WRITE | APR_CREATE | APR_BINARY;
        break;
    }

but APR sets OPEN_ACTION_REPLACE_IF_EXISTS for the given APR flags:
    if (flag & APR_CREATE) {
        oflags |= OPEN_ACTION_CREATE_IF_NEW;
        if (!(flag & APR_EXCL)) {
            if (flag & APR_APPEND)
                oflags |= OPEN_ACTION_OPEN_IF_EXISTS;
            else
                oflags |= OPEN_ACTION_REPLACE_IF_EXISTS;
        }
    }

So the fix is to remove 'if (flag & APR_APPEND)' statement:
    if (flag & APR_CREATE) {
        oflags |= OPEN_ACTION_CREATE_IF_NEW;
        if (!(flag & APR_EXCL)) {
            oflags |= OPEN_ACTION_OPEN_IF_EXISTS;
        }
    }


Note that the OPEN_ACTION_REPLACE_IF_EXISTS is explicitly set later
in the function if APR_TRUNCATE is specified.

I checked Win32 code and file is not truncated there if
APR_WRITE | APR_CREATE | APR_BINARY flags are set.
Which is a right behaviour.
Comment 1 Laszlo Kishalmi 2005-06-29 10:34:57 UTC
I suggest to assign this defect to Brian Havard a faithful supporter of Apache
on OS/2 and he has a committer role to fix this problem.
Comment 2 Joe Orton 2005-08-24 13:48:57 UTC
It looks like this should be fixed in 1.2.1 and will be in 0.9.7;

http://svn.apache.org/viewcvs?rev=209047&view=rev