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