mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Refactor FileAvoidWrite
This commit is contained in:
@@ -262,18 +262,12 @@ class FileAvoidWrite(object):
|
||||
old_content = None
|
||||
|
||||
try:
|
||||
old_f = open(self._path, r_mode)
|
||||
except IOError:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
with open(self._path, r_mode) as old_f:
|
||||
old_content = old_f.read()
|
||||
if old_content == buf:
|
||||
return
|
||||
except IOError:
|
||||
pass
|
||||
finally:
|
||||
old_f.close()
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
with open(self._path, w_mode) as f:
|
||||
f.write(buf)
|
||||
|
||||
Reference in New Issue
Block a user