Make recentfiles.do_save exception safe.
This commit is contained in:
parent
5f3f280ea0
commit
b3edd2fa5f
@ -184,26 +184,26 @@ 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")
|
||||||
xml_file.write('<RecentFiles>\n')
|
xml_file.write('<RecentFiles>\n')
|
||||||
index = 0
|
index = 0
|
||||||
for item in self.gramps_recent_files:
|
for item in self.gramps_recent_files:
|
||||||
index += 1
|
index += 1
|
||||||
if index > MAX_GRAMPS_ITEMS:
|
if index > MAX_GRAMPS_ITEMS:
|
||||||
break
|
break
|
||||||
xml_file.write(' <RecentItem>\n')
|
xml_file.write(' <RecentItem>\n')
|
||||||
xml_file.write(' <Path><![CDATA[%s]]></Path>\n' % item.get_path())
|
xml_file.write(' <Path><![CDATA[%s]]></Path>\n' % item.get_path())
|
||||||
xml_file.write(' <Name><![CDATA[%s]]></Name>\n' % item.get_name())
|
xml_file.write(' <Name><![CDATA[%s]]></Name>\n' % item.get_name())
|
||||||
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