##// END OF EJS Templates
bookmarks: use context manager when writing files...
Martin von Zweigbergk -
r42502:ec5bd3ab default
parent child Browse files
Show More
@@ -204,27 +204,18 b' class bmstore(object):'
204 rbm._writeactive()
204 rbm._writeactive()
205
205
206 with repo.wlock():
206 with repo.wlock():
207 file_ = repo.vfs('bookmarks', 'w', atomictemp=True,
207 with repo.vfs('bookmarks', 'w', atomictemp=True,
208 checkambig=True)
208 checkambig=True) as f:
209 try:
209 self._write(f)
210 self._write(file_)
211 except: # re-raises
212 file_.discard()
213 raise
214 finally:
215 file_.close()
216
210
217 def _writeactive(self):
211 def _writeactive(self):
218 if self._aclean:
212 if self._aclean:
219 return
213 return
220 with self._repo.wlock():
214 with self._repo.wlock():
221 if self._active is not None:
215 if self._active is not None:
222 f = self._repo.vfs('bookmarks.current', 'w', atomictemp=True,
216 with self._repo.vfs('bookmarks.current', 'w', atomictemp=True,
223 checkambig=True)
217 checkambig=True) as f:
224 try:
225 f.write(encoding.fromlocal(self._active))
218 f.write(encoding.fromlocal(self._active))
226 finally:
227 f.close()
228 else:
219 else:
229 self._repo.vfs.tryunlink('bookmarks.current')
220 self._repo.vfs.tryunlink('bookmarks.current')
230 self._aclean = True
221 self._aclean = True
General Comments 0
You need to be logged in to leave comments. Login now