Bug 33844 - OS/2: Wrong flags set for file open
Summary: OS/2: Wrong flags set for file open
Status: RESOLVED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: 0.9.6
Hardware: PC OS/2
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-04 14:34 UTC by Vitali Pelenyov
Modified: 2005-08-24 05:48 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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