~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: INADA Naoki
  • Date: 2010-02-23 02:37:27 UTC
  • mto: (4634.141.1 2.0-integration)
  • mto: This revision was merged to the branch mainline in revision 5075.
  • Revision ID: songofacandy@gmail.com-20100223023727-84mfv9vgjgi1b72x
Revert to previous implementation using os.fdopen(os.open())

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
import __builtin__
18
17
import os
19
18
import re
20
19
import stat
1919
1918
        So deleting or renaming closed file that opened with this function
1920
1919
        is not blocked by child process.
1921
1920
        """
1922
 
        return __builtin__.open(filename, mode+'N', bufsize)
 
1921
        writing = 'w' in mode
 
1922
        appending = 'a' in mode
 
1923
        updating = '+' in mode
 
1924
        binary = 'b' in mode
 
1925
 
 
1926
        flags = os.O_NOINHERIT
 
1927
        # see http://msdn.microsoft.com/en-us/library/yeby3zcb%28VS.71%29.aspx
 
1928
        # for flags for each modes.
 
1929
        if binary:
 
1930
            flags |= os.O_BINARY
 
1931
        else:
 
1932
            flags |= os.O_TEXT
 
1933
 
 
1934
        if writing:
 
1935
            if updating:
 
1936
                flags |= os.O_RDWR
 
1937
            else:
 
1938
                flags |= os.O_WRONLY
 
1939
            flags |= os.O_CREAT | os.O_TRUNC
 
1940
        elif appending:
 
1941
            if updating:
 
1942
                flags |= os.O_RDWR
 
1943
            else:
 
1944
                flags |= os.O_WRONLY
 
1945
            flags |= os.O_CREAT | os.O_APPEND
 
1946
        else: #reading
 
1947
            if updating:
 
1948
                flags |= os.O_RDWR
 
1949
            else:
 
1950
                flags |= os.O_RDONLY
 
1951
 
 
1952
        return os.fdopen(os.open(filename, flags), mode, bufsize)
1923
1953
else:
 
1954
    import __builtin__
1924
1955
    open = __builtin__.open