| @@ -144,11 +144,15 @@ def validate_file(fname): | |||||
| finddname = glob_escape(torrent['info']['name'].decode(_encoding)) | finddname = glob_escape(torrent['info']['name'].decode(_encoding)) | ||||
| dirname = list(fname.parent.rglob(finddname))[0] | |||||
| for dirname in fname.parent.rglob(finddname): | |||||
| tordir = dirname.parent | |||||
| tordir = dirname.parent | |||||
| return validate(torrent, tordir) | |||||
| try: | |||||
| return validate(torrent, tordir) | |||||
| except FileNotFoundError as e: | |||||
| continue | |||||
| else: | |||||
| raise FileNotFoundError('unable to find directory for %s' % (repr(fname.name))) | |||||
| def validate(torrent, basedir): | def validate(torrent, basedir): | ||||
| '''Take a decode torrent file, where it was stored in basedir, | '''Take a decode torrent file, where it was stored in basedir, | ||||
| @@ -256,7 +260,25 @@ class _TestCases(unittest.TestCase): | |||||
| self.make_files(sd, self.origfiledata) | self.make_files(sd, self.origfiledata) | ||||
| good, bad = validate_file(tf) | |||||
| origrglob = pathlib.PosixPath.rglob | |||||
| def _rglob_patch(b): | |||||
| return () | |||||
| with unittest.mock.patch.object(pathlib.PosixPath, 'rglob', | |||||
| side_effect=_rglob_patch): | |||||
| self.assertRaisesRegex(FileNotFoundError, | |||||
| 'unable to find directory for \'a.torrent\'', | |||||
| validate_file, tf) | |||||
| def _rglob_patch(b): | |||||
| return list(pathlib.PosixPath(x) for x in | |||||
| [ 'randomdir', 'somedir' ]) + \ | |||||
| list(origrglob(pathlib.PosixPath('.'), 'somedir')) | |||||
| with unittest.mock.patch.object(pathlib.PosixPath, 'rglob', | |||||
| side_effect=_rglob_patch): | |||||
| good, bad = validate_file(tf) | |||||
| self.assertFalse(bad) | self.assertFalse(bad) | ||||