mirror of
https://github.com/servo/servo
synced 2026-05-01 03:47:53 +02:00
Utilize Python context managers for opening/closing files
In some of these cases, files were not being closed
This commit is contained in:
@@ -41,18 +41,16 @@ def replaceFileIfChanged(filename, newContents):
|
||||
|
||||
# oldFileContents = ""
|
||||
# try:
|
||||
# oldFile = open(filename, 'rb')
|
||||
# oldFileContents = ''.join(oldFile.readlines())
|
||||
# oldFile.close()
|
||||
# with open(filename, 'rb') as oldFile:
|
||||
# oldFileContents = ''.join(oldFile.readlines())
|
||||
# except:
|
||||
# pass
|
||||
|
||||
# if newContents == oldFileContents:
|
||||
# return False
|
||||
|
||||
f = open(filename, 'wb')
|
||||
f.write(newContents)
|
||||
f.close()
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(newContents)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user