mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
[#149 state:fixed] Fixed crash on result saving.
This commit is contained in:
parent
f28ffc680a
commit
54ffcfab79
@ -8,10 +8,13 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
|
import os.path as op
|
||||||
from xml.etree import ElementTree as ET
|
from xml.etree import ElementTree as ET
|
||||||
|
|
||||||
from . import engine
|
from . import engine
|
||||||
from jobprogress.job import nulljob
|
from jobprogress.job import nulljob
|
||||||
|
from hscommon.conflict import get_conflicted_name
|
||||||
from hscommon.markable import Markable
|
from hscommon.markable import Markable
|
||||||
from hscommon.util import flatten, nonone, FileOrPath, format_size
|
from hscommon.util import flatten, nonone, FileOrPath, format_size
|
||||||
from hscommon.trans import tr
|
from hscommon.trans import tr
|
||||||
@ -304,8 +307,22 @@ class Results(Markable):
|
|||||||
match_elem.set('second', str(dupe2index[match.second]))
|
match_elem.set('second', str(dupe2index[match.second]))
|
||||||
match_elem.set('percentage', str(int(match.percentage)))
|
match_elem.set('percentage', str(int(match.percentage)))
|
||||||
tree = ET.ElementTree(root)
|
tree = ET.ElementTree(root)
|
||||||
with FileOrPath(outfile, 'wb') as fp:
|
|
||||||
tree.write(fp, encoding='utf-8')
|
def do_write(outfile):
|
||||||
|
with FileOrPath(outfile, 'wb') as fp:
|
||||||
|
tree.write(fp, encoding='utf-8')
|
||||||
|
|
||||||
|
try:
|
||||||
|
do_write(outfile)
|
||||||
|
except IOError as e:
|
||||||
|
if e.errno == 21: # outfile is a directory
|
||||||
|
p = str(outfile)
|
||||||
|
dirname, basename = op.split(p)
|
||||||
|
otherfiles = os.listdir(dirname)
|
||||||
|
newname = get_conflicted_name(otherfiles, basename)
|
||||||
|
do_write(op.join(dirname, newname))
|
||||||
|
else:
|
||||||
|
raise
|
||||||
self.is_modified = False
|
self.is_modified = False
|
||||||
|
|
||||||
def sort_dupes(self, key, asc=True, delta=False):
|
def sort_dupes(self, key, asc=True, delta=False):
|
||||||
|
@ -137,6 +137,7 @@ class TestCaseDupeGuru:
|
|||||||
eq_(len(app.results.groups), 0)
|
eq_(len(app.results.groups), 0)
|
||||||
|
|
||||||
def test_rename_when_nothing_is_selected(self):
|
def test_rename_when_nothing_is_selected(self):
|
||||||
|
# Issue #140
|
||||||
# It's possible that rename operation has its selected row swept off from under it, thus
|
# It's possible that rename operation has its selected row swept off from under it, thus
|
||||||
# making the selected row None. Don't crash when it happens.
|
# making the selected row None. Don't crash when it happens.
|
||||||
dgapp = DupeGuru()
|
dgapp = DupeGuru()
|
||||||
|
@ -77,6 +77,18 @@ class TestCaseResultsEmpty:
|
|||||||
self.results.groups = []
|
self.results.groups = []
|
||||||
assert not self.results.is_modified
|
assert not self.results.is_modified
|
||||||
|
|
||||||
|
def test_save_to_same_name_as_folder(self, tmpdir):
|
||||||
|
# Issue #149
|
||||||
|
# When saving to a filename that already exists, the file is overwritten. However, when
|
||||||
|
# the name exists but that it's a folder, then there used to be a crash. The proper fix
|
||||||
|
# would have been some kind of feedback to the user, but the work involved for something
|
||||||
|
# that simply never happens (I never received a report of this crash, I experienced it
|
||||||
|
# while fooling around) is too much. Instead, use standard name conflict resolution.
|
||||||
|
folderpath = tmpdir.join('foo')
|
||||||
|
folderpath.mkdir()
|
||||||
|
self.results.save_to_xml(str(folderpath)) # no crash
|
||||||
|
assert tmpdir.join('[000] foo').check()
|
||||||
|
|
||||||
|
|
||||||
class TestCaseResultsWithSomeGroups:
|
class TestCaseResultsWithSomeGroups:
|
||||||
def setup_method(self, method):
|
def setup_method(self, method):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user