comparison mercurial/windows.py @ 37882:3a0f322af192 stable

windows: fix incorrect detection of broken pipe when writing to pager Paging e.g. hg incoming on Windows and quitting the pager before the output is consumed will print 'abort: Invalid argument'. This is because the windows error 0xE8 (ERROR_NO_DATA) is mapped to EINVAL even though it is documented as 'The pipe is being closed'. Note that this fix assumes that Windows' last error code is still valid in the exception handler. It works correctly in all my tests. A simpler fix would be to just map EINVAL to EPIPE, like was done is flush previously, but that would be less precise. This error was not observed previously, when pager was an extension.
author Sune Foldager <cryo@cyanite.org>
date Wed, 04 Jul 2018 14:19:13 +0200
parents a6c6b7beb025
children af8d8513d7de
comparison
equal deleted inserted replaced
37881:173cfdde0c86 37882:3a0f322af192
170 while start < l: 170 while start < l:
171 end = start + limit 171 end = start + limit
172 self.fp.write(s[start:end]) 172 self.fp.write(s[start:end])
173 start = end 173 start = end
174 except IOError as inst: 174 except IOError as inst:
175 if inst.errno != 0: 175 if inst.errno != 0 and not win32.lasterrorwaspipeerror(inst):
176 raise 176 raise
177 self.close() 177 self.close()
178 raise IOError(errno.EPIPE, 'Broken pipe') 178 raise IOError(errno.EPIPE, 'Broken pipe')
179 179
180 def flush(self): 180 def flush(self):
181 try: 181 try:
182 return self.fp.flush() 182 return self.fp.flush()
183 except IOError as inst: 183 except IOError as inst:
184 if inst.errno != errno.EINVAL: 184 if not win32.lasterrorwaspipeerror(inst):
185 raise 185 raise
186 raise IOError(errno.EPIPE, 'Broken pipe') 186 raise IOError(errno.EPIPE, 'Broken pipe')
187 187
188 def _is_win_9x(): 188 def _is_win_9x():
189 '''return true if run on windows 95, 98 or me.''' 189 '''return true if run on windows 95, 98 or me.'''