From c2ac1018e586174b5353531aa4cb917b2d5b7306 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Mon, 19 Sep 2022 13:52:39 -0700 Subject: [PATCH] fix issue w/ calculating size of last piece... --- ui/medashare/btv/__init__.py | 17 ++++++++++++++++- ui/medashare/btv/fixtures/40plus1.txt.torrent | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 ui/medashare/btv/fixtures/40plus1.txt.torrent diff --git a/ui/medashare/btv/__init__.py b/ui/medashare/btv/__init__.py index c8931f2..86004fd 100644 --- a/ui/medashare/btv/__init__.py +++ b/ui/medashare/btv/__init__.py @@ -47,7 +47,10 @@ class Storage: # get length sz = length piececnt = roundup(sz, piecelen) - self._pieceindex = [ [ dict(file=self._rootpath, offset=x * piecelen, size=piecelen if x < piececnt - 1 else sz - piececnt * x) ] for x in range(piececnt) ] + self._pieceindex = [ [ dict(file=self._rootpath, + offset=x * piecelen, size=piecelen if + x < piececnt - 1 else sz - x * piecelen) ] for x in + range(piececnt) ] else: self._buildindex() @@ -391,6 +394,18 @@ class _TestCases(unittest.TestCase): self.assertFalse(good) self.assertEqual(hashes, {}) + shutil.copy(self.fixtures / '40plus1.txt.torrent', self.basetempdir) + tor = self.basetempdir / '40plus1.txt.torrent' + + with open(sd / '40plus1.txt', 'w') as fp: + fp.write('w') + + good, bad, hashes = validate_file(tor, with_file_hashes=sha512) + + self.assertEqual(bad, { sd / '40plus1.txt' }) + self.assertFalse(good) + self.assertEqual(hashes, {}) + def test_verification(self): # Testing for "missing" files # piece size 2 (aka 4 bytes) diff --git a/ui/medashare/btv/fixtures/40plus1.txt.torrent b/ui/medashare/btv/fixtures/40plus1.txt.torrent new file mode 100644 index 0000000..6c25890 --- /dev/null +++ b/ui/medashare/btv/fixtures/40plus1.txt.torrent @@ -0,0 +1 @@ +d13:creation datei1663620495e4:infod6:lengthi41e4:name11:40plus1.txt12:piece lengthi4e6:pieces220:e®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}Ÿe®©ŒWÜÒ¡ÿ°Ó\¢ʯ}ŸÀé÷0Kp/Váè›OˆE Š‰k©¤Œ:m’­´äÆ34¸‚PŠm«ÃÅo?Ôë|»M‰Sdñ&ôs\}(=µ„kº‰*Uìâ§M|ý˜­È;ç“In ý‹FÍŸ2å’üe5:nodeslee \ No newline at end of file