Mercurial > public > mercurial-scm > hg
comparison hgext/blackbox.py @ 18786:ed39a8f94e95
blackbox: prevent failed I/O from causing hg to abort
Instead, we simply print a warning message if opening the blackbox log
file fails, or if writing to it fails.
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Wed, 20 Mar 2013 13:40:05 -0700 |
parents | 1506eb487ddd |
children | f56278a0a0c5 |
comparison
equal
deleted
inserted
replaced
18785:136516cd3d69 | 18786:ed39a8f94e95 |
---|---|
55 | 55 |
56 if blackbox: | 56 if blackbox: |
57 date = util.datestr(None, '%Y/%m/%d %H:%M:%S') | 57 date = util.datestr(None, '%Y/%m/%d %H:%M:%S') |
58 user = getpass.getuser() | 58 user = getpass.getuser() |
59 formattedmsg = msg[0] % msg[1:] | 59 formattedmsg = msg[0] % msg[1:] |
60 blackbox.write('%s %s> %s' % (date, user, formattedmsg)) | 60 try: |
61 blackbox.write('%s %s> %s' % (date, user, formattedmsg)) | |
62 except IOError, err: | |
63 self.debug('warning: cannot write to blackbox.log: %s\n' % | |
64 err.strerror) | |
61 lastblackbox = blackbox | 65 lastblackbox = blackbox |
62 | 66 |
63 def setrepo(self, repo): | 67 def setrepo(self, repo): |
64 self._blackbox = repo.opener('blackbox.log', 'a') | 68 try: |
69 self._blackbox = repo.opener('blackbox.log', 'a') | |
70 except IOError, err: | |
71 self.debug('warning: cannot write to blackbox.log: %s\n' % | |
72 err.strerror) | |
73 self._blackbox = None | |
65 | 74 |
66 ui.__class__ = blackboxui | 75 ui.__class__ = blackboxui |
67 | 76 |
68 def uisetup(ui): | 77 def uisetup(ui): |
69 wrapui(ui) | 78 wrapui(ui) |