mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor FileAvoidWrite
This commit is contained in:
parent
c6cb0b667f
commit
2c300e209d
@ -262,18 +262,12 @@ class FileAvoidWrite(object):
|
|||||||
old_content = None
|
old_content = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
old_f = open(self._path, r_mode)
|
with open(self._path, r_mode) as old_f:
|
||||||
except IOError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
old_content = old_f.read()
|
old_content = old_f.read()
|
||||||
if old_content == buf:
|
if old_content == buf:
|
||||||
return
|
return
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
finally:
|
|
||||||
old_f.close()
|
|
||||||
|
|
||||||
with open(self._path, w_mode) as f:
|
with open(self._path, w_mode) as f:
|
||||||
f.write(buf)
|
f.write(buf)
|
||||||
|
Loading…
Reference in New Issue
Block a user