Make recentfiles.do_save exception safe.
This commit is contained in:
parent
5f3f280ea0
commit
b3edd2fa5f
@ -184,10 +184,10 @@ class RecentFiles(object):
|
||||
"""
|
||||
Saves the current Gramps RecentFiles collection to the associated file.
|
||||
"""
|
||||
if sys.version_info[0] < 3:
|
||||
xml_file = open(os.path.expanduser(GRAMPS_FILENAME), 'w')
|
||||
else:
|
||||
xml_file = open(os.path.expanduser(GRAMPS_FILENAME), 'w', encoding='utf8')
|
||||
with (open(os.path.expanduser(GRAMPS_FILENAME), 'w')
|
||||
if sys.version_info[0] < 3 else
|
||||
open(os.path.expanduser(GRAMPS_FILENAME), 'w', encoding='utf8'))\
|
||||
as xml_file:
|
||||
if use_lock:
|
||||
fcntl.lockf(xml_file,fcntl.LOCK_EX)
|
||||
xml_file.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
@ -203,7 +203,7 @@ class RecentFiles(object):
|
||||
xml_file.write(' <Timestamp>%d</Timestamp>\n' % item.get_time())
|
||||
xml_file.write(' </RecentItem>\n')
|
||||
xml_file.write('</RecentFiles>\n')
|
||||
xml_file.close()
|
||||
|
||||
# all advisory locks on a file are released on close
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user