Mercurial > hg
changeset 8421:b6d0fa8c7685
posixfile: remove posixfile_nt and fix import bug in windows.py
The posixfile_nt class has been superseded by posixfile in osutils.c,
which works on Windows NT and above. All other systems get the regular
python file class which is assigned to posixfile in posix.py (for POSIX)
and in the pure python version of osutils.py (for Win 9x or Windows NT
in pure mode).
author | Sune Foldager <cryo@cyanite.org> |
---|---|
date | Wed, 13 May 2009 21:36:16 +0200 |
parents | f53bc3e37655 |
children | 437e06bbd11e |
files | mercurial/pure/osutil.py mercurial/win32.py mercurial/windows.py |
diffstat | 3 files changed, 13 insertions(+), 125 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/pure/osutil.py Thu May 14 14:12:32 2009 -0700 +++ b/mercurial/pure/osutil.py Wed May 13 21:36:16 2009 +0200 @@ -8,6 +8,8 @@ import os import stat as _stat +posixfile = file + def _mode_to_kind(mode): if _stat.S_ISREG(mode): return _stat.S_IFREG if _stat.S_ISDIR(mode): return _stat.S_IFDIR @@ -47,3 +49,4 @@ else: result.append((fn, _mode_to_kind(st.st_mode))) return result +
--- a/mercurial/win32.py Thu May 14 14:12:32 2009 -0700 +++ b/mercurial/win32.py Wed May 13 21:36:16 2009 +0200 @@ -264,114 +264,6 @@ return [os.path.join(userdir, 'mercurial.ini'), os.path.join(userdir, '.hgrc')] -class posixfile_nt(object): - '''file object with posix-like semantics. on windows, normal - files can not be deleted or renamed if they are open. must open - with win32file.FILE_SHARE_DELETE. this flag does not exist on - windows < nt, so do not use this class there.''' - - # ideally, we could use win32file._open_osfhandle and avoid this - # class entirely, but we would need the win32 _fdopen function, - # which is not exported by the win32file module. - - def __init__(self, name, mode='rb'): - self.closed = False - self.name = name - self.mode = mode - access = 0 - if 'r' in mode or '+' in mode: - access |= win32file.GENERIC_READ - if 'w' in mode or 'a' in mode or '+' in mode: - access |= win32file.GENERIC_WRITE - if 'r' in mode: - creation = win32file.OPEN_EXISTING - elif 'a' in mode: - creation = win32file.OPEN_ALWAYS - else: - creation = win32file.CREATE_ALWAYS - try: - self.handle = win32file.CreateFile(name, - access, - win32file.FILE_SHARE_READ | - win32file.FILE_SHARE_WRITE | - win32file.FILE_SHARE_DELETE, - None, - creation, - win32file.FILE_ATTRIBUTE_NORMAL, - 0) - except pywintypes.error, err: - raise WinIOError(err, name) - - def __iter__(self): - for line in self.readlines(): - yield line - - def read(self, count=-1): - try: - cs = cStringIO.StringIO() - while count: - wincount = int(count) - if wincount == -1: - wincount = 1048576 - val, data = win32file.ReadFile(self.handle, wincount) - if not data: break - cs.write(data) - if count != -1: - count -= len(data) - return cs.getvalue() - except pywintypes.error, err: - raise WinIOError(err) - - def readlines(self, sizehint=None): - # splitlines() splits on single '\r' while readlines() - # does not. cStringIO has a well behaving readlines() and is fast. - return cStringIO.StringIO(self.read()).readlines() - - def write(self, data): - try: - if 'a' in self.mode: - win32file.SetFilePointer(self.handle, 0, win32file.FILE_END) - nwrit = 0 - while nwrit < len(data): - val, nwrit = win32file.WriteFile(self.handle, data) - data = data[nwrit:] - except pywintypes.error, err: - raise WinIOError(err) - - def writelines(self, sequence): - for s in sequence: - self.write(s) - - def seek(self, pos, whence=0): - try: - win32file.SetFilePointer(self.handle, int(pos), whence) - except pywintypes.error, err: - raise WinIOError(err) - - def tell(self): - try: - return win32file.SetFilePointer(self.handle, 0, - win32file.FILE_CURRENT) - except pywintypes.error, err: - raise WinIOError(err) - - def close(self): - if not self.closed: - self.handle = None - self.closed = True - - def flush(self): - # we have no application-level buffering - pass - - def truncate(self, pos=0): - try: - win32file.SetFilePointer(self.handle, int(pos), - win32file.FILE_BEGIN) - win32file.SetEndOfFile(self.handle) - except pywintypes.error, err: - raise WinIOError(err) - def getuser(): '''return name of current user''' return win32api.GetUserName()
--- a/mercurial/windows.py Thu May 14 14:12:32 2009 -0700 +++ b/mercurial/windows.py Wed May 13 21:36:16 2009 +0200 @@ -8,9 +8,17 @@ from i18n import _ import osutil, error import errno, msvcrt, os, re, sys + nulldev = 'NUL:' +umask = 002 -umask = 002 +# wrap osutil.posixfile to provide friendlier exceptions +def posixfile(name, mode='r', buffering=-1): + try: + return osutil.posixfile(name, mode, buffering) + except WindowsError, err: + raise WinIOError(err) +posixfile.__doc__ = osutil.posixfile.__doc__ class winstdout: '''stdout on windows misbehaves if sent through a pipe''' @@ -270,20 +278,5 @@ try: # override functions with win32 versions if possible from win32 import * - if not _is_win_9x(): - posixfile = posixfile_nt - try: - # fast, buffered POSIX-like file support - from osutil import posixfile as _posixfile - def posixfile(name, mode='r', buffering=-1): - # wrap osutil.posixfile to provide friendlier exceptions - try: - return _posixfile(name, mode, buffering) - except WindowsError, err: - raise WinIOError(err) - posixfile.__doc__ = _posixfile.__doc__ - except ImportError: - # slow, unbuffered POSIX-like file support - posixfile = posixfile_nt except ImportError: - posixfile = file + pass