diff options
| author | Shawn O. Pearce <sop@google.com> | 2009-04-18 14:48:03 -0700 |
|---|---|---|
| committer | Shawn O. Pearce <sop@google.com> | 2009-04-18 14:48:03 -0700 |
| commit | 76ca9f8145f367f83df19981da4dd934fdda471b (patch) | |
| tree | d6c095928fd2b1131972206b3c3f498843a736a6 /git_config.py | |
| parent | accc56d82b902e7c7a22401db710958fcb1c7b58 (diff) | |
| download | git-repo-76ca9f8145f367f83df19981da4dd934fdda471b.tar.gz | |
Make usage of open safer by setting binary mode and closing fds
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'git_config.py')
| -rw-r--r-- | git_config.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/git_config.py b/git_config.py index 7aad80d2..7e642a4c 100644 --- a/git_config.py +++ b/git_config.py | |||
| @@ -219,7 +219,11 @@ class GitConfig(object): | |||
| 219 | return None | 219 | return None |
| 220 | try: | 220 | try: |
| 221 | Trace(': unpickle %s', self.file) | 221 | Trace(': unpickle %s', self.file) |
| 222 | return cPickle.load(open(self._pickle, 'r')) | 222 | fd = open(self._pickle, 'rb') |
| 223 | try: | ||
| 224 | return cPickle.load(fd) | ||
| 225 | finally: | ||
| 226 | fd.close() | ||
| 223 | except IOError: | 227 | except IOError: |
| 224 | os.remove(self._pickle) | 228 | os.remove(self._pickle) |
| 225 | return None | 229 | return None |
| @@ -229,9 +233,11 @@ class GitConfig(object): | |||
| 229 | 233 | ||
| 230 | def _SavePickle(self, cache): | 234 | def _SavePickle(self, cache): |
| 231 | try: | 235 | try: |
| 232 | cPickle.dump(cache, | 236 | fd = open(self._pickle, 'wb') |
| 233 | open(self._pickle, 'w'), | 237 | try: |
| 234 | cPickle.HIGHEST_PROTOCOL) | 238 | cPickle.dump(cache, fd, cPickle.HIGHEST_PROTOCOL) |
| 239 | finally: | ||
| 240 | fd.close() | ||
| 235 | except IOError: | 241 | except IOError: |
| 236 | os.remove(self._pickle) | 242 | os.remove(self._pickle) |
| 237 | except cPickle.PickleError: | 243 | except cPickle.PickleError: |
